I am trying to interface Seeed Studio's RS485 shield for Raspberry Pi along with the Python Minimalmodbus library on Raspberry Pi 2B - NOT WORKING!!!
shield : https://www.seeedstudio.com/RS-485-Shield-for-Raspberry-Pi.html
I tested following on Raspberry Pi:
- It worked fine if I send data using Python serial library. It turns on a relay on a slave device and responds correctly.
ser.write('\xff\x05\x00\x00\xff\x00\x99\xe4')
- It is not working if I use Minimalmodbus library for Python
instrument.write_bit(0,1,5)
error: minimalmodbus.NoResponseError: No communication with the instrument (no answer)
note: I used same Minimalmodbus python code using another USB-to-RS485 converter on same RPi and it worked fine.
Pyhton Code:
import minimalmodbus
import time
import serial
instrument = minimalmodbus.Instrument('/dev/ttyAMA0', 255)
instrument.serial.baudrate = 9600
instrument.serial.bytesize = 8
instrument.serial.stopbits = 1
instrument.serial.timeout = 1
instrument.mode = minimalmodbus.MODE_RTU
instrument.clear_buffers_before_each_transaction = True
instrument.debug = True
while 1:
instrument.write_bit(0,1,5)
time.sleep(5)
error: minimalmodbus.NoResponseError: No communication with the instrument (no answer)
Can anybody help if I can use this specific rs485-shield with Minimalmodbus library? Thank you in advance
Regards,
The
write_bit
function is reading the response after the message is sent. And Seeed RS-485 Shield needs to toggle theGPIO18
pin to switch between reading and writing. As is shown in the sample code in documentation https://wiki.seeedstudio.com/RS-485_Shield_for_Raspberry_Pi/#communication-test-code.By checking the code of
write_bit
function I don't think that there is an easy way to toggle that pin as betweenserial.write
andserial.read
these no place to register own hook and toggle the PIN there (https://github.com/pyhys/minimalmodbus/blob/c08208523b729d178a9f662725a69195924f7c34/minimalmodbus.py#L1379).