Toll-Free Customer Support 24/7

Modbus communication in Raspberry Pi

Step 1: Install python Package minimalmodbus


sudo pip install minimalmodbus

Step2: Open any editor and copy below code:


import minimalmodbus
import time

minimalmodbus.BAUDRATE = 9600

# port name, slave address (in decimal)
instrument = minimalmodbus.Instrument('/dev/ttyAMA0',1)

while True:
# Register number, number of decimals, function code
temperature = instrument.read_register(3853, 1, 3)
print temperature
time.sleep(1)

Back to top