Transclusion: IOT-GATE-iMX8: Modbus

From Compulab Mediawiki
Revision as of 13:15, 24 January 2023 by Igor (talk | contribs)
Jump to: navigation, search

Modbus is a standard communication protocol and is a commonly available means of connecting industrial electronic devices. IOT-GATE-iMX8 RS485 ports can be used to implement the Modbus protocol.
It is recommended to use the modpoll - a command line based Modbus master simulator and test utility. Download and install the modpoll utility:

compulab@iot-gate-imx8:~$ wget https://www.modbusdriver.com/downloads/modpoll.tgz -/tmp/
...
compulab@iot-gate-imx8:~$ sudo tar -xvf /tmp/modpoll.tgz -C /opt/
...

Modbus Communication Example

[XY-MD02] is a high-precision temperature and humidity sensor. XY-MD02 uses the RS485 hardware interface and protocol layer compatible with standard industrial Modbus RTU protocol.

  • Connect the XY-MD02 sensor to the IOT-GATE-iMX8, RS485 port:
    • Connect power lines to a DC power supply 5V-30V
    • Connect RS485 lines
--------------------                                   
|                  |                                   
|                  *--(+)---< <------------- 5V-30V    
|                  |                                   
|                  *--(-)---< <-------------- GND     ------------------------  
| XY-MD02 (RS485)  |                                  |                      |
|                  *--(A+)--< <---...---> >--(P7/2)---*-----                 |
|                  |                                  | P7 |  IOT-GATE-iMX8  |
|                  *--(B-)--< <---...---> >--(P7/1)---*-----                 |
|                  |                                  |                      |
--------------------                                  ------------------------ 
  • Read temperature once:
root@iot-gate-imx8:~# /opt/modpoll/arm-linux-gnueabihf/modpoll -b 9600 -p none -t 3 -c 1 -r 2 -1 /dev/ttymxc0
-- Polling slave...
[2]: 284
  • Read humidity once:
root@iot-gate-imx8:~# /opt/modpoll/arm-linux-gnueabihf/modpoll -b 9600 -p none -t 3 -c 1 -r 3 -1 /dev/ttymxc0

-- Polling slave...
[3]: 453