RS-485 's Introduction
Previous reading
Requirements for working with RS-485
RS-485 in M-Duino
RS-485 in Ardbox
For the Ardbox family we have two subfamilies. In this one, we have to choose between RS-485 and RS-232 using the switches and jumpers as we show in the following image:
Hardware
The first thing we need to do is to be sure that the industrial Arduino PLC is supplied with 12-24Vdc.
The pins of the PLC that we have to use for RS-485 communication.
#include <RS485.h>
To check the RS-485 activation you only have to use the serial monitor from the Arduino IDE using the right sentence inside the setup() function.
Serial.begin(9600);
It is also important to implement the initialization on the setup() function.
RS485.begin(38400);
IMPORTANT❗: CHECK THE SPEED OF TRANSMISSION OF PLC-LAPTOP AND PLC-DEVICES.
A basic example of writing in the RS-485:
// Include Industrial Shields libraries
#include <RS485.h>
//// IMPORTANT: check switches configuration
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Begin serial port
Serial.begin(9600);
// Begin RS485 port
RS485.begin(38400);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Wait bytes in the serial port
if (Serial.available()) {
byte tx = Serial.read();
// Echo the byte to the serial port again
Serial.write(tx);
// And send it to the RS-485 port
RS485.write(tx);
}
}
// And send it to the RS-485 port
RS485.write(tx);
}
}
A basic example of reading of the RS-485:
// Include Industrial Shields libraries
#include <RS485.h>
//// IMPORTANT: check switches configuration
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Begin serial port
Serial.begin(9600);
// Begin RS485 port
RS485.begin(38400);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Print received byte when available
if (RS485.available()) {
byte rx = RS485.read();
// Hexadecimal representation
Serial.print("HEX: ");
Serial.print(rx, HEX);
// Decimal representation
Serial.print(", DEC: ");
Serial.println(rx, DEC);
}
}
Basic Full Duplex example of RS-485:
Before starting the test, connect A, B (receivers) to the Y, Z (transmitters).
Basics about RS-485 of an industrial PLC