Node-RED library for Grove base HAT

As teacher I use Node-RED on a Raspberry Pi for learning students about IoT. Node-RED is a no-code/low-code platform where people can make their own automated system and/or information dashboard.

The Software

The Node-RED installation instructions can be found at https://nodered.org. Here is a screenshot of the example test flows:

The Hardware

To use hardware sensors and actuators you can plug in a Grove base HAT from Seeed Studio and connect sensors from Seeed to the board. To be able to control or read the actuators/sensors you have to use a Node-RED library. The one I used for a while was the library node-red-contrib-grove-base-hat.

However this year this library did not work anymore. The main reason is that the used Python scripts in this library were written for Python version 2 and the newest Raspberry OS uses default Python and Python libraries version 3.

I did not want to update the Python scripts (personal reasons 🙂 but used primary bash scripts to replace them.

The extra tools used in this library:

  • WiringPi gpio tool to read and write to the digital pins.
  • Default Raspberry Pi OS linux i2c-tools to connect to the Analog-Digital-Conveter on the Grove-base-HAT.
  • I have written a library (io_toolsPi) with io tools to read or write to specific sensors or actuators.

The new library is named node-red-contrib-grove-base-hat-bash. I have already added nine nodes to this library.

You can install this library with the Manage Palette menu.

You can find extra information and installation instruction here: https://flows.nodered.org/node/node-red-contrib-grove-base-hat-bash

When you like this library please rate this on Node-RED. When you have questions/remarks, please leave them in the comment. I will try to answer them.

In the README.md of this (https://gitlab.com/iot-lab-org/node-red-contrib-grove-base-hat-bash) repository you can find most information how use use and install the Node-RED library. In this blog I wil add extra technical background.

Bash script location

The bash (born again shell) scripts can be found at:

/home/<username>/.node-red/node_modules/node-red-contrib-grove-base-hat-bash/<node-name>

The username is usually the name of the user who installed node-red.

Please edit and test them at your own convenience. If there are errors or you have better solutions please contact me so I can update the scripts.

Output pin

The grove-Led and grove-relay is controlled by WiringPi gpio command. For example setting the mode and write logic 1 to output.

gpio -g mode 5 out

gpio -g write 5 1

The -g parameter makes the gpio using the BCM numbering. The Grove Base HAT uses the BCM numbering (for example D5 is BCM gpio 5).

Leave a Reply

Your email address will not be published. Required fields are marked *