RS485 on Industruino IND.I/O
The IND.I/O has a standard RS485 port that can be accessed from the hardware serial, Serial1, which does not affect the USB serial connection. This is an advantage of the 32u4 and 1286 chip of the Industruino over the standard 328 on the Arduino Uno.
The wind speed sensor (anemometer) that i have, uses the Modbus protocol over an RS485 connection, aka Modbus RTU. The sensor is the Modbus Slave and the Industruino is the Modbus Master.
The Industruino RS485 is half-duplex, aka 'two wire' = A and B (plus GND). My sensor had 4 wires, for Vcc, GND, A and B, which i connected straight to the Industruino as in above picture. I also had to connect an external power supply on the Industruino as the 5V USB from the laptop is not sufficient to power the sensor (min 7V). I supplied 9V from my Industruino PROTO power supply, described in another blog post.
Modbus RTU library
First i had a look at this ModbusMaster library but it did not allow sufficient configuration, such as the RS485 Transmit Enable pin. The SimpleModbusMaster library does allow more configuration. Latest version available here, including a useful Manual.
The library uses 3 simple commands:
- modbus_construct: to initialise a packet (= an instruction) in SETUP
- modbus_configure: to set baud rate, timeout, scan rate, TxEnablePin, register variable in SETUP
- modbus_update: to execute the instruction in LOOP