Category Archives: Daftar isi

Contoh Code Sketch untuk LCD matrix I2C dan RTC1307 I2C dipakai bersama .

RTC_LCD_I2C

#include <TimeLib.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
tmElements_t tm;
unsigned int counter=0;
void setup() {

lcd.init(); // lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(0,0); // Set LCD cursor position (column, row)
lcd.print(“DS1307 + LCD-I2C”);
lcd.setCursor(0, 1); // Set LCD cursor position (column, row)
}

void loop()
{
digitalClockDisplay();
}

void digitalClockDisplay()
{
//tmElements_t tm;
if (RTC.read(tm))
{
lcd.setCursor(0, 1); // Set LCD cursor position (column, row)
print2digits(tm.Hour);
lcd.print(“:”);
print2digits(tm.Minute);
lcd.print(“:”);
print2digits(tm.Second);
//lcd.setCursor(4, 2);
print2digits(tm.Day);
lcd.print(“/”);
print2digits(tm.Month);
lcd.print(“/”);
print2digits(tm.Year+1970-2000);
//lcd.setCursor(4, 3);
//lcd.print(tm.Wday);
}

}
//=================
void print2digits(int number)
{
if (number >= 0 && number < 10) {
lcd.print(‘0’);
}
lcd.print(number);
}

/*
void TimeCheck()
{
int tem[17];
for(int i=11;i<17;i++)
{
tem[i]=EEPROM.read(i);
}
if(Hor == tem[11] && Min == tem[12] && off==1)
{
add=11;
lcd.clear();
lcd.print(“alarm………..”);
}
}
*/

Advertisements

Pengetahuan Dasar Arduino: Dasar RTC DS1307 Menampilkan Jam dan Tanggal pada LCD

#include <TimeLib.h>
#include <Wire.h>
#include <DS1307RTC.h> // library ini berisi class  RTCDS1307
#include <LiquidCrystal.h>
LiquidCrystal lcd( 5,6,7,8,9,10);//(rs, en,d0, d1, d2, d3)    pin rw di hubungkan dg GND
tmElements_t  waktu;     //membuat objeck dari class  DS1307RTC

void setup() {
lcd.begin(20, 4);
lcd.setCursor(0, 0); // Set LCD cursor position (column, row)
lcd.print(“TEST RTC DS1307”);
lcd.setCursor(0, 1); // Set LCD cursor position (column, row)
lcd.print(“JAM:”);
//lcd.setCursor(0, 2); // Set LCD cursor position (column, row)
//lcd.print(“TGL:”);
//lcd.setCursor(0, 3); // Set LCD cursor position (column, row)
//lcd.print(“Day:”);

}

void loop()
{
digitalClockDisplay();
delay(1000);
}

void digitalClockDisplay()
{

if (RTC.read(waktu))
{
lcd.setCursor(4, 1); // Set LCD cursor position (column, row)
print2digits(waktu.Hour);
lcd.print(“:”);
print2digits(waktu.Minute);
lcd.print(“:”);
print2digits(waktu.Second);

//lcd.setCursor(4, 2);
//print2digits(waktu.Day);
//lcd.print(“/”);
//print2digits(waktu.Month);
//lcd.print(“/”);
// lcd.print(tmYearToCalendar(waktu.Year));  //atau lcd.print(waktu.year+1970);
//lcd.setCursor(4, 3);
//lcd.print(waktu.Wday);
}

}
//=================
void print2digits(int number)
{
if (number >= 0 && number < 10) {
lcd.print(‘0’);
}
lcd.print(number);
}

 

Video Tutorial Dasar Arduino Bag-4: Built in Function

Video Tutorial Dasar Arduino Bag-4: built in function

Video Tutorial Dasar Arduino Bag-3: Sofware Arduino

Video Tutorial Dasar Arduino Bag-3: Sofware Arduino

Video Tutorial Dasar Arduino Bag-2: hardware Arduino

Video Tutorial Dasar Arduino Bag-2: hardware Arduino

Video Tutorial Dasar Arduino Bag-1: Mengenal Arduino

Tutorial Dasar Arduino Bag-1: Mengenal Arduino

 

Ebook Pemrograman Android Berbahasa Indonesia Resmi dari Google

https://chromplex.com/unduh-ebook-pemrograman-android-berbahasa-indonesia-resmi-dari-google/

Pengetahuan Dasar Membaca dan Menulis data ke file di SD CARD pd Arduino

[draft ]

Pendahuluan

Pada artikel ini kita akan menyimpan data register modbus ke dalam file text yg disimpan di memori sd card.

sd card dipasang pada ethernet shield  yg terdapat soket untuk sd card.

Contoh Code

#include <SD.h>

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

//==============BACA SD CARD==============================================

void readSDdataREG()
{
char InputChar;
String RegisterNo;
String RegisterValue;
Serial.println(“baca data setting.txt”);
myFile = SD.open(“dataREG.txt”);

if (myFile) {
while (myFile.available())
{
delay(200);
InputChar = myFile.read();//”[”
while((myFile.available()) && (InputChar != ‘[‘))
{ // selama blm ketemu ‘[‘ looping disini
InputChar = myFile.read();
}

InputChar = myFile.read();
while((myFile.available()) && (InputChar != ‘=’))
{
RegisterNo = RegisterNo + InputChar;
InputChar = myFile.read();
}

InputChar = myFile.read();
while((myFile.available()) && (InputChar != ‘]’))
{
RegisterValue = RegisterValue + InputChar;
InputChar = myFile.read();
}
//============================
if(InputChar == ‘]’)
{
Serial.print(“[“); Serial.print(RegisterNo);
Serial.print(“]=”); Serial.println(RegisterValue);
// Apply the value to the parameter
//RegValueInt=RegisterValue.toInt();
Mb.MbData[RegisterNo.toInt()-40001]=RegisterValue.toInt();
//writeAngka(1234, 4); //baris3
// writeAngka(RegisterValue.toInt(), 4); //baris3
//writeAngka(RegisterNo.toInt()-40001, 4); //baris3
/// strobe_74595();
// delay(500);
RegisterNo = “”;
RegisterValue = “”;
}
}// end while ada file
myFile.close();
}
else
{
Serial.println(“error opening dataREG.txt”);
}

}

//==============TULIS SD CARD==============================================

/*

CONTOH DATA  YG DISIMPAN :

[40001=123]

[40002=456]

DST….

*/

void writeSDdataREG()
{
SD.remove(“dataREG.txt”);
myFile = SD.open(“dataREG.txt”, FILE_WRITE);
for(int i=0;i<40;i++)
{
myFile.print(“[“);
myFile.print(i+40001);
myFile.print(“=”);myFile.print(Mb.MbData[i]);
myFile.println(“]”);
}
myFile.close();
Serial.println(“Writing dataREG done.”);
}
//==============SD END========================

Set Jam, Hari dan Tanggal RTC DS1307 pada Arduino melalui serial

DS1307

Ketika data  jam dan tanggal sdh tidak sesuai maka kita harus menset ulang data di memori RTC .  Kita bisa menset data RTC melalui kode arduino  parameter yg akan di set bisa kita berikan melalui serial dari PC

RTC<->Arduino<->serial<->PC

pada PC bisa menggunakan menu serial monitor pada IDE arduino.

sedangkan kode arduino untuk setting RTC DS1307 adalah sbb:

#include <DS1307RTC.h>
#include <Wire.h>
#include <TimeLib.h>
byte detik = 0;
byte menit = 0;
byte jam = 0;
byte hari = 0;
byte tgl = 0;
byte bln = 0;
byte thn = 0;

tmElements_t tm;

void setup()
{

Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.

Serial.println(“waktu saat ini: “);
printTime();
Serial.println(“edit tgl dan jam ? Y/N”);

while (!Serial.available())
delay(10);
if (Serial.read() == ‘y’ || Serial.read() == ‘Y’)
{
Serial.flush();
Serial.read();
setTime();
Serial.print(“waktu setelah diset: “);
printTime();
}
else
Serial.println(“finish”);
}

void loop()
{
}

 

// This set of codes is allows input of data
void setTime() {
Serial.println(“=======================”);
thn = readByte();
Serial.print(“tahun, 00-99 :”);
thn = readByte()+2000-1970;   // misal thn 2018 ,  ketik 18   , di memory = 2018-1970= 48
Serial.println(thn);

Serial.print(“bulan, 1-12 :”);
bln = readByte();
Serial.println(bln);

Serial.print(“tgl, 1-31 :”);
tgl = readByte();
Serial.println(tgl);
Serial.println(“hari 1-7 (minggu=1 sabtu=7):”);
hari = readByte();
Serial.println(hari);
Serial.print(“jam, 0-23:”);
jam = readByte();
Serial.println(jam);
Serial.print(“menit, 0-59 : “);
menit = readByte();
Serial.println(menit);
detik = 0;
Serial.println(“data sdh masuk”);
tm.Hour = jam;
tm.Minute = menit;
tm.Second = detik;
tm.Wday=hari;
tm.Day = tgl;
tm.Month = bln;
tm.Year = thn;

if (RTC.write(tm))
Serial.println(“setting berhasil…”);
else
Serial.println(“setting gagal…”);
}

 

byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != ‘\n’) {
if (incomingByte >= ‘0’ && incomingByte <= ‘9’)
reading = reading * 10 + (incomingByte – ‘0’);
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}

 

void printTime() {
readTime();

}

 

void readTime() {

if (RTC.read(tm))
{
Serial.print(“JAM = “);
print2digits(tm.Hour);
Serial.write(‘:’);
print2digits(tm.Minute);
Serial.write(‘:’);
print2digits(tm.Second);

Serial.print(“,HARI=”);

Serial.print(tm.Wday);
Serial.write(‘,’);
Serial.print(tm.Day);
Serial.write(‘/’);
Serial.print(tm.Month);
Serial.write(‘/’);
Serial.print(tm.Year+1970);   // jika thn 2018  dimemory terisi 48 , makanya harus ditambah dgn 1970.
Serial.println();
} else {
if (RTC.chipPresent()) {
Serial.println(“Please run the SetTime”);
Serial.println();
} else {
Serial.println(“DS1307 not connect”);
Serial.println();
}
delay(9000);
}
delay(1000);
}

 

void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write(‘0’);
}
Serial.print(number);
}

Pengetahuan Dasar Input Data Arduino dengan Remote TV

Software

-Arduino

Library IRRemote

Hardware

-Remote TV ( NEC, SONY, PANASONIC, SANYO atau yg lainya) pada contoh ini menggunakan remote dgn data kode  NEC  spt pd gb ke-2

-Sensor TV /IR senor

-Arduino board

PINIRREMOTE.jpg

 

Rangkai spt gambar berikut.  pin data untuk contoh ini no 8

irremote.jpg

Code Program

#include <IRremote.h>

int RECV_PIN = 8;
int y=0,data;
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
displayUtama();
pilihMenuUtama();

}
void displayUtama(){
Serial.println(“Display Utama”);
}

//==========================================
void pilihMenuUtama(void)
{ int y=0;
int Loop0=1; // loop1 baca menu,loop2 input data.

Serial.println(“pilihMenuUtama”);
while(Loop0) //loop baca #
{
y = key();
if( y == 1) // pilih menu #
{
menuUtama(); //tampilkan menu utama lalu menuju loop 2 baca keypad ke-2
Loop0=0;
}
if( y == 2) // pilih menu #
{
menuUtama1(); //tampilkan menu utama lalu menuju loop 2 baca keypad ke-2
Loop0=0;
}
} // end while(Loop0)

}
//=============================
int bacaRemotedanEnter(){
//input data integer dan tekan #
int y=0;
int Loop0=1; // loop1 baca menu,loop2 input data.
int data=0;
Serial.println(“baca remote dan enter”);
while(Loop0) //loop baca #
{
y = key();
if( y <10 ) // pilih menu 1-9
{
if(y==0 && results.value !=0xFF6897) continue;
data =data*10+y;
Serial.println(data);

}
if( y == ‘#’) // pilih menu #
{
Loop0=0;
return data;
}

delay(300); // Do not get immediate repeat
} // end while(Loop0)
}
//=============================
void menuUtama(){
Serial.println(“input plan:”);
int datahasil = bacaRemotedanEnter();
Serial.print(“hasil baca remote dan enter : “);
Serial.println(datahasil);
return;
}
void menuUtama1(){
Serial.println(“input cycle:”);
int datahasil = bacaRemotedanEnter();
Serial.print(“hasil baca remote dan enter : “);
Serial.println(datahasil);
return;
}
//=========================================
int key(void)
{

char KEY = 1 ;
while(KEY){
if (irrecv.decode(&results))
{
// Serial.println(results.value, HEX);
if(results.value != 0xFFFFFFFF)
{

y= translateIR();

KEY=0;
irrecv.resume(); // Receive the next value
return y;
}
delay(100); // Do not get immediate repeat
irrecv.resume(); // Receive the next value
}
}
}

//========================================================

int translateIR() // data tergantung kode masing2 merk remote
{
if(results.value== 0xFF30CF) return 1;
if(results.value== 0xFF18E7) return 2;
if(results.value== 0xFF7A85) return 3;
if(results.value== 0xFF10EF) return 4;
if(results.value== 0xFF38C7) return 5;
if(results.value== 0xFF5AA5) return 6;
if(results.value== 0xFF42BD) return 7;
if(results.value== 0xFF4AB5) return 8;
if(results.value== 0xFF52AD) return 9;
if(results.value== 0xFF6897) return 0;
if(results.value== 16769055) return ‘#’;

}
//======================================

hasilbacairremoteTV