Secrets of the USB PowerControl – Application Notes

Secrets of the USB PowerControl – Application NotesIMG_2860 copy 2

Want to Control your Pi or Arduino?  Secrets?  What could be Secret about the USB PowerControl?

OK, well not really secrets.  What we are talking about here is three ways of using the USB PowerControl that aren’t documented in the specification.   Buy it here!

The three things are documented below the description of USB POwerControl.   What the three things are:

  • Making the USB PowerControl on by Default, when connected to a GPIO that needs to be initialized (like the Pi and Arduino GPIOs)
  • Turning off the USB PowerControl even if the battery is higher than ~3.3V and lower than ~3.8V.
  • Controlling the USB PowerControl with a 3.3V GPIO Line, WITHOUT a buffer.

What is the USB PowerControl?

The USB PowerControl board is a USB to USB solid state relay.  It is is a digitally controlled power switch for your Arduino orIMG_0884 Raspberry Pi.  It is a Pi On and Off switch.

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 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.

This board was initially designed to sit in-between a Solar Power Controller (such as SunAir/SunAirPlus) and a Raspberry Pi / Arduino. The input to the board was designed to come directly from a LiPo battery so the computer won’t be turned on until the LiPo battery was charged up aboveIMG_2986Smalljpg 3.8V. We provide 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).  This really happens!!!!  You kill Raspberry Pi SD Cards this way.

The software for this device is simple. You use one GPIO line to turn it on or off (or connect it directly to your LiPo battery for automatic control!). It controls the 5V line that powers a USB device plugged into the female USB A power end of the board.

Features

  • Can Switch the Power to any plugged into the Female A USB port
  • On/Off Controlled by a single control line Implements Hysteresis on Control line
  • 3.8V/3.3V Turn On/Off Voltage on Control Line 3.3V Turn Off Voltage on Control Line
  • Over Current Protection
  • Thermal Shutdown
  • Reverse Current Blocking
  • Can be connected to GPIO Pin or directly to LiPo Battery
  • Supports both Arduino and Raspberry Pi
  • Has Dual USB ports – no more cutting USB cables
  • Will work with SunAir and SunAirPlus Solar Power Controllers

The Secrets

Making the USB PowerControl on by Default, when connected to a GPIO that needs to be initialized (like the Pi and Arduino GPIOs)

The problem is that if the LIPOBAT input is floating, the USB PowerControl will stay off.   When an Arduino or Raspberry Pi is being initialized, the GPIO lines are in a high impedance state (floating) and the USB PowerControl will stay off.

While this is fine in many circuits, in SunRover, our new solar powered robot, it is not.  Why?   SunRover has two computers.  The Arduino based BatteryWatchDog (Power Management System) is supposed to be on all the time (and has a hardware watchdog to reboot it if it goes away).  However, if the BatteryWatchDog completely dies, we want the Raspberry Pi to reboot and tell us that there is a problem with the BatteryWatchDog.   This may not happen in every case, but we want it to happen in the situation where the Arduino goes away while leaving the GPIO floating.

IMG_5433To accomplish this, we solder a 10K Ohm resistor from LIPOBAT to TP2 which is the VDD5VIN from the external USB plug.  Now the USB PowerControl is default ON.

A second pleasant side effect of this is when we are debugging the SunRover robot, we don’t HAVE to have the Arduino BatteryWatchDog running.

 

Turning off the USB PowerControl even if the battery is higher than ~3.3V and lower than ~3.8V.

The situation for this came up in the development of WeatherPi.   The problem is that the WeatherPi detects when the battery voltage is less than 3.5V and shuts down.  However, when the Raspberry Pi shuts down it is still drawing current (~100ma by one measurement) and since the battery voltage is higher than 3.3V, the Raspberry Pi stays on.  Not what we want.

The scenario is this:

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 by adding a hardware watchdog timer. For a tutorial on hardware watchdog timers, read the SwitchDoc series starting here.

We used a Dual WatchDog Timer Board to fix this problem. We set the RaspberryPi python to “pat the dog” (preventing the watchdog IMG_3461timer 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.

“COut” is labeled TP3 on the USBPowerControl.  See the WeatherPi Instructable for full directions on how to do this.

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.

Controlling the USB PowerControl with a 3.3V GPIO Line, WITHOUT a buffer.

Turning the USB PowerControl by connecting a GPIO pin to turn it on and off works well with an Arduino (5V GPIOs), but what do you do if you want to turn it on and off with a Raspberry Pi (which has 3.3V GPIOs).  Well you can use a voltage translation buffer, or you can get clever and use a diode and a pullup resistor.

Connect a 10K Pullup resistor as in the first secret above to TP2 and the LIPOBAT pin, and then connect a diode with the anode towards the Raspberry Pi GPIO pin and suddenly, if your GPIO on the Raspberry Pi is at 3.3V, then the USB PowerControl is on.  If it is close to Ground (0.0V) then the diode will be forward biased and will drag the LIPOBAT pin below ~3.4V and the USB PowerControl is turned off. Magic!

Here is the circuit diagram:

secret3USBPowerControl

2 Comments

  1. Hi there,

    I’m trying to power my Raspberry Pi with both the SunAir Plus and the USB Power Control. I have the SunAir hooked up to miniUSB power and the USB PowerControl hooked up to that, yet its not powering on. So I figured the USB PowerControl was on default off, so I put a 10K resistor between the LipoBat and TP2 and the board still does not come on. Do I have a faulty board? Or am I just mistakenly not routing any power to it?

    Thanks for your help!

    • Kyle,

      Hooking it up for the first time is always tricky!

      Hook up LipoBat to 5V on the SunAirPlus board and you will see the light turn on.

      LipoBat has to be above about 3.6V for the USB PowerControl Board to turn on.

      SDL

Comments are closed.