Nouveau : le pare-feu IA surveille toute la plateforme et explique chaque incident en termes simples. Découvrez comment ça marche

Reply To: Pi as Modbus RTU master for six PIC slaves on one RS-485 line: replies collide and get garbled

Yes, it’s the GPIO timing, and the missing bias doesn’t help. I had almost the same line on six pump controllers.

Driving DE/RE from Python is too slow and too jittery. After the write, your code switches back to receive only when Linux gets round to it. At 38400 a slave can start answering within a couple of milliseconds, so the start of the reply is lost or you’re still driving the line while the slave talks. Fix it in hardware: a USB-RS485 adapter with automatic direction control (FTDI-based ones are good), or let the kernel do it on the UART with rs485 mode. The adapter is the five-minute fix.

Then the line itself:

  • Bias: one pull-up on A and one pull-down on B, only once on the bus (560 R to 1 k is typical), so the idle line is defined.
  • Common ground wire between all nodes.
  • Give pymodbus a sane timeout and a pause between slaves, some old firmware needs a breather.
client = ModbusSerialClient(port="/dev/ttyUSB0", baudrate=38400, parity="N",
                            stopbits=1, bytesize=8, timeout=0.3, retries=2)
for unit in range(11, 17):
    rr = client.read_holding_registers(0, count=4, slave=unit)
    time.sleep(0.02)

Then report all six as children of the Pi on v1/gw/telemetry, keyed by name (« mixer-11 » and so on). Each one gets its own device in Hermetry, and you can put a Device offline rule on their profile.

Solution acceptée♥ 1