HMI WEINTEK Connect Arduino Menggunakan protokol Modbus RTU

 HMI WEINTEK Connect Arduino Menggunakan protokol Modbus RTU 

Download Software EasybuilderPro

    Klik DIsini Untuk mendownload software Easybuilder pro

Download Program HMI

    Klik Disini untuk Download Program HMI Weintek

Download Program Arduino


/****Arduino MODBUS RTU***
 * 
 * Source Code By : Lukman Amirul F ( dengan Bantuan Kopas Kono kene :v)
 * 
 * MODBUS library written by Jason Vreeland [CodeRage]
 * Released 3/7/2010 under GNU license
 * https://code.google.com/archive/p/arduino-modbus-slave/downloads
 */
#include <modbus.h>
#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>
modbusDevice regBank;
modbusSlave slave;

#define GREEN_LED 3
#define RED_LED 5
#define BUTTON 2
#define POTENTIOMETER A0

void setup()
{   
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);

  //Assign the Modbus Slave ID.
  regBank.setId(1);

  //Add Digital Output registers
  regBank.add(1);

  //Add Digital Input registers
  regBank.add(10001);
  
  //Add Analog Output registers  
  regBank.add(40010);   
  
  //Analog input registers
  regBank.add(30001);
  
  slave._device = &regBank; 
  // Initialize the baudrate serial port 
  // Set in SCADA: Baud rate=9600,Data bits=8,Stop bits=1,Parity=None,Flow control=None
  slave.setBaud(9600);  
}

void loop()
{
  //Digital output
  int DO3 = regBank.get(1);
  if (DO3 <= 0 && digitalRead(GREEN_LED) == HIGH)digitalWrite(GREEN_LED,LOW);
  if (DO3 >= 1 && digitalRead(GREEN_LED) == LOW)digitalWrite(GREEN_LED,HIGH);
  
  //Digital Input
  byte DI2 = digitalRead(BUTTON);
  if (DI2 >= 1)regBank.set(10001,0);
  if (DI2 <= 0)regBank.set(10001,1);
    
  //Analog input
  regBank.set(30001, (word)analogRead(POTENTIOMETER));

  //Analog output 
  word AO10 = regBank.get(40010);
  analogWrite(RED_LED,AO10);
  
  slave.run();
  delay(100);
}


    Klik Disini untuk Download program Arduino

Lebih Jelasnya Anda bisa Tonton Video Berikut :




Komentar

Postingan populer dari blog ini

Mengirim Data Sensor dari NodeMcu ESP8266 ke Spreeadshets atau Google Sheets