Integrating Arduino with CODESYS Systems
Integrating Arduino with CODESYS Systems
CODESYS cannot be run directly on Arduino hardware due to the lack of official support and insufficient operating system or memory resources available on microcontrollers like ATmega328 or ESP32, which are commonly used in Arduino systems .
Serial/USB communication between Arduino and CODESYS, such as a connection to a Raspberry Pi or IPC with UART, is a cost-effective method for data exchange. Using SysCom libraries in CODESYS allows serial data read/write operations. One limitation is the need for message parsing logic on the receiving side since Arduino typically sends structured messages over Serial/USB .
Arduino can be configured as a Modbus slave while CODESYS acts as the Modbus master. In this setup, an Arduino device equipped with Modbus libraries such as ModbusRTU or ModbusTCP can connect over Serial or Ethernet with a CODESYS-controlled system configured as the Modbus master. This allows for simple sensor and actuator communication .
In an Arduino and CODESYS communication setup utilizing MQTT, a broker serves as an intermediary that manages the distribution of messages between clients. Mosquitto is an example of a tool that can be used as an MQTT broker, facilitating communication by allowing Arduino to publish and CODESYS to subscribe to the same MQTT topics .
Using CAN bus for communication between Arduino and CODESYS is advantageous due to its structured and industrial-standard nature, which allows for reliable and fast message exchange. However, Arduino requires a CAN shield to communicate over CAN, while CODESYS must support CANopen to properly integrate into the industrial communication framework .
MQTT protocol can be used by Arduino to publish or subscribe data to a broker, and CODESYS can also subscribe to or publish on the same MQTT topics by using its MQTT client libraries. This setup is beneficial for IoT and wireless systems, enabling devices to communicate over the internet or private networks .
Choosing serial/USB communication for connecting Arduino with CODESYS is relatively low-cost since it only requires basic serial communication setups commonly available on Arduino boards and CODESYS-compatible devices like Raspberry Pi. In contrast, CAN bus necessitates purchasing additional hardware like CAN shields and potentially higher costs for CANopen support. MQTT might require investment in network setup and broker services, particularly for secure and distributed systems, making serial/USB the most budget-friendly option .
To utilize CAN bus for Arduino and CODESYS integration, the hardware requirements include installing a CAN shield on the Arduino. The communication protocol requires both Arduino and the CODESYS PLC to support CAN messages, with CODESYS using the CANopen protocol for structured communication .
MQTT might be preferred over Modbus for connecting Arduino with CODESYS in scenarios that involve IoT applications and require wireless capabilities. MQTT's lightweight messaging protocol is ideal for devices that are distributed over large areas, enabling publish/subscribe messaging over the internet or other networks, whereas Modbus is more suitable for simpler, local wired communication setups .
When using Modbus for temperature sensor data transfer from Arduino to CODESYS, Arduino reads the temperature from a sensor like a DHT and writes this data to a Modbus holding register (e.g., 40001). CODESYS then reads this register to obtain the temperature value, which can be displayed in an HMI. The steps involve setting up Modbus communication libraries on Arduino, configuring Modbus master settings in CODESYS, and ensuring reliable data exchange over Serial or Ethernet .