It's time to rethink the hardware watchdog monitoring the Raspberry Pi (model 3 B) that is hosting my home automation system. A long time ago, back in early December 2019 to be precise, I described how to use a one relay cryptocurrency hardware watchdog in a post entitled Cheap Of-the-Shelf Raspberry Pi Hardware Watchdog. Although the watchdog has been running without apparent problem since then, I was not entirely pleased with it for three reasons.
- The watchdog resets the Raspberry Pi server if the latter no longer
signals that it's alive by shorting the
RUNpin to ground. This is bad because this does not shut down the Raspberry properly and it could corrupt the file system.
- The watchdog toggles the
RUNsignal nine times in quick succession before allowing the Raspberry Pi enough time to complete its reset sequence, which may raise the odds of corrupting the SD card.
- Should the watchdog itself fail it could very well disable the server.
The reason is that normal operation of the Raspberry Pi requires 3.3 volts
RUNpin. The normally closed watchdog relay needs to be energized at all times to avoid bringing
RUNdown to O volts. Should the watchdog power supply fail, for example, the relay will close which will ground the Raspberry Pi
RUNpin and disable the SoC until the connection from the watchdog to the pin is manually broken.
After setting up that less than perfect watchdog, I started to ponder how to replace it with something better. Two options came to mind:
- I could try again to order a two relay watchdog for mining rigs. Their increased flexibility would come at the expense of a USB port used not only to power the device but to set its parameters.
- The cheap and small ATtiny85 also seemed like a good choice. Some had recently arrived and the AVR programmer (see Using the Sparkfun Tiny AVR Programmer in Ubuntu 18.04) purchased quite some time ago could finally be put to good use.
At the same time, a Seeed Studio representative contacted me and invited me to review the Raspberry Pi Zero. I was taken aback, the Pi Zero has been available for some time and is well known. "What", I asked, "could I possibly add to an already large body of material readily available?" On further thought, a $5 Raspberry Pi Zero was not much more expensive than a two relay watchdog. Furthermore, using a Raspberry Pi as a watchdog for a Raspberry Pi was just the kind of self referential context that I sometimes relish. Besides, just think how much more could be done with an ARM processor with loads of memory and GPIO pins compared to an 8 bit, 8 pin AVR processor.
A proposal to write about the use of a Raspberry Pi Zero as a watchdog was accepted. However I had dithered so long that by then the Zero was no longer in stock. Seeed Studio suggested that the project might be completed with some other device from their product line. This time I moved with unusual speed and I ordered the following items the same day I got that offer:
- Seeeduino XIAO - Arduino Microcontroller - SAMD21 Cortex M0+ at $4.90
- Sipeed Longan Nano - RISC-V GD32VF103CBT6 Development Board at $4.90
- Wio Lite RISC-V (GD32VF103) - With ESP8266 at $6.90
- ROCK PI S - Mini Computer with Rockchip RK3308 - 512MB RAM at $13.90
The first two boards are obviously comparable in price to a Raspberry Pi Zero, the other two are more expensive and straddle the price of a Raspberry Pi Zero W sharing Wi-Fi connectivity with the latter. All prices are in US dollars and exclude shipping costs. The budget allocated by the sponsor was overrun, but that's OK. I am not in this for the money. Nevertheless, I am grateful for the help from Seeed Studio. Should you be wondering what sort of conditions were imposed on me, here are the complete instructions I received on how to proceed:
You just need to put an order using the coupon we offer you, after you receive the package you can start doing your project and post it on your website.
As a matter of fact, I am planning to produce a number of posts on the subject. First there will be an incursion into the topic of hard and soft reboots on the Raspberry Pi. After that introduction, the basic working of the hardware watchdog using a Raspberry Pi will be presented. I may not have a Raspberry Pi Zero but I do have the original Raspberry Pi from around 2011. Given the excellent work of the Raspberry Foundation, Raspbian Buster works perfectly on it and it is a perfect stand-in for the Zero. Add a Wi-Fi USB dongle and it represents a Zero W.
The test fixture: Raspberry Pi 3 B below the breadboard with tactive switches, Raspberry Pi 1 instead of Raspberry Pi Zero, RTC/EEPROM module and numerous Dupont wires all held together with rubber bands and tape on a piece of cardboard.
The next step will be to replicate that basic functionality with the Seeeduino XIAO. I don't anticipate too much problem because the device can be programmed in the familiar Arduino IDE. After, I will examine the possibility to do as much with the RISC-V (GD32) chips boards. It should be possible to use the on board display to show the current time and changes to the status of the watchdog in real time with the Sipeed Longan Nano. Remote access and control of the watchdog with the Wio Lite RISC-V will be investigated. Using a quad core SoC does look like overkill, but I hope to use the ROCK PI S not only as a watchdog but also as a time server (SNTP) for the local area network in addition to being a watchdog. But that just the start. At the present time I known nothing about that system, but if my hopes cannot be transformed into reality, there is little doubt in my mind that they could be achieved with a Raspberry Pi Zero W or any other Raspberry Pi with network capabilities.
All this may seem to be a make work project as I apparently have too much time on my hands. Of course, the reason the plan calls for so many different devices as hardware watchdog is because I want to learn something about them. Eventually, I will settle on one or two watchdog designs only. There's a lot of work ahead, see you in the next posts: