Hartmut Wendt
Published © GPL3+

Node-RED: RS485 Raspberry Pi Tutorial

Configuring Node-RED for usage with and our RS485 HAT on a Raspberry Pi.

IntermediateProtip1 hour4,981
Node-RED: RS485 Raspberry Pi Tutorial

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1
RS485 HAT for Raspberry Pi
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Story

Read more

Code

Simple Communication example

JSON
use the import function of Node-RED
[{"id":"3f1d0d89.047be2","type":"tab","label":"RS485 HAT Simple Test","disabled":false,"info":""},{"id":"cf8f85d0.ae5778","type":"serial in","z":"3f1d0d89.047be2","name":"","serial":"28624537.d44aca","x":250,"y":280,"wires":[["259beb6c.eb724c"]]},{"id":"1ec27ec4.857b79","type":"serial out","z":"3f1d0d89.047be2","name":"","serial":"28624537.d44aca","x":510,"y":420,"wires":[]},{"id":"259beb6c.eb724c","type":"debug","z":"3f1d0d89.047be2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":490,"y":280,"wires":[]},{"id":"4bbd60d7.ca9d58","type":"inject","z":"3f1d0d89.047be2","name":"","topic":"","payload":"Hello World","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":420,"wires":[["1ec27ec4.857b79"]]},{"id":"28624537.d44aca","type":"serial-port","z":"","serialport":"/dev/serial0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"0x0d","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

Modbus example

JSON
use the import funtion of Node-RED
[{"id":"fc0351ac.0e82","type":"tab","label":"RS485 HAT Modbus test","disabled":false,"info":""},{"id":"ddca156f.2070a","type":"modbus-read","z":"fc0351ac.0e82","name":"","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"unitid":"1","dataType":"HoldingRegister","adr":"0","quantity":"8","rate":"2000","rateUnit":"ms","delayOnStart":true,"startDelayTime":"1","server":"75beb9d9.444ee","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":230,"y":260,"wires":[[],["d0032da0.c6f7b8"]]},{"id":"d0032da0.c6f7b8","type":"modbus-response","z":"fc0351ac.0e82","name":"","registerShowMax":"8","x":550,"y":260,"wires":[]},{"id":"c58cff22.de2578","type":"inject","z":"fc0351ac.0e82","name":"SET Register 6 to 255","topic":"","payload":"[255]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":420,"wires":[["ed8e9c94.6c98"]]},{"id":"ed8e9c94.6c98","type":"modbus-write","z":"fc0351ac.0e82","name":"","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"MHoldingRegisters","adr":"6","quantity":"1","server":"75beb9d9.444ee","x":560,"y":440,"wires":[[],["e03f5688.f2bee8"]]},{"id":"e03f5688.f2bee8","type":"debug","z":"fc0351ac.0e82","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":780,"y":460,"wires":[]},{"id":"8d17bc89.388878","type":"inject","z":"fc0351ac.0e82","name":"SET Register 6 to 0","topic":"","payload":"[0]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":480,"wires":[["ed8e9c94.6c98"]]},{"id":"75beb9d9.444ee","type":"modbus-client","z":"","name":"","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/serial0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"10","clientTimeout":"100","reconnectTimeout":""}]

Credits

Hartmut Wendt

Hartmut Wendt

12 projects • 18 followers

Comments