PiDog2

Introducing The PiDog2

PiDog2 is a "hat" for all Raspberry Pi computers with 40-pin GPIO connectors (that only excludes the computer module and the original Model A) that provides much needed hardware watchdog and power management capabilities that the Raspberry Pi itself lacks. It does this with minimal fuss and almost no effort on your part

Background

The Raspberry Pi computers are great. They're cheap, fun to use, run a solid operating system, and can be programmed in whatever languages you like. Furthermore, they have ample IO capability, through USB ports and through that big, beautiful GPIO connector. However, there are a couple of problems with the Raspberry Pi's that make them difficult to deploy in places where a human can't easily visit them and "fix" the from time to time

  1. Because of the complexity of the operating system scripting languages, and the potential unreliability of whatever you have attached to the Pi, sometimes they just lock up. Quite simply, they need to be rebooted.
  2. The Raspberry by has no means to turn itself off. You can shutdown the operating system, and that reduces power a but your peripherals plugged into the USB ports are still pulling power. In fact the Pi is, too -- a little. Worst of all, if you do shut down the OS, you have no way of remotely bringing it back up!
  3. Raspberry PI's do not have an easy way to monitor their own power supply. If you have a battery-powered Pi and want to know the state of the battery, you're out of luck.

I designed the PiDog after I had to deploy Raspberry PI-based cameras and sensors around a wide campus, powered by batteries and solar panels. They worked pretty well in most cases, but after a long period of low sun, or certain types of network outages, or OS updates gone bad, the Pi's would "die" and disappear off our network for good, requiring that I visit them and manually reset them. This was tedious and crashes for low voltage / low power sometimes resulted in damage to the uSD flash cards in the Pi's. My solution to this was a small amount of hardware to reset the Pi's and turn them off when power is low or unavailable, but being able to turn them back on when the power is back!

Enter the PiDog2

The PiDog2 solves all those problems. First, the PiDog2 can cut the power to a Raspberry Pi after specified period of time. This lets it serve as an external watchdog timer, or let's you use it to perform a complete powerdown after a clean shutdown. Second, it can power the Raspberry Pi back up after a different specified time. Finally, it provides the Pi with a measurement of the 5V and 3.3V supplies, as well as up to two other voltages of your choice. This lets software running on the Pi make intelligent choices about when it should gracefully shut down in order to save battery and avoid flash corruption. Then, using the PiDog2, it can wake again periodically, check the battery voltages and decide whether to power back down or operate normally.


How does it work

PiDog2 is powered by an Attiny84 microcontroller that is connected to the Pi via the GPIO header and the SPI interface. It uses one of the standard Raspberry Pi SPI chip-selects, but you can still use other SPI devices that work off other chip selects. The PiDog2 inserts a MOSFET switch between the incoming USB 5V and the Raspberry Pi. This way, it can turn the Pi on and off. Connection is very simple: simply remove the USB connector from your Raspberry Pi, attach the PiDog2 to the Raspberry Pi's GPIO header, and put the USB connector onto the PiDog2. That's all the hardware setup you need!

The PiDog2 is programmed to look like a handful of 32 bit registers that contain various countdown timers and control bits, and there is a basic Python library provided that makers interacting with those registers a snap.

Features

  • Low Rds power mosfet, capable of switchin 5V at 4 amps with less than 100mV voltage drop. (You'll see more drop in your USB cable under such load!)
  • 40 pin Raspberry Pi GPIO header, for connecting directly to any Raspberry Pi. You can order with an extended pin header so that you can put another hat on top of the PiDog2.
  • A 4-pin header with 2 grounds, the 5V unswitched, and 5V switched power rail, so you can directly power the Pi or another device without using USB
  • A 2x3 Atmel ICSP connection which you can use for programming the AVR --- but you won't need it!
  • Two LEDs that indicate status (shutdown imminent) and (shutdown has occurred at least once since the Pi has talked to the the PiDog2 and cleared the bit.)
  • A 3-pin debug port that allows you to see serial messages from the PiDog2, to aid in debugging and programming. (There is serial out, no serial in.)
  • voltage measurement of the 5V input, the 5V output, and the 3.3V rail of the Raspberry Pi.
  • Two 2-pin JST connectors for measuring two other voltages. Voltage dividers on these inputs allow measuring any voltage up toe 16V
  • A power-on LED
  • Reset button
  • in-situ programming of the AVR. If you want to update the firmware, or simply experiment with your own, you can do so directly from the Raspberry Pi without removing the PiDog2. No external hardware programmer is required -- the Pi can program the Attiny!


Resources

The projects can be found on GitHub: https://github.com/djacobow/pidog2. In that repo, you'll find:

  • complete firmware and instructions for building it with the Arduino environment
  • instructions for how to flash the AtTiny from the Raspberry Pi
  • A simple Python-based library that provides access to the PiDog2's registers
  • Example scripts that show basic watchdog operation (periodic timer resets) as well as a "shut down and turn off example.


Errata

Some boards were assembled with a resistor present that does not belong.

  • If you have a v0.7 board and it has 100k resistor R2, please remove it.
  • If you have a v0.5 board and it has 100k resistor R10 , please remove it.

On some boards, these resistors were populated when they should not have been. This can cause the PiDog to cut the power to the RPi during in-situ programming, resulting in a sad RPi and an unprogrammed PiDog. Not good. If you board has this resistor, please remove it from the board and you should be good to go. If you have any questions, do not hesitate to contact me at dave -at- southberkeleyelectronics.com.