Introducción
En este tutorial te guiaremos por el proceso de configuración y uso de la comunicación RS-485 con los PLCs Arduino y ESP32 de Industrial Shields. RS-485 es un estándar robusto y ampliamente utilizado en comunicación industrial, ideal para conectar dispositivos a larga distancia en entornos con interferencias. Ya sea que estés integrando tu PLC en una red Modbus o habilitando la comunicación con otros dispositivos RS-485, esta guía cubre todos los pasos esenciales tanto para la configuración hardware como software.
Este tutorial está diseñado para las siguientes familias de PLCs de Industrial Shields, garantizando compatibilidad y facilidad de uso:
- Familia M-Duino PLC
- Familia Ardbox PLC
- Familia ESP32 PLC
- ESP32 PLC 14
Al finalizar esta guía, tendrás un conocimiento completo de cómo configurar la comunicación RS-485, incluyendo el cableado, la configuración de librerías de software y la implementación de tu primer programa de comunicación. Tanto si eres un profesional experimentado como si eres nuevo en el mundo de los PLCs, este tutorial te proporciona las bases que necesitas para aprovechar RS-485 en tus proyectos de automatización.
Hardware
M-Duino PLC Family Hardware
The M-Duino PLC features one RS-485 port formed by pins A+, B-, Y+ and Z-.
This means that the communication with another device using RS-485 can be either:
- Half-Duplex (HD) using A+ and B-.
- Full-Duplex (FD) using A+, B-, Y+ and Z-.
Switch configurations
To use the RS-485 communication, configure the communications switch as follows:
- Set bottom switch 1 to OFF to use HD communication
- Set bottom switch 1 to ON to use FD communication
Connections
Typically, the connections between devices are:
- For HD communication: A+ with A+ and B- with B-
- For HD communication: A+ with Y+, B- with Z-, Y+ with A+ and Z- with B-.
For more information, check the Technical Features
Ardbox PLC Family Hardware
The Ardbox family PLCs features one RS-485 port formed by pins A+, B-, Y+ and Z-.
This means that the communication with another device using RS-485 can be either:
- Half-Duplex (HD) using A+ and B-.
- Full-Duplex (FD) using A+, B-, Y+ and Z-
Configuración de switches
To use the RS485 communication of the Ardbox Relay, configure the communications switch as follows:
- Set top switch 1 to ON
- Set top switch 2 to OFF
- Set top switch 3 to ON
- Set top switch 4 to OFF
- Set right top switch 2 to select between HD and FD
- Set right bottom switch 1 to ON
- Set right bottom switch 2 to OFF
- Set right bottom switch 3 to ON
- Set right bottom switch 4 to OFF
To use the RS485 communication of the Ardbox Analog, configure the communications switch as follows:
- Set top switch 1 to OFF
- Set top switch 2 to ON
- Set top switch 3 to OFF
- Set top switch 4 to ON
- Set right top switch 1 to select between HD and FD
Conexiones
Typically, the connections between devices are:
- For HD communication: A+ with A+ and B- with B-.
- For HD communication: A+ with Y+, B- with Z-, Y+ with A+ and Z- with B-.
For more information, check the Technical Features.
ESP32 PLC Family Hardware
The ESP32 PLC features one RS485 port formed by pins A+ and B-.
Switch Configurations
To use this port, ensure that switch 3 is set to OFF on the communications switch.
Connections
Connect the A+ and B- pins to your desired device for RS485 communication. Typically, the connections between devices are: A+ with A+ and B- with B-.
For more information, check the Technical Features
ESP32 PLC 14 Hardware
The ESP32 PLC features one RS485 port formed by pins A+ and B-.
Switch Configurations
There are no switch configurations needed for this device.
Connections
Connect the A+ and B- pins to your desired device for RS485 communication. Typically, the connections between devices are: A+ with A+ and B- with B-.
For more information, check the Technical Features
Software
Install the industrialshields-avr board on the Arduino IDE. You can do it by following this tutorial.
Selecciona tu placa y modelo:
- For M-Duino PLC Family: Tools > Board > Industrial Shields AVR Boards > M-Duino [Extension] family and Tools > Model > M-Duino [Module]
- For Ardbox PLC Family: Tools > Board > Industrial Shields AVR Boards > Ardbox [Extension] family and Tools > Model > Ardbox [Module] HF+ w/HW RS-485
- For ESP32 PLC Family: Tools > Board > Industrial Shields ESP32 Boards > ESP32 PLC Family and Tools > Model > ESP32 PLC [Module]
- For ESP32 PLC 14: Tools > Board > Industrial Shields ESP32 Boards > 14 IOS PLC Family
Include the RS485 library in your code and use RS485 to refer to the RS485 port.
Make sure that the baudrate and duplex mode is the same in the all the devices.
Some basic functions
1. Iniciar el puerto RS485:
RS485.begin(BAUDRATE, HALFDUPLEX);
2. Enviar datos:
RS485.write(tx);
3. Comprobar si hay datos disponibles y leerlos
if (RS485.available()) {
byte rx = RS485.read();
}
Consulta el siguiente código de prueba RS-485: