Category Archives: Dasar

Pengetahuan dasar umum yang membantu memahami PC Control

Contoh Code Parsing Data string Serial Arduino

 

String readString; //main captured String

String data1; //data String
String data2;
String data3;
String data4;
String data5;

//format data diterima   dari pc atau arduino lainya : 123a123b123c123d123*

void setup()
{
Serial1.begin(9600);

}

void loop()
{
TerimaData();
}//loop

void TerimaData(void)
{

if( Serial1.available())
{

//=================
char c = Serial1.read();           //gets one byte from serial buffer
if (c == ‘*’)
{
ind1 = readString.indexOf(‘a’); //finds location of first ,
data1 = readString.substring(0, ind1); //captures first data String

ind2 = readString.indexOf(‘b’, ind1+1 ); //finds location of second ,
data2 = readString.substring(ind1+1, ind2+1); //captures second data String

ind3 = readString.indexOf(‘c’, ind2+1 );
data3 = readString.substring(ind2+1, ind3+1);

ind4 = readString.indexOf(‘d’, ind3+1 );
baris4 = readString.substring(ind3+1); //captures remain part of data after last ,

ind5 = readString.indexOf(‘*’, ind4+1 );
data5 = readString.substring(ind4+1); //captures remain part of data after last ,

readString=””; //clears variable for new input

data1=””;
data2=””;
data3=””;
data4=””;
data5=””;
}
else
{
readString += c;     //  data serial yg dibaca gabungkan
}

}

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 Membuat Aplikasi VB.Net untuk Monitoring Counter Produksi via LAN

sumber  :  www.counterproduksi.com

Panduan teknis  untuk membaca/menulis  data  ke  mikro counter dan Andon 7 segment maupun Andon matrik p10.

vbcounter

Untuk  mengakses data counter menggunakan aplikasi VB.Net atau C#  anda akan diberikan class library untuk setiap pembelian counter produksi. Dengan class library ini pemrograman VB.net atau C# untuk mengakses data counter menjadi sangat mudah  dilakukan.

vbcounter

Step by step Cara Mengakses (baca/tulis)  Data Counter dengan VB.Net  via LAN (TCP)

1. Menambahkan library counter*  ke dalam projet VB.net

Melalui menu Project->Add reference
Lalu pada code tambahkan:
Imports CounterTCP
——————————————————————————–
2. Membuat Obect counter

Private CounterLineA As CounterTCP.Client
Private CounterLineB As CounterTCP.Client

——————————————————————————–
3. Membuat koneksi ke Counter

Try
‘ Create new client Counter  and add event functions
CounterLineA = New Client(txtAlamatIPLineA..Text, NoPort)

AddHandler CounterLineA.OnResponseData, New CounterTCP.Client.ResponseData(AddressOf CounterLineA_OnResponseData)

Catch [error] As SystemException
‘MessageBox.Show([error].Message)
End Try
——————————————————————————–
4. Membaca Counter

// Membaca data Counter Line A
Try
CounterLineA.ReadDataCounter( 0, 15)  ‘baca data  0 – 15
Catch [error] As SystemException
MessageBox.Show(“READ EROR”)
End Try

// Membaca data Counter Line B
Try
CounterLineB.ReadDataCounter( 0, 15)  ‘baca data  0 – 15
Catch [error] As SystemException
MessageBox.Show(“READ EROR”)
End Try

——————————————————————————– 
5. Menampilkan Data Counter ke Form

Private Sub CounterLineA_OnResponseData()

Dim data As Byte()

data = values
TextBox1.Text = (data(0) * 256 + data(1)).ToString()   ‘ data  ke-1  plan
TextBox2.Text = (data(2) * 256 + data(3)).ToString()  ‘data ke-2    actual
TextBox3.Text = (data(4) * 256 + data(5)).ToString()   ‘data ke-3   target
TextBox4.Text = (data(6) * 256 + data(7)).ToString()    ‘data ke- 4… dst

End Sub
——————————————————————————–

6. Menulis data ke   Counter

Private Sub Button9_Click()
Dim data(1) As Integer
Dim Address As UShort

Address = Convert.ToUInt16(txtAdress.Text)
data(0) = Convert.ToInt16(txtData.Text)

Try
CounterLineA.WriteDataCounter(Address, data)
Catch [error] As SystemException
MessageBox.Show([error].ToString)
End Try

End Sub

——————————————————————————–
7. Memutus koneksi aplikasi  dgn  Counter

CounterLineA.disconnect()

——————————————————————————–

Contoh Form menampilkan data Counter

form display counter

*Class Library Counter untuk VB.net / C# disertakan pada setiap pembelian counter produksi  . www.counterproduksi.com

iklan

 

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);
}