Back in October I asked for any help about a less common hardware watchdog meant for cryptocurrency mining rigs. Here is an image of the device.
That plea generated exactly zero (0) replies. There could be three reasons for this.
- No one else dared or was stupid enough to purchase this item.
- No one reads these postings.
- How to use such a device is obvious to everyone else but me.
None of these explanations is particularly pleasing. No matter, let's put on a brave front and plod on. After the timing tests done with an ESP8266 as described in a previous post, I did some electrical tests. Take what follows with a grain of salt as I am definitely not an expert. My test equipment is pretty much limited to a cheap digital voltage, current and resistance meter.
The reset pins that are connected directly to the poles of the relay. Some describe such a relay as having dry contacts. It means that they are completely isolated and can be connected to a Raspberry Pi without problem. The HDD LED connector is an input but I nevertheless tested and found only a very small voltage across the pins. Surprisingly, neither pin is directly connected to the USB connector ground, which I guess is also a good thing. The more obvious problem is the operating voltage of that input. The two mystery chips on the little board are connected to 5 volts. Will a 3.3 volt signal be sufficient?
I dug up an old 2nd generation Pi to run some tests; no point in
endangering a more recent Raspberry Pi. In truth, the likelyhood of anything
bad happening seemed pretty low. After installing
Raspbian Buster Lite, I upgraded the OS which gave me just about enough
time to write a first draft of this post. Then a virtual Python environment was created and two Python
pip: RPi.GPIO (0.7.0) and gpiozero (1.5.1) for
handling the Pi GPIO pins were added to the environment. A very simple Python
wdfeed.py emulates a computer hard disk drive
Note how I dutifully followed the advice to update
proceeding with installing the second module. Below is the content of
I then connected the watchdog HD+ to pin 7 of the Raspberry Pi GPIO header (that is BCM pin 4 or GPIO4) and the HD- to pin 9 (GND) of the header. After inserting the watchdog USB jack into one of the RPi USB ports, the script is started.
While it was initially heartening to see the double flash of red every second between the orange relay and the HDD LED connector, it was disconcerting to hear the relay click a couple of minutes later on. Clearly, the watchdog was not being "fed". The instructions about the polarity connecting the HDD activity pins were ambiguous. Inverting the lines meant the LED no longer flashed but the relay was blissfully quiet. So that confirmed that HIGH signal from the Raspberry Pi which is nominally 3.3 volts but could be as low as 1.6 volt was decoded correctly by the watchdog which runs at 5 volts. Time to move on to the real test.
The first step was to add an entry in the
schedule of tasks to start the script at boot time.
@reboot command instructs
execute the following command (as
root) every time the
Raspberry Pi is booted.
It is important to use the Python in the virtual environment to run the
script because the needed
gpiozero module is not installed in
Buster Lite (it may be installed in the Desktop versions of Raspbian Buster).
The trailing &, which leaves the script running in the background, must
not be forgotten.
There is provision for a hardware reset button on the Raspberry Pi although the two pin header has to be soldered in. After that, it was a simple matter to connect the two RST pins of the watchdog to the Raspberry Pi reset pins. There is no polarity to respect, this is just a switch.
The yellow arrow points to the Raspberry Pi reset connector.
Also connected to the header is a dusk sensor based on the LDR visible above the case.
Power was applied to the Raspberry Pi with everything wired up and with
the watchdog connected to the USB port. The Pi had plenty of time to complete
its boot sequence, including starting the watchdog feeding script so that the
watchdog did nothing. I did verify that it was running using
The script uses up 0.6%-0.7% of the CPU time when writing to the GPIO port for a few milliseconds every second and 0% when sleeping.
The fork bomb shell script is a good way to test the
effectiveness of the watchdog. Here is the script saved under the name
To see what was happening,
htop was left running in one
ssh session while the "bomb" was launched in another.
htop froze. Then the session
forkbomb was launched became unresponsive and
eventually the connection was interrupted.
After a couple of minutes, the watchdog began to turn the relay on and off and after a bit more than a minute, it turned the relay off (open) for long enough leaving the Raspberry Pi enough time, 150 seconds to reboot and start feeding the watchdog. Success!.
In summary, the cheap (fake) USB watchdog can be used with a Raspberry Pi. Run a script that toggles GPIO pin XX every second or so and then connect the four watchdog header pins to the Raspberry Pi as shown below.
|RST1||RUN connector||no polarity|
|HD-||GPIO Pin XX||flip the connectors if the LED between the connector and the relay begins to flash|
While this device works, it is not perfect. A hard reset could corrupt the SD card; it is the equivalent to abruptly turning the power off and then back on. Not only does the watchdog initiate a hard reset without first attempting a reboot, it actually performs about 8 resets before finally giving the Raspberry Pi a time enough to boot.
There is another little "gotcha". If you issue a
command or something equivalent, then you have only a minute or two to
manually remove power from the Raspberry Pi. Otherwise, the watchdog will
reset the computer and it will reboot.
I will use this device for the time being. Another retiree with a penchant for this kind of stuff with whom I have the pleasure of corresponding is planning to use a Raspberry Pi Zero as a watchdog. I am sure he will be able to do something rather better with attempts at rebooting before resorting to a single hard reset if nothing else works. I may imitate him but I am still hoping that my supplier sends the ubiquitous USB watchdog with two relays ordered months ago. So far the promised replacement for the plastic jewellery shipped instead of the watchdog has not materialized.