Tutorial Membuat RTU Arduino
By : Fuad Hasan
Bahan :
Arduino uno
Ethernet shield R3
Board Digital dan Analog
Kabel UTP
Kabel data arduino
Software :
Arduino IDE
Modscan32
Langkah-langkah:
Masukkan library Mudbus ke folder C:\Program
Files\Arduino\libraries
Run Software Arduino, bisa download disini
https://www.arduino.cc/en/Main/Software
Masukin sketch pinMode(A1, OUTPUT);
pinMode(7, OUTPUT);
/*
pinMode(8, OUTPUT);
Author : Fuad Hasan
pinMode(9, OUTPUT);
*/
Mb.R[21] = 1987;
#include <SPI.h>
}
#include <Ethernet.h>
void loop()
#include "Mudbus.h"
{
Mudbus Mb;
Mb.Run();
//Function codes 1(read coils), 3(read registers), 5(write
coil), 6(write register) //Analog inputs 0-1023
//signed int Mb.R[0 to 125] and bool Mb.C[0 to 128] Mb.R[0] = (analogRead(A2)*1); // tegangan
MB_N_R MB_N_C Mb.R[1] = (analogRead(A4)*1); // arus
//Port 502 (defined in Mudbus.h) MB_PORT Mb.R[2] = (analogRead(A3)*1); // temperature
void setup() //Digital inputs
{ Mb.C[0] = digitalRead(2);
uint8_t mac[] = { 0x91, 0xA1, 0xDA, 0x00, 0x52, 0x05 }; Mb.C[1] = digitalRead(5);
uint8_t ip[] = { 192, 168, 1, 10 }; Mb.C[2] = digitalRead(6);
uint8_t gateway[] = { 192, 168, 1, 1 }; //Digital outputs
uint8_t subnet[] = { 255, 255, 255, 0 }; digitalWrite(7, Mb.C[4]);
Ethernet.begin(mac, ip, gateway, subnet); digitalWrite(8, Mb.C[5]);
//Avoid pins 4,10,11,12,13 when using ethernet shield digitalWrite(9, Mb.C[6]);
delay(3000); digitalWrite(A1, Mb.C[7]);
Serial.begin(9600); digitalWrite(A0, Mb.C[8]);
pinMode(2, INPUT); }
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(A0, OUTPUT);
Klik Verify untuk Compile sketch
yang dicopy tadi
Setting board dan port arduino
Pilih Tool – board – arduino uno
Pilih Tool – Port- com (sesuai arduino, cek di device
manager)
Upload Sketch ke arduino
Settiing IP laptop/PC 192.168.1.87(87 bisa di ganti angka
lain selain 10(ip RTU) dan 1(ip gateway))
Tancapkan Ethernet shield to arduino
Tancapkan kabel UTP to port RJ45 ethernet shield dan
port RJ45 laptop
Cek komunikasi RTU menggunakan Command Promt
(CMD)
Ketik perintah : Ping 192.168.1.10 untuk cek sesaat
Ketik perintah : Ping 192.168.1.10 –t untuk cek seterusnya
Test RTU menggunakan modscan32
Setelah koneksi menggunakan modscan berhasil, itu
menandakan RTU Modbus TCP arduino sudah sukses.