John Shovic's Google Plus Switch: Project Curacao - Battery Watchdog - Part 3

Project Curacao - Battery Watchdog - Part 3


Project Curacao - The Battery Watchdog (Arduino)

The Battery Watchdog

After a significant period of testing, we have determined that the Raspberry Pi does not wake up very well from a discharged battery event as it is being recharged by the solar cells. What appears to be happening is the battery reaches a high enough voltage and the charger turns the power on to the Raspberry Pi. The Raspberry Pi Model A takes around 300mA and immediately pulls the battery back down to the point where the Raspberry Pi will not boot.  This kind of constant boot/reboot cycle can kill SD cards after a period of time. After some thought, we determined that we could use a low power Arduino Uno with a relay as a very smart watchdog timer. This device has its own small LiPo battery, a small solar cell and it's own charger. We want this device to be independent of the main system. It will do the following four things:

1) Monitor the main system battery voltage and turn the relay on to the main system when the batteries reach 20% charge. This is in the case of a full battery discharge rate. There will be a 5% of charge hysterisis to prevent flapping. This meaning that the relay will not turn off until a 15% charge rate has been reached.

2) Monitor a GPIO pin from the Raspberry Pi, looking for transitions at least every 15 minutes. If the Raspberry Pi does not change the state of this pin every 15 minutes, the Battery Watchdog attempts to shutdown the Raspberry Pi and then cuts power for 10 seconds and re-applys the power to reboot the Raspberry Pi.

3) It will start the Raspberry Pi up approximately 3 hours before sunrise and shut the Raspberry Pi down approximately three hours after sundown.  Sunrise and sundown will be approximated by the use of a photoresistor with enough hysterisis to not mistake a cloud for the sunset. It will also bring the Raspberry Pi up in the middle of the night for 30 minutes to record night time temperatures. If the main battery is fully charged, the Battery Watchdog will cancel the night time shutdown.

4) Additional GPIO pins on the Raspberry Pi will be used by the Battery Watchdog to communicate status and events through a linked serial interface. This will also be used to allow the Raspberry Pi to shut itself off in case of high temperatures.

This entire watchdog could be done in hardware with an FPGA board, but we decided to go with the parts we had on hand. A good question we have yet to answer is whether to make the power relay normally open or normally closed. If it is normally open and the Battery Watchdog fails, then the Raspberry Pi is out of action. If it is normally closed and the Watchdog fails, then the Raspberry Pi might be able to still function.

For a system designed to operate 3700 miles away from the engineer who has to fix it, a good watchdog function is critical.


Implementation


We have implemented the battery watchdog by using an Arduino Mega 2650.  We used a Mega because it has 8K SRAM and we did not want to worry about running out of SRAM.  Yes, it's lazy, but quicker.  We will probably run out anyway!

Implementation details to follow

Software

The software is written in the standard Arduino IDE.   All of the code used in this article is posted on GitHub at github.com/projectcuracao.


No comments:

Post a Comment