pymodbus en un Pi 3 con HAT RS-485: sin respuesta del medidor en ttyS0
Traducido del English por IA ·
Pi 3B, un HAT RS-485 en el conector GPIO (dirección automática), un medidor de energía Schneider PM5110 en la dirección 1, con 9600 8E1 configurado en el panel frontal del medidor. El plan es leer unos cuantos registros y publicarlos en Hermetry cada 10 s.
from pymodbus.client import ModbusSerialClient
c = ModbusSerialClient(port="/dev/ttyS0", baudrate=9600, parity="E", stopbits=1, bytesize=8, timeout=1)
c.connect()
print(c.read_holding_registers(3027, count=2, slave=1))
Resultado cada vez:
Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response
El LED de comunicaciones del medidor parpadea cuando envío, así que algo le llega. El mismo medidor responde a un adaptador USB RS-485 en mi portátil con la misma configuración. Llevo años trabajando con Modbus en PLC, pero las Pi son nuevas para mí.
Pi 3B, an RS-485 HAT on the GPIO header (auto direction), one Schneider PM5110 power meter at address 1, 9600 8E1 set on the meter’s front panel. The plan is to read a handful of registers and publish them to Hermetry every 10 s.
from pymodbus.client import ModbusSerialClient
c = ModbusSerialClient(port="/dev/ttyS0", baudrate=9600, parity="E", stopbits=1, bytesize=8, timeout=1)
c.connect()
print(c.read_holding_registers(3027, count=2, slave=1))
Result every time:
Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response
The meter’s comms LED blinks when I send, so something reaches it. Same meter answers a USB RS-485 stick on my laptop with the same settings. I’ve done Modbus for years on PLCs but Pis are new to me.
Traducido del English por IA ·
¿La velocidad en baudios es la misma en ambos extremos? Siempre me sale ese error cuando olvido cambiarla.
Is the baud the same on both ends? I always get that error when I forget to change it.
Traducido del English por IA ·
¿Desactivaste el Bluetooth? En la Pi 3, la UART buena se asigna al Bluetooth por defecto.
Did you turn Bluetooth off? On the Pi 3 the good UART goes to Bluetooth by default.
Traducido del English por IA ·
La velocidad en baudios coincide. No he tocado el Bluetooth.
Baud matches. Bluetooth I haven’t touched.
Traducido del English por IA ·
No soy ingeniero, pero peleé contra este error exacto durante una semana con una Pi 3 y un medidor de calor en la sala de calderas de nuestro hotel, y eran dos cosas a la vez.En una Pi 3, la UART adecuada (PL011) está conectada al Bluetooth, y los pines GPIO usan la mini UART, ttyS0. La velocidad en baudios de la mini UART depende del reloj del núcleo, así que cuando la CPU cambia de velocidad, los 9600 dejan de ser 9600. Además, la mini UART no tiene paridad, y tu medidor está en 8E1. Así que el medidor oye tu petición, responde, y la Pi no logra interpretar la respuesta.La segunda me pilló: la consola de inicio de sesión serie. Si cmdline.txt todavía tiene console=serial0,115200, la Pi escribe su indicador de login en el bus RS-485 al arrancar y mantiene un getty en el puerto.Lo que me solucionó el problema:
# /boot/firmware/config.txt (o /boot/config.txt en imágenes antiguas)
enable_uart=1
dtoverlay=disable-bt
sudo systemctl disable hciuart
# raspi-config: Interface Options > Serial Port
# login shell over serial: No, serial port hardware: Yes
Reinicia y usa /dev/serial0 (que apunta a ttyAMA0 después de esto) en pymodbus. Comprueba también si tu medidor cuenta los registros desde 0 o desde 1. Los manuales de Schneider los listan desde 1, así que el 3028 del manual es el 3027 en el bus, y tú lo tenías bien.
I’m not an engineer, but I fought this exact error for a week with a Pi 3 and a heat meter in our hotel’s boiler room, and it was two things together.
On a Pi 3 the proper UART (PL011) is wired to Bluetooth and the GPIO pins get the mini UART, ttyS0. The mini UART’s baud rate follows the core clock, so when the CPU changes speed the 9600 isn’t 9600 any more. The mini UART also has no parity, and your meter is on 8E1. So the meter hears your request, answers, and the Pi can’t make sense of the reply.
Second one got me: the serial login console. If cmdline.txt still has console=serial0,115200, the Pi writes its login prompt onto the RS-485 bus at boot and keeps a getty on the port.
What fixed it for me:
# /boot/firmware/config.txt (or /boot/config.txt on older images)
enable_uart=1
dtoverlay=disable-bt
sudo systemctl disable hciuart
# raspi-config: Interface Options > Serial Port
# login shell over serial: No, serial port hardware: Yes
Reboot, then use /dev/serial0 (it points to ttyAMA0 after this) in pymodbus. Also check whether your meter counts registers from 0 or 1. Schneider manuals list them 1-based, so 3028 in the book is 3027 on the wire, and you had that right.
Traducido del English por IA ·
Fueron las dos cosas. getty estaba usando serial0, y la mini UART con paridad par nunca funcionó. Después de desactivar disable-bt y apagar la consola, el PM5110 respondió a la primera: 230,4 V L1-N. Ahora publica cada 10 s. Gracias David, y Megan por señalar lo de Bluetooth.
It was both. getty was sitting on serial0, and the mini UART with even parity never worked. After disable-bt and the console off, the PM5110 answered on the first try: 230.4 V L1-N. Publishing every 10 s now. Thanks David, and Megan for pointing at Bluetooth.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

