modbus communication with arduino etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Modbus really common communication protocol with RS485 physical layer in the industry.
Novadays its really popular to work with arduino to communicating between industrial equipments,controllers,sensors etc.
the pic above is rs485 to tll card for arduino and we will use it to take modbus messages to covert rx-tx signals.
Here is our rs485 shiled connection.As you see it uses max485 chip inside
Each device which has modbus communication feature should be connected as parallel as shown here.We dont want to mention about modbus protocol in here.You can search the blog for modbus communication features more detail.
Rs485 shield connection with arduino
DI (data in) to pin 11
RO (receive out) to pin 10
DE (data enable) and RE (receive enable) jumpered together and to pin 3
Vcc and Gnd connected
A and B : the RS485 pair
Gnd between distant Arduinos can be in cable or local electrical ground.
Novadays its really popular to work with arduino to communicating between industrial equipments,controllers,sensors etc.
the pic above is rs485 to tll card for arduino and we will use it to take modbus messages to covert rx-tx signals.
Here is our rs485 shiled connection.As you see it uses max485 chip inside
Each device which has modbus communication feature should be connected as parallel as shown here.We dont want to mention about modbus protocol in here.You can search the blog for modbus communication features more detail.
Rs485 shield connection with arduino
DI (data in) to pin 11
RO (receive out) to pin 10
DE (data enable) and RE (receive enable) jumpered together and to pin 3
Vcc and Gnd connected
A and B : the RS485 pair
Gnd between distant Arduinos can be in cable or local electrical ground.
Arduino master Codes (not modbus rs485 serial communication):
#include <SoftwareSerial.h> /*-----( Declare Constants and Pin Numbers )-----*/ #define SSerialRX 10 //Serial Receive pin #define SSerialTX 11 //Serial Transmit pin #define SSerialTxControl 3 //RS485 Direction control #define RS485Transmit HIGH #define RS485Receive LOW #define Pin13LED 13 /*-----( Declare objects )-----*/ SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX /*-----( Declare Variables )-----*/ int byteReceived; int byteSend; void setup() /****** SETUP: RUNS ONCE ******/ { // Start the built-in serial port, probably to Serial Monitor Serial.begin(9600); Serial.println("YourDuino.com SoftwareSerial remote loop example"); Serial.println("Use Serial Monitor, type in upper window, ENTER"); pinMode(Pin13LED, OUTPUT); pinMode(SSerialTxControl, OUTPUT); digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver // Start the software serial port, to another device RS485Serial.begin(4800); // set the data rate }//--(end setup )--- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { digitalWrite(Pin13LED, HIGH); // Show activity if (Serial.available()) { byteReceived = Serial.read(); digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit RS485Serial.write(byteReceived); // Send byte to Remote Arduino digitalWrite(Pin13LED, LOW); // Show activity delay(10); digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit } if (RS485Serial.available()) //Look for data from other Arduino { digitalWrite(Pin13LED, HIGH); // Show activity byteReceived = RS485Serial.read(); // Read received byte Serial.write(byteReceived); // Show on Serial Monitor delay(10); digitalWrite(Pin13LED, LOW); // Show activity }
Arduino Slave Codes (not modbus rs485 serial communication) :
#include <SoftwareSerial.h> /*-----( Declare Constants and Pin Numbers )-----*/ #define SSerialRX 10 //Serial Receive pin #define SSerialTX 11 //Serial Transmit pin #define SSerialTxControl 3 //RS485 Direction control #define RS485Transmit HIGH #define RS485Receive LOW #define Pin13LED 13 /*-----( Declare objects )-----*/ SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX /*-----( Declare Variables )-----*/ int byteReceived; int byteSend; void setup() /****** SETUP: RUNS ONCE ******/ { // Start the built-in serial port, probably to Serial Monitor Serial.begin(9600); Serial.println("SerialRemote"); // Can be ignored pinMode(Pin13LED, OUTPUT); pinMode(SSerialTxControl, OUTPUT); digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver // Start the software serial port, to another device RS485Serial.begin(4800); // set the data rate }//--(end setup )--- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { //Copy input data to output if (RS485Serial.available()) { byteSend = RS485Serial.read(); // Read the byte digitalWrite(Pin13LED, HIGH); // Show activity delay(10); digitalWrite(Pin13LED, LOW); digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit RS485Serial.write(byteSend); // Send the byte back delay(10); digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit // delay(100); }// End If RS485SerialAvailable
you can find modbus libraries and examples in here