Pi 3 RS-485 HAT ile pymodbus: ttyS0 üzerinden sayaçtan yanıt yok
Yapay zekâ tarafından English dilinden çevrildi ·
Pi 3B, GPIO başlığına takılı bir RS-485 HAT (otomatik yön), adres 1’de tek bir Schneider PM5110 güç sayacı, sayacın ön panelinde ayarlanmış 9600 8E1. Planım birkaç register’ı okuyup her 10 saniyede bir Hermetry’ye yayınlamak.
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))
Her seferinde sonuç:
Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response
Ben gönderdiğimde sayacın iletişim LED’i yanıp sönüyor, yani bir şey ona ulaşıyor. Aynı sayaç, dizüstü bilgisayarımdaki USB RS-485 çubuğuna aynı ayarlarla yanıt veriyor. Yıllardır PLC’lerle Modbus kullanıyorum ama Pi’ler bana yeni.
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.
Yapay zekâ tarafından English dilinden çevrildi ·
İki uçta da baud hızı aynı mı? Bunu değiştirmeyi unuttuğumda hep bu hatayı alıyorum.
Is the baud the same on both ends? I always get that error when I forget to change it.
Yapay zekâ tarafından English dilinden çevrildi ·
Bluetooth’u kapattınız mı? Pi 3’te varsayılan olarak iyi UART, Bluetooth’a yönlendirilir.
Did you turn Bluetooth off? On the Pi 3 the good UART goes to Bluetooth by default.
Yapay zekâ tarafından English dilinden çevrildi ·
Baud hızı eşleşiyor. Bluetooth’a dokunmadım.
Baud matches. Bluetooth I haven’t touched.
Yapay zekâ tarafından English dilinden çevrildi ·
Mühendis değilim, ama bu tam hatayla bir hafta uğraştım. Pi 3 ve otelimizin kazan dairesindeki bir ısı sayacıyla çalışıyordum ve sorun iki şeyin birlikte olmasıymış.Pi 3’te asıl UART (PL011) Bluetooth’a bağlı, GPIO pinleri ise mini UART’a, yani ttyS0’a gidiyor. Mini UART’ın baud hızı çekirdek saatini takip ediyor; bu yüzden CPU hızı değiştiğinde 9600 artık 9600 olmuyor. Mini UART’ın ayrıca eşlik biti (parity) yok, sayacınız ise 8E1 ayarında. Sonuçta sayaç isteğinizi duyup yanıt veriyor, Pi ise yanıtı çözemiyor.Beni asıl yakalayan ikinci sorun seri giriş konsoluydu: cmdline.txt hâlâ console=serial0,115200 içeriyorsa Pi açılışta giriş istemini RS-485 hattına yazıyor ve porta bir getty süreci bağlı kalıyor.Benim için işe yarayan çözüm:
# /boot/firmware/config.txt (eski imajlarda /boot/config.txt)
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
Yeniden başlattıktan sonra pymodbus’ta /dev/serial0 kullanın (bu işlemden sonra ttyAMA0’ı gösterir). Ayrıca sayacınızın registerları 0’dan mı yoksa 1’den mi saydığını kontrol edin. Schneider kılavuzları registerları 1 tabanlı listeler; yani kitapta 3028 olan register hatta 3027 olarak gider, ve siz bunu doğru bilmişsiniz.
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.
Yapay zekâ tarafından English dilinden çevrildi ·
İkisi de geçerliydi. serial0 üzerinde getty çalışıyordu ve çift parity kullanan mini UART hiç çalışmadı. disable-bt ayarını yapıp konsolu kapattıktan sonra PM5110 ilk denemede yanıt verdi: L1-N 230,4 V. Artık her 10 s’de bir yayın yapılıyor. Teşekkürler David, Bluetooth konusunda yönlendirdiğin için Megan’a da.
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.
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.
Sohbete katılın
Soru sormak ve yanıtlamak, yararlı gönderileri beğenmek ve sorununuzu çözen yanıtı işaretlemek için oturum açın. Her katkı puan ve seviye kazandırır.

