Description
Hello! Great library. I'm trying to get up and running on a RP2040 (raspberry pi pico) to make a very low cost solution using this library and RS485.
For hardware I am using:
I am able to successfully send commands from a host to the RP2040, but they always time out, even though the value is received by the node. This is the same whether we're talking about a holding register, coil, etc...
To simplify the debug process, below is MVP code to replicate the issue using this hardware:
#include <Arduino.h>
#include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>
RS485Class _RS485(Serial1, 0, 6, 1); //middle value (DE) is driver enable - need custom pinout
void setup()
{
Serial.begin(115200);
//slave id 1
if ( !ModbusRTUServer.begin(_RS485,1,9600,SERIAL_8N1) )
{
Serial.println("Failed to start Modbus RTU Server!");
while (1);
}
// configure 1 coil at address 1
ModbusRTUServer.configureCoils(1,1);
}
void loop()
{
// poll for Modbus RTU requests
if (ModbusRTUServer.poll() )
{
Serial.println("Received request!");
Serial.println( "Coil value: " + String(ModbusRTUServer.coilRead(1)) );
}
}
When calling from a host (whether python or a GUI-based program like ModbusMechanic) the result is the same. My node can see the command from the host, but the response is never seen by the host. It always times out.
See resulting serial output from node below, when I send a 0, followed by a 1 for the coil value from a host to the node:
Received request!
Coil value: 0
Received request!
Coil value: 1
NOTE: to get the code to compile I had to change a couple default pin values within RS485.h, just because the RP2040 doesn't have an A5 or A6:
#ifndef RS485_DEFAULT_DE_PIN
#define RS485_DEFAULT_DE_PIN 6
#define RS485_DEFAULT_RE_PIN 1
#endif
I'm wondering if this could be an issue with the software serial on the RP2040's compatibility with the library? Looking forward to others' thoughts!
Thank you!
Michael