Category Archives: Daftar isi

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

 

 

DVD 3 TUTORIAL Dasar Komunikasi data (RS232,Modbus RTU, RS485, NETWORK/SOCKET PROGRAMMING) READY STOCK!!!………

DVD 3  Dasar Komunikasi data READY  STOCK!!!……………. 

SILAHKAN YG MAU ORDER……..   HARGA 250 RIBU…. SELAMA MASA PROMO CUKUP BAYAR  150 RIBU SAJA.. !!!

-TUTORIAL DASAR RS232 (ada di dvd 2 juga)

-TUTORIAL DASAR RS485

TUTORIAL DASAR Modbus RTU

TUTORIAL DASAR  NETWORK/SOCKET  basic programming

hubungi :  sms/WA  089661513601.

Pengetahuan Dasar Simpan Data Char Integer dan Array di EEPROM

Contoh Code -1

void writeInteger(int addr, int dataeeprom)
{
writeeeprom(addr+1, dataeeprom & 0xff);
writeeeprom(addr, (dataeeprom>>8) & 0xff);
}

int ReadInteger(int addr)
{ char value=0,value2=0;
value = readeeprom(addr);
value2 = readeeprom(++addr);
value = (value <<8) & 0xff00;
value = value | value2;
return value;
}

void writeeeprom(unsigned int alamat, unsigned char datana)
{
while(EECR & (1<<1));
EEAR = alamat;
EEDR = datana;
EECR |= (1<<2);
EECR |= (1<<1);
delay_ms(10);
}
unsigned char readeeprom(unsigned int alamat)
{
unsigned char dataeeprom;
while(EECR & (1<<1));
EEAR = alamat;
EECR |= (1<<0);
dataeeprom=EEDR;
return dataeeprom;
delay_ms(10);
}

void simpanArrayKeEEPROM( int array[],int alamat)
{ char i=0;

for(i=0;i<13;i++)
{
writeInteger(alamat, array[i]) ;
alamat=alamat+2;
}
}

 

Contoh Kode -2 dgn menggunakan library EEPROM

#include <EEPROM.h>

void writeEepromInteger(int addr, unsigned int dataeeprom)
{
EEPROM.write(addr+1, dataeeprom & 0xff);
EEPROM.write(addr, (dataeeprom>>8) & 0xff);
delay(50);
}

int readEepromInteger(int addr)
{
int value = EEPROM.read(addr);
int value2 = EEPROM.read(++addr);
value = (value <<8) & 0xff00;
value = value | value2;
return value;
}

//contoh penggunaan fungsi writeEepromInteger()  diatas

writeEepromInteger(1,1500);   // write intger 1500 ke alamat 1 dan 2 dimemori eeprom
writeEepromInteger(4,6789);   // write intger 6789 ke alamat 4 dan 5 dimemori eeprom

//contoh penggunaan fungsi readeepromInteger()  diatas

int dataku =readEepromInteger(1);   //baca Eeprom alamat 1 dan 2 simpan sebagai integer di variable dataku

int datamu =readEepromInteger(4);

Pengetahun Dasar dan Contoh code Timer pada Arduino

Pengetahun Dasar dan Contoh code Timer pada Arduino

Pendahuluan

Cara kerja Timer Arduino sama dengan Cara kerja Timer pada timer mikrokontroller AVR yg sudah dibahas pada artikel disini.  Hal ini dikarenakan Arduino menggunakan mikrokontroler AVR sebagai chip utamanya yaitu atmega 328, atmega 1260 atmeg2560 dll.

Pada Arduino telah disediakan(ada yg membuatkan) library untuk penggunaan timer seingga kita tak perlu menetahui detail register yg dipakai.  sedang untuk menggunakan timer pada compiler lain (misal avr-gcc atau codevision) kita sendiri yg harus menseting nilai register yg mengatur timer .

pada Arduino Timer0 sebaiknya tdk kita gunakan karena timer0 dipakai oleh fungsi delay() dan milis()

 Memakai Timer dgn bantuan Library yg sdh tersedia 

berikut ini beberapa library siap pakai  sdh sy test pada Arduino Uno (CPU atmega 328) dan Arduino Mega (CPU ATmega 2560)

1.TimerLib

2.TimerOne

3.MsTimer2

Contoh :

Memakai Timer tanpa menggunakan Library 

#include <TimerOne.h>

void setup()
{
pinMode(13, OUTPUT);   

Timer1.initialize(100000); // 100.000 ms ( 0.1 sec )
Timer1.attachInterrupt( LedBlink);
}

void loop()
{

}

/// --------------------------
/// ISR Timer Routine  , nama fungsi bisa custom
/// --------------------------
void LedBlink()
{
digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}

Memakai Timer tanpa menggunakan Library 

void setup()
{
  pinMode(13, OUTPUT);

  // initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;

  TCNT1 = 34286;            // preload timer 65536-16MHz/256/2Hz
  TCCR1B |= (1 << CS12);    // 256 prescaler 
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
}

ISR(TIMER1_OVF_vect)        //nama fungsi harus "ISR(nama vector) 
{
  TCNT1 = 34286;            // preload timer
  digitalWrite(13, digitalRead(13) ^ 1);
}

void loop()
{
 
}

Cara kerjanya spt ini:

-Set durasi/periode  timer overflow  misal kita set 2 detik

-tiap 2 detik  terjadi overflow yg akan menimbulkan interupsi  (interupsi overflow)

-interupsi akan menjalankan fungsi ISR

-paramater fungsi ISR adalah nama vector atau vector name dari tiap jenis penyebab interupsi.  berikut vector name untuk tiap interupsi  timer yg lainya :

TIMER0_OVF_vect   adalah vector name  untuk interupsi overflow timer 0

TIMER1_OVF_vect    untuk timer 1

TIMER2_OVF_vect    untuk timer 2

TIMER3_OVF_vect    untuk timer 3   dst…..

Belajar VB.Net dan Arduino paket hemat..

Belajar Mudah  VB Net dan Arduino

promo2

 

Pengetahuan Dasar Komunikasi (network) VB.Net dengan Arduino Ethernet

Untuk pemula daripada nanti bingung sebaiknya baca dulu teori dasar pemrograman jaringan dan  dasar network arduino 


[Draft]

Pengetahuan Dasar Komunikasi VB.Net  dengan Arduino Ethernet

 

Pendahuluan

bla bla bla hehehuhu  sabar dulu yah

Setup Hardware :

arduinoethernet0
arduino + ethernet shield

 

arduinoethernet1

Memasang ethernet shield di atas Arduino Uno dibawah

arduinoethernet1a

Pasang  kable utp  dan usb

kalau blm punya kable UTP  pergilah ke toko komputer katakan sama mba nya ” mba beli kabel UTP semeter,  dikrimping ya ke dua ujungnya”  kalau ditanya buat apa ,katakan padanya : buat mengikat hatimu hehehe.

Set Alamat IP komputer yg akan dihubungkan dgn Arduino

sy  menggunakan win 7 ,untuk set alamat IP nya sbb:

setLANpc.jpg

alamat IP PC harus dlm grup yg sama dgn Arduino konkritnya spt ini

jika alamat Arduino 192.168.1.xxx (192.168.1 adalah alamat grup, xxx adalah alamat host )

maka IP komputer  harus sama dgn yg diatas kecuali xxx harus ,nilai xxx  1 s/d 255

contoh alamat IP ethernet shield  192.168.1.177   xxx disini kita set =177.

alamat IP komputer anda  192.168.1. 9.      xxx disini kita set= 9 ( yg penting jgn 0 atau 177)

Koneksi kabel LAN  PC dan Arduino ethernet shield sbb:

arduinoethernet3

 

Program VB.Net sbg client

contoh client VB.net mengirim string :  1234#

vbclient

Program Arduino sbg server

serverarduino

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
int i=0;
String inString = “”;
EthernetServer server(5000);
boolean alreadyConnected = false;

void setup()

{
Ethernet.begin(mac, ip);
// menunggu client
server.begin();
Serial.begin(9600);
Serial.print(“aku arduino pelayan yg sedang nunggu kerjaan”);
}
void loop() {
EthernetClient client = server.available();
if (client) {
if (!alreadyConnected) {
client.flush();   // clear bufer
Serial.println(“Wow ada tamu yg datang”);
client.println(“Hello, VB.Net ada yg bisa sy  bantu?”);
alreadyConnected = true;
}

if (client.available() > 0) {
char thisChar = client.read();     // Vb.net mengirim data angka diakhiri #
if(thisChar !=’#’)
{
inString += thisChar;
}
else
{
client.println(“hai VB.Net request sdh  kuterima tunggu sebentar ya..”);
Serial.print(“string:”);
Serial.println(inString);
Serial.print(“Nilai:”);
Serial.println(inString.toInt());
client.println(“nih aku kembalikan angkanya  aku tambah 10 ya “);
client.println(inString.toInt()+10);
client.println(“sama aku kasih bonus deh dgn hasil baca pin analog 0 : “);
int hasilPin_A0 = analogRead(A0);
client.println(hasilPin_A0);
i=0;
inString=””;
}

}
}
}

promoarduinovbnet

 

 

Pengetahuan Dasar Membaca & Menulis File dgn Vb net

Namespace yg digunakan : System.IO

Class untuk create, copy,delete,rename direktory : Class Directory

Method  Class Directory  yg sering dipakai:
Exist(path)             :   Mengecheck keberadaan file  dgn return  value boolean
CreateDirectory     :   membuat  directory
Delete(path)          :  menghapus Directory

 

Class untuk  create, copy,delete,rename file : Class File
Method  Class File  yg sering dipakai:
Exist(path)             :   Mengecheck keberadaan file  dgn return  value boolean
Delete(path)          : menghapus file
Copy(source,dest) : copy file dari path sumber ke path tujuan
Move(source,dest) : memindahkan file dari path sumber ke path tujuan

fileio

Class yg digunakan baca tulis file

  1. Class  FileStream, StreamReader dan StreamWriter  : untuk akses file text
  2. Class FileStream, BinaryReader dan BinaryWriter : untuk akses file biner

pada contoh dibawah ini digunakan membaca tulis file text.

Contoh kode VB.Net  akses file

Imports System.IO
Public Class Form1
Private Const dir As String = “C:\direktoriku\”

‘Membuat direktori

Private Sub btnBuatDirektory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuatDirektory.Click
If Not Directory.Exists(dir) Then
Directory.CreateDirectory(dir)
MessageBox.Show(“berhasil”)
Else
MessageBox.Show(“gagal atau direkstory sdh ada”)
End If
End Sub

‘Menghapus direktori

Private Sub btnHapusDirektory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapusDirektory.Click
If Directory.Exists(dir) Then
Directory.Delete(dir)
MessageBox.Show(“berhasilhapus Dir”)
Else
MessageBox.Show(“hapus gagal atau DIR tdk ada”)
End If
End Sub

‘Membuat file fileku.txt di dlm direktori C:\direktoriku\

Private Sub btnBuatFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuatFile.Click
If Not File.Exists(dir + “fileku.txt“) Then
File.Create(dir + “fileku.txt“)
MessageBox.Show(“berhasil”)

FileClose()
End If
End Sub

‘Menghapus file fileku.txt

Private Sub btnHapusFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapusFile.Click
If File.Exists(dir + “fileku.txt“) Then
File.Delete(dir + “fileku.txt“)
MessageBox.Show(“berhasilhapus”)
FileClose()
End If
End Sub

‘Menulis  data string ke file

Private Sub btnWriteFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteFile.Click
Dim konekFile As New StreamWriter(dir + “fileku.txt“)

konekFile.Write(TextBox1.Text + “, “)
konekFile.Write(TextBox2.Text + “, “)
konekFile.WriteLine(TextBox3.Text)

konekFile.Close()

‘Membaca semua isi file

End Sub

Private Sub btnReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadFile.Click
Dim konekFile As New StreamReader(dir + “fileku.txt“)
txtAll.Text = konekFile.ReadToEnd
konekFile.Close()

End Sub

‘Membaca data file perbaris

Private Sub btnReadBaris_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadBaris.Click
Dim objBacaFile1 As New StreamReader(dir + “fileku.txt“)
TextBox1.Text = objBacaFile1.ReadLine
TextBox2.Text = objBacaFile1.ReadLine
TextBox3.Text = objBacaFile1.ReadLine
objBacaFile1.Close()
End Sub

‘Menulis data tanpa menghapus data yg ada  dlm file

Private Sub btnWriteAppend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteAppend.Click
Dim objTulisFile As New StreamWriter(New FileStream(dir + “fileku.txt“, FileMode.Append, FileAccess.Write))
objTulisFile.Write(TextBox1.Text + “,”)
objTulisFile.Write(TextBox2.Text + “,”)
objTulisFile.WriteLine(TextBox3.Text)
objTulisFile.Close()
End Sub

‘Membaca data file per baris

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objBacaFile As New StreamReader(New FileStream(dir + “fileku.txt“, FileMode.OpenOrCreate, FileAccess.ReadWrite))
TextBox1.Text = objBacaFile.ReadLine
TextBox2.Text = objBacaFile.ReadLine
TextBox3.Text = objBacaFile.ReadLine
objBacaFile.Close()
End Sub

‘ Membaca  file dan parsing   data string  , contoh isi file: 123,765,987,..dst

Private Sub btnReadSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSplit.Click
Dim objBacaFile3 As New StreamReader(New FileStream(dir + “fileku.txt“, FileMode.OpenOrCreate, FileAccess.ReadWrite))

Do While objBacaFile3.Peek <> -1

Dim baris As String = objBacaFile3.ReadLine
Dim dataKolom() As String = baris.Split(CChar(“,”))
TextBox1.Text = dataKolom(0)
TextBox2.Text = dataKolom(1)
TextBox3.Text = dataKolom(2)

Loop

objBacaFile3.Close()

End Sub
End Class

Pengetahuan Dasar Membuat Grafik Real Time VB.Net Data Serial Port Arduino

Pengetahuan Dasar Membuat Grafik Real Time Data Serial Port

Aplikasi yg dibutuhkan
VB.Net
Codevision atau Arduino

ARDUINO_MODUL

Hardware yg dibutuhkan
Usb to Serial
Mikrocontroller board AVR atau Arduino board

Tahapan Pembuatan aplikasi VB.Net

-Buka project baru

-pada form tambahkan komponen Chart,timer, textbox,listbox  dan button

-Atur tata letak komponen chart,textbox,buton pada form

graph

Kode ProgramVB.Net 2010
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.Threading.Thread
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Dim data As String
Dim frek As String
Dim RXArray(2047) As Char
Dim RXCnt As Integer ‘
Dim time As String
Dim frekwensi As String
Dim engChart As New Series

Dim WithEvents COMPort As New SerialPort

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub
Private Sub ClosePort()
If COMPort.IsOpen Then
COMPort.Close()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If COMPort.IsOpen Then
COMPort.Close()
Label3.Text = “koneksi berhasil ditutup”

End If
End Sub

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
ComboBox1.Items.Add(COMString)
Next
Chart1.Series.Clear()
Chart1.Titles.Add(“data serial real time”)
engChart.Name = “analog in”
engChart.ChartType = SeriesChartType.Line
Chart1.Series.Add(engChart)
Chart1.ForeColor = Color.Cyan
ComboBox1.Focus()
RXCnt = 0

End Sub

‘=================================================================

‘=================================================================
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
Dim RXByte As Byte

Do
RXByte = COMPort.ReadByte
RXArray(RXCnt) = Chr(RXByte)

If Chr(RXByte) = Chr(13) Then
Me.Invoke(New MethodInvoker(AddressOf Display))
RXCnt = 0
End If
RXCnt = RXCnt + 1

Loop Until (COMPort.BytesToRead = 0)
End Sub

Private Sub Display()
data = (New String(RXArray, 1, RXCnt))

TextBox1.Text = data

DoUpdate()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
time = TimeOfDay
End Sub
Public Sub DoUpdate()

Try
engChart.Points.AddXY(time, data)
Catch ex As Exception

Label3.Text = ex.Message
Finally

End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If COMPort.IsOpen Then
COMPort.RtsEnable = False
COMPort.DtrEnable = False
ClosePort()

Application.DoEvents()
Sleep(200)
End If
COMPort.PortName = ComboBox1.Text
COMPort.BaudRate = 9600
COMPort.WriteTimeout = 2000
Try
COMPort.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try

If COMPort.IsOpen Then
COMPort.RtsEnable = True
COMPort.DtrEnable = True

Label3.Text = “koneksi berhasil dibuka”
End If
End Sub
End Class

kode program Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
// baca  analog pin 0:
int sensorValue = analogRead(A0);
// kirim hasil ke serial
Serial.println(sensorValue);
delay(1000);
}

Kode progrtam AVR codevision

/*****************************************************
Date : 13/08/2016
Chip type : ATmega16
Clock frequency : 11,059200 MHz
kontinyu kirim data :50987<0D>60734<0D>dst..
*****************************************************/

#include <mega16.h>
#include <stdio.h>
#include <delay.h>

unsigned int i;
void main(void)
{
// 8 Data, 1 Stop, No Parity
// Baud rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

while (1)
{
i++;
putchar(i/1000 %10 + 0x30);
putchar( i/100 %10 + 0x30);
putchar(i/10 %10 + 0x30);
putchar(‘.’);
putchar(i % 10 + 0x30);
putchar(‘\r’) ;
delay_ms(600);

};
}

promoarduinovbnet

Contoh kode Arduino Menulis String data ke Mifare RFID Tag

contoh string yg akan ditulis  “tgl 20/07/2016 NO ST:001/ST/SDI-SYM/VII/2016 Rp.50.000,-#” .
string diatas dikirim dari serial port dan di simpan kedalam array buffer[64].
krn tiap 1 blok tag rfid cuma ada 16 byte maka string diatas ditulis ke dalam 4 blok yaitu blok 1,2 4 dan 5
blok 3,7,11, 15, 19… dst tdk boleh untuk menyimpan data krn berisi data untuk authentifikasi

/*
*menulis string ke MIFARE RFID card menggunakan RFID-RC522 reader
—————————————————————————–
* Pin layout should be as follows:
* Signal Pin Pin Pin
* Arduino Uno Arduino Mega MFRC522 board
* ————————————————————
* Reset 9 5 RST
* SPI SS 10 53 SDA
* SPI MOSI 11 52 MOSI
* SPI MISO 12 51 MISO
* SPI SCK 13 50 SCK
*————————————————————–

*/

#include  SPI.h
#include  MFRC522.h
//atur kembali konfigurasi pin sesuai modul arduino anda
#define SS_PIN 10 //Arduino Uno
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(“Write string data on a MIFARE PICC “);
}

void loop() {

// Prepare key – all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) return;

Serial.print(“Card UID:”); //kirim UID ke serial port
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “);
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print(” PICC type: “); // kirim PICC type ke serial port
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));

byte buffer[64]; //untuk menampung string dari serial port
byte block;
byte status, len;

Serial.setTimeout(20000L) ; // time out serial port 20 detik
// input string
Serial.println(“masukan data string akhiri dgn #”);
len=Serial.readBytesUntil(‘#’, (char *) buffer, 64) ; // terima data string dari serial
for (byte i = len; i < 64; i++) buffer[i] = ‘\s’; // sisa bufer disi kode spasi

block = 1;
//Serial.println(“Authenticating using key A…”);
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(“PCD_Authenticate() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}

// Write block
status = mfrc522.MIFARE_Write(block, buffer, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print(“MIFARE_Write() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(“MIFARE_Write() success: “);

block = 2;
//Serial.println(“Authenticating using key A…”);
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(“PCD_Authenticate() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}

// Write block
status = mfrc522.MIFARE_Write(block, &buffer[16], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print(“MIFARE_Write() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(“MIFARE_Write() success: “);
block = 4;
//Serial.println(“Authenticating using key A…”);
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(“PCD_Authenticate() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}

// Write block
status = mfrc522.MIFARE_Write(block, &buffer[32], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print(“MIFARE_Write() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(“MIFARE_Write() success: “);

block = 5;
//Serial.println(“Authenticating using key A…”);
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(“PCD_Authenticate() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}

// Write block
status = mfrc522.MIFARE_Write(block, &buffer[48], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print(“MIFARE_Write() failed: “);
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(“MIFARE_Write() success: “);

Serial.println(” “);
mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD

}