ArduinoModbus
ArduinoModbus copied to clipboard
Library only working for 1 simultaneous Server on RP2040 using earlephilhower's arduino-pico platform
Hello! Strange issue for you all:
I have been running code successfully on a Adafruit Feather RP2040 with PlatformIO's standard Raspberry Pi pico platform. However, once I changed over to using earlephilhower's arudino-pico on the same exact board, a strange behavior began:
Everything seems totally fine when testing 1 ModbusRTUServer physical device at a time. However, if the same code is run on two slaves connected on the same bus (for example, with modbus address/id 1 and 2, respectively) I can only read from 1 device. The requests from the second device will time out unless I wait a few seconds to issue the new request.
Here's an illustration of the setup
- Adafruit Feather RP2040 connected via Modbus RTU RS485 - (address 1)
- Adafruit Feather RP2040 connected via Modbus RTU RS485 - (address 2)
- Computer w/ RS485 to USB adapter running python, polling both devices for their holding register values
Result
- A. With PlatformIO's standard Raspberry Pi pico platform, works totally fine
- B. earlephilhower's arudino-pico on the exact same setup, only 1 device can be polled at a time, without waiting seconds between devices
If I just poll one device at a time, the responses happen within a few milliseconds, and I can poll constantly for days without a comms issue. It is only when two devices are introduced that the issue occurs.
Any thoughts on what could be going on here? Thank you!
MVP main.cpp example code for Adafruit Feather RP2040:
#include <Arduino.h>
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
const int MODBUS_ADDRESS = 1; //change between 1 and 2, per simultaneous device
void setup()
{
Serial.begin(115200);
//slave id 1
if ( !ModbusRTUServer.begin(MODBUS_ADDRESS,115200,SERIAL_8N1) )
{
Serial.println("Failed to start Modbus RTU Server!");
while (1);
}
// configure 50 holding registers, starting at address 1
ModbusRTUServer.configureHoldingRegisters(1,50);
}
void loop()
{
// poll for Modbus RTU requests
if (ModbusRTUServer.poll() )
{
Serial.println("Received request!");
}
}
platform.ini file for PlatformIO compilation:
[env:adafruit-rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = adafruit_feather
framework = arduino
board_build.core = earlephilhower
#Selectively uncomment block below for latest tested library version
lib_deps =
https://github.com/arduino-libraries/ArduinoModbus.git
FYI: For RS485.h to compile I had to make a couple #define
and pinmapping changes, which may be necessary depending on your pinout as well for testing