Wednesday, 11 December 2024

Pimoroni Grow Hat in NodeRED (Part 1 Initial Setup)

 Introduction

We recently set up a plant monitoring system based on a Raspberry Pi Zero and a Pimoroni Grow Hat. It's a great little board that fits over a Pi Zero, giving you the ability to monitor your potted plants. You can connect up to three capacitive saturation sensors, allowing you to ensure your plants don't go unwatered for too long, and there's even three electric pump driver outputs, so you can go 'full-auto'.


Pimoroni's Grow Hat

As you can see from the photo, it comes with a display and four buttons, which allows you to calibrate the sensors, setup alerts, and turn on actions such as automatic watering (if you have the correct pumps). It's really quite impressive what it can do with very little work.

One of the main purposes of this setup was to get it all working in NodeRED, but unlike Pimoroni's Automation Hat, there's no plugin available. The long term goal here was to provide a web dashboard (maybe a few charts) and connect this up to Apple Homekit.

A secondary goal was for my son to learn NodeRED and have a bit of fun.

I'm going to assume you've got a reasonable grasp of installing software on a Raspberry Pi, the online guides are relatively easy to follow, but other than that we're not going to be writing much code.

Initial Setup

Getting the Grow Hat going was easy, solder the header onto a new Pi Zero, install the Raspberry Pi operating system and plug the Grow the board onto the GPIO. You'll need to install the Grow python software, but this is just a matter of following Pimoroni's 'Getting Started Guide', and then the display lit up, ready to go.

The onboard menu allows you to set the wet and dry frequencies for the sensors, and you really need to go through the calibration process if you want the bar graph to accurately represent the water saturation levels. As the pot dries out, the frequency will rise, so the python software tracks that and turn it into a percentage.

There's a simple calculation in the python code, and (assuming a linear relationship) it turns the pulse frequency read at the three GPIO pins into a percentage value. Understanding that means we can replicate the process in NodeRED.

 Moving onto NodeRED

Hopefully you understand what NodeRED is, if not, it's a way of building systems and automation using message flows. There's no programming, as such, you just need to understand the concept and contents of the messages in the flows.

We'll start by running the basic install from the NodeRED installation page for the Raspberry Pi. After it installs, everything else continues in the browser. If you're using a different machine to run the browser on (which I do) you need to use the following address:

http://<hostname>:1880. (You can find the IP address by running 'hostname -I' on the Pi)

In the Manage Palette settings, I added the following nodes:

  • node-red-node-pi-gpio
  • node-red-dashboard
  • node-red-contrib-msg-speed
  • node-red-contrib-moving-average

 I'll go more into these later, but right now we're only interested in the pi-gpio node. Here's how it looks in NodeRED nodes column.


The Pi-GPIO nodes

 




 

 

 

 

 

 

Drag an 'rpi-gpio in' node onto the flow and set the Pin value to '16 - GPIO23'.

Add a debug node, deploy the flow and we'll see the following values flashing by on the debug tab.

Reading the Grow hat's input from Sensor 1








 

 

It flicks between 1 and 0 very quickly, and this gives us a clue how we can replicate the Grow Hat's screen in our flow. The speed that this input changes is the frequency mentioned earlier.

Looking at the Grow documentation, the sensors are on the following pins:

Sensor 116 - GPIO23
Sensor 224 - GPIO8
Sensor 322 - GPIO25

Next time we'll look at turning these signals into a meaningful value.