Tutorial: Part 4 -Building a Solar Powered Raspberry Pi Weather Station – GroveWeatherPi

Tutorial: Part 4 -Building a Solar Powered Raspberry Pi Weatheron-off_plain Station – GroveWeatherPi

The Raspberry Pi is a fabulous device to on which to build your projects.    The GroveWeatherPi project is designed to show the capabilities of this computer while remaining accessible to a diverse Maker community.

GroveWeatherPi is a Solar Powered Raspberry Pi WiFi connected weather station designed for Makers by SwitchDoc Labs ( www.switchdoc.com). This is a great system to build and tinker with. All of it is modifiable and all source code is included.

This tutorial for building your own Solar Powered Weather Station based on the Raspberry Pi consists of 14 parts.

[include-page id=”gdplinks”]

Safely Turning the Pi On and Off 

The Brownout Problem

In this important step, we are going to discuss the problem of powering down and up your Raspberry Pi. In Solar Powered systems, this is called the “Brownout Problem”. We will be showing how to use a simple device, the USB Power Control from SwitchDoc Labs to solve this problem.

One of the most important issue in designing a Raspberry Pi Solar Power System is turning on and off. The “Brownout Problem” is a real issue. Why worry? If you have a long string of cloudy days, you may run your battery down. You can compensate for this in your design by adding more panels and more batteries, but that can get really expensive and your system might still run out of power, just a lot less frequently.

Shutting Off the Pi

Shutting a Raspberry Pi off is pretty easy. When the battery voltage falls below some value, you just do a “sudo shutdown -h now” and your Raspberry Pi will shutdown cleanly. After doing the test talked about here ( https://www.switchdoc.com/2015/04/turning-the-pi-on-and-off-weatherpi-solar-power/ ) , we chose 3.5V as the voltage to shut down the Raspberry Pi.

Note that in most solar power systems, you need to monitor the battery voltage and not the 5V power supply because with most modern voltage booster systems, the circuitry will work very hard to keep the 5V going and then just give up crashing to a much lower voltage when it runs out of power.

Figure9
Showing Shutdown Voltage and Startup Voltage on the Raspberry Pi

That means your computer would have little or no warning when the voltage is about to drop. By monitoring the battery voltage, you can tell when the battery is getting low enough and then shut down your computer safely. For LiPo batteries, this will be when your voltage gets down to about 3.5V or so. This can all be monitored with the SunAirPlus solar charge controller that we are using in GroveWeatherPi.

Starting the Pi 

Enough about shutting down the computer. What about starting it up?

The Issue

You can’t just let the controller power up the computer. The problem is that the supply voltage will move up and down until there is enough charge in the battery to fully supply the computer. When the computer turns on (connecting a full load), you will pull the battery down hard enough to brown out the computer causing the Raspberry Pi to crash. This constant rebooting cycle can corrupt and ruin your SD card and cause your computer to never boot at all, even when the power is restored. We had this VERY thing happen to us 3500 miles away with Project Curacao. Arduinos are more tolerant of this, but Raspberry Pi’s do not like a ill-behaved power supply. You just can’t be sure of what state the computer will power up at without a good power supply.

This issue can be handled in a number of ways. The first is to use another computer (like an Arduino made to be very reliable by using a WatchDog – see the Reliable Computer series on switchdoc.com – https://www.switchdoc.com/2014/11/reliable-projects-watchdog-timers-raspberry-pi-arduinos/ ) to disconnect the Raspberry Pi’s power through a latching relay or MOSFET when there isn’t enough power. Project Curacao ( https://www.switchdoc.com/project-curacao-introduction-part-1/) used this approach.

We didn’t want to add an additional computer to GroveWeatherPi, so we chose a second solution.

Power Your Pi Up and Down with the USB Power Control

A second (and cheaper!) way of handling the brownout and power up problem is to use a dedicated power controller that will shut the power off to the Raspberry Pi and restore the power when the battery voltage is high enough to avoid ratcheting the supply voltage up and down because of the load of the Raspberry Pi.   This is called Hysteresis. We have designed a board to do just this (called the USB Power Controller) that will plug between the USB coming out of the SunAir Solar Power Controller and the Raspberry Pi as in the picture to the below.

GroveWeatherPi
SunAIrPlus Plugged into the USB Power Control Board

The USB Power Controller Board 

The USB PowerControl board is a USB to USB solid state relay.

Anything you can plug into a USB port can be controlled with USB PowerControl. It’s easy to hook up. You connect a control line (a GPIO line or the output of a LiPo battery) to the LIPOBATIN line on the USB Power Control device and if the line is LOW (< ~3.3V) the USB Port is off. If it is HIGH (above 3.8V) the USB Port is turned on and you have 5V of power to the USB plug.

There is a hysteresis circuit so the board won’t turn on and then turn immediately off because the power supply is yanked down when the computer turns on (putting a load not the battery).

There is little software for this device. You connect it directly to your LiPo battery for automatic control! The only software used detects the battery voltage and decides when to shut down the computer. The USB Power Control takes care of shutting the power to the Raspberry Pi when the battery voltage gets low enough. Note that a shutdown Raspberry Pi still draws current (according to one quick measurement, about 100ma).

One More Scenario 

One last point. After thinking about the power down sequence, we came up with one more scenario. What if:

  1. The battery voltage reaches 3.5V and the Raspberry Pi is shut down.

2. The USB PowerController will turn the power off when the battery reaches about ~3.4V.

However, what if the sun comes up at this time and the battery starts charging again?

Then the USB PowerController will never reach ~3.4V and will never turn off. And the Pi will never reboot. Not a good scenario!

We fixed this problem by adding a hardware watchdog timer.

For a tutorial on hardware watchdog timers, read the SwitchDoc series starting here.   https://www.switchdoc.com/2014/11/reliable-projects-watchdog-timers-raspberry-pi-arduinos/

We used a Dual WatchDog Timer Board to fix this problem. We set the RaspberryPi python to “pat the dog” (preventing the watchdog timer from triggering) every 10 seconds. The timer is set to trigger after about 200 seconds if it isn’t patted. The timer is connected to pull the “COut” point down to ground on the USB PowerController which shuts off the Raspberry Pi.

Because of the hysteresis circuit on the USB PowerController the Raspberry Pi will stay off until the battery voltage reaches ~3.9V and then the Pi will reboot. Now the above scenario will never happen. By the way, there is no real way of using the internal Pi Watchdog to do this. You don’t want to reboot the Pi, you want to shut off the power in this scenario.

If you don’t want to solder the one wire required (which will be replaced with a jumper pin and Grove connector in the next version of the USB PowerControl board), you may leave this board out.    You may have to go out and hand reset your solar power station when the above scenario occurs, but hopefully not too often.

USB PowerControl
Block diagram of USB/SunAirPlus
Figure12
Dual WatchDog Timer