Category Archives: Daftar isi

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(“/”);
//print2digits(waktu.Year+1904);
//lcd.setCursor(4, 3);
//lcd.print(waktu.Wday);
}

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

 

Advertisements

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();
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+1904);
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

Pengetahuan Dasar Membuat Master Modbus RTU dengan VB.net

Pengetahuan Dasar Membuat Master Modbus RTU dengan VB.net

vbmastermodbusrtu

Langkah Langkah Membuat master Modbus RTU  dgn VB Net

-Buat  Project VB Net baru

-Buat Form spt pada gambar diatas

-simpan project

-copy file library pccontrolwordpress.dll ke folder  bin\debug  (di folder project disimpan)

-add reference  arahkan ke file pccontrolwordpress.dll

-untuk mendapatkan file library pccontrolwordpress.dll bisa di download di https://drive.google.com/open?id=0BzD886yEhaFrWTcxa1NTSnVINmc

untuk membuat objek modbus ketik di bagian paling atas

Dim objcounter As pcontrolWordpress.ModbusRTU = New pcontrolWordpress.ModbusRTU

untuk melihat class modbusRTU dan method2 yg ada dilibrary  pccontrolworpress.dll klik menu object browser .

untuk Kode pada vb net

Imports pcontrolWordpress.Modbus
Public Class Form1
Dim objcounter As pcontrolWordpress.Modbus = New pcontrolWordpress.Modbus
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each COMString As String In My.Computer.Ports.SerialPortNames ‘ Load all available COM ports.
ComboBox1.Items.Add(COMString)
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If objcounter.Open(ComboBox1.Text, 19200, 8, 0, IO.Ports.StopBits.One) = True Then
LabelStatus.Text = objcounter.counterStatus
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If objcounter.Close Then
LabelStatus.Text = objcounter.counterStatus
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim data(6) As Short

If objcounter.ReadMultipleRegisters(Convert.ToByte(txtAlamatSlave.Text), 0, 6, data) = True Then
For i = 0 To 5
ListBox1.Items.Add((40001 + i).ToString + ” = ” + data(i).ToString)
Next i
LabelStatus.Text = objcounter.counterStatus
End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim data(1) As UShort

data(0) = Convert.ToUInt16(txtNilaiReg.Text)

If objcounter.WriteMultipleRegisters(Convert.ToByte(txtAlamatSlave.Text), Convert.ToUInt16(txtStartReg.Text), Convert.ToUInt16(txtQtyReg.Text), data) Then
LabelStatus.Text = objcounter.counterStatus
End If

End Sub
End Class

penjelasan  tentang dasar modbus  anda bisa lihat di video tutorial DVD 3.

hasil eksekusi program diatas antara lain

mastermodbusrtuhasil