Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library only working for 1 simultaneous Server on RP2040 using earlephilhower's arduino-pico platform #155

Open
pomplesiegel opened this issue Aug 26, 2024 · 3 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@pomplesiegel
Copy link

pomplesiegel commented Aug 26, 2024

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

  1. Adafruit Feather RP2040 connected via Modbus RTU RS485 - (address 1)
  2. Adafruit Feather RP2040 connected via Modbus RTU RS485 - (address 2)
  3. 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

@pomplesiegel
Copy link
Author

I'm wondering if this could somehow be an issue of a pin being left low/high, hogging the bus? Weird that it eventually resets. Any ideas of some things to try, and can anyone else try this as well to replicate?

@pomplesiegel

This comment was marked as duplicate.

@pomplesiegel
Copy link
Author

Hello! FYI, I switched to this library instead (below) and for me it is working much more reliably for the RP2040 on this platform. Thank you!

https://github.com/CMB27/ModbusRTUSlave

@per1234 per1234 changed the title Library only working for 1 simultaneous Server on RP2040 using earlephilhower's arudino-pico Library only working for 1 simultaneous Server on RP2040 using earlephilhower's arduino-pico platform Sep 7, 2024
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Sep 7, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

8 participants
@pomplesiegel @per1234 and others