In the field of modern industrial control, industrial equipment of various types and levels usually adopts differentiated communication protocols for data interaction, resulting in widespread problems of poor protocol compatibility and heterogeneous communication. Modbus RTU features a simple structure and excellent universality, which is widely applied to low-speed sensors, serial lower computers and other industrial devices. In contrast, EtherCAT possesses nanosecond-level synchronization accuracy, high real-time performance and high bandwidth, and is mostly used in real-time control scenarios such as servo drives and high-speed I/O devices. To solve the difficulties in data intercommunication and high protocol adaptation cost between devices with the two protocols, this paper develops a multi-protocol hybrid gateway with both real-time motion control and low-speed serial acquisition capabilities based on the Raspberry Pi 5 development board. Built on open-source protocol stacks, the gateway realizes data transparent transmission and protocol conversion between the high-speed EtherCAT bus and the Modbus RTU serial bus. Meanwhile, it is equipped with a visual human-computer interaction interface to complete real-time monitoring and manual control of EtherCAT slave devices and Modbus acquisition equipment. With a concise structure and strong scalability, this design can provide a reference for multi-protocol integration schemes of small and medium-sized industrial control systems.
Hardware Design
For the Modbus RTU part, a self-developed Modbus RFID reader is applied, as shown in the figure below. It is designed based on the STM32F0 chip and supports Modbus RTU communication and RS485 interface.
The schematic diagram is shown below. The FM17550 is adopted as the RFID radio frequency chip.
For the EtherCAT slave device, AX58100 is used as the ESC chip and STM32F411 serves as the main control MCU. The LEDs on the core board can be controlled by the main station.
The schematic of the AX58100 circuit is shown below. Two RJ45 network interfaces are led out, serving as the IN and OUT ports for EtherCAT communication respectively.
A 1280×800 capacitive touch screen is adopted as the display device. All wiring of the Modbus RFID reader, EtherCAT slave device, Raspberry Pi and the touch screen are completed as shown in the figure below.
Software Design
Open-Source Protocol Stack Software
According to the project requirements, it is necessary to select the communication protocol stack software. The software scheme is designed as follows:
For EtherCAT communication, SOEM is adopted as the EtherCAT master protocol stack software.
For Modbus communication, libmodbus is adopted as the Modbus master protocol stack software.
For the UI interaction part, Dear ImGui is used as the GUI library.
Links to several open-source software packages are listed below:
Next, the above protocol stack software needs to be integrated. This project uses CMake as the build system, and the CMake scripts are developed as follows. The content of the ImGui CMake file is shown below.
The project’s CMakeLists.txt is shown below. Core dependencies: SOEM, SDL2, OpenGL, ImGui, libmodbus, and pthread.
# project info
cmake_minimum_required(VERSION 3.28)
project(master VERSION 0.1.0 LANGUAGES C CXX)
# set some option
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(SOEM_BUILD_SAMPLES ON)
# libs
add_subdirectory(lib/SOEM)
include(lib/imgui.cmake)
add_executable(master master.cpp imgui_main.cpp fieldbus.c)
# link libraries
target_link_libraries(master PRIVATE soem)
target_link_libraries(master PRIVATE imgui)
target_link_libraries(master PRIVATE modbus)
target_link_libraries(master PRIVATE pthread)
Code Development
For the UI section, two separate windows have been implemented.
One window handles the EtherCAT Master UI interaction, and the other window manages the Modbus Master UI interaction.
Since the full source code is quite lengthy, it will not be displayed in the text. The complete code can be downloaded at the end of the article for reference.
The core part of the main function code is shown below.
Three threads are created:
One thread is responsible for EtherCAT communication with a synchronization cycle of 5ms;
Another thread handles Modbus RTU communication with a cycle of 10ms;
The third thread is the UI thread, which runs the interface developed with ImGui.
The software running screenshot is shown below. The left window is the EtherCAT master UI, which adopts PDO communication mode and realizes the control of onboard LEDs on the EtherCAT slave board. The right window is the Modbus master UI, which implements reading card ID data from the Modbus RFID reader.
In this project, a hybrid EtherCAT and Modbus RTU master gateway is built based on Raspberry Pi 5. With open-source libraries including SOEM, libmodbus and Dear ImGui, multi-protocol communication, data acquisition and visual human-computer interface are completed. The system successfully realizes LED control of EtherCAT slaves and card ID reading of Modbus RFID devices. During debugging, I also found several limitations and imperfections in this solution. The Raspberry Pi 5 generates considerable heat under high load, which may cause thermal throttling and reduce communication stability during long-term operation. In addition, the current multi-thread structure lacks optimized mutex control and scheduling strategy, occasionally resulting in minor data jitter. Furthermore, only basic communication functions are implemented, without disconnection reconnection, error tolerance and data filtering algorithms.
Future optimization will be carried out in both hardware and software aspects. Active heat dissipation will be added to solve thermal throttling, and electromagnetic interference suppression will be optimized. In terms of software, thread scheduling logic will be improved, and fault detection and data filtering will be supplemented. Moreover, a real-time kernel will be transplanted to further reduce communication latency. I am still in the learning stage, and this prototype has many immature details. Any suggestions, optimization ideas and discussions about Raspberry Pi industrial gateway are highly appreciated.
Yassin
Yassin | Building Compact, High-Current Connections for Drones & Robots
Quote
We use cookies on the DroneBot Workshop Forums to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.