New Product – USB PowerControl With Grove

New Product – USB PowerControl With GroveUSB PowerControl

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.  You can even use it as a Raspberry 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.

We have now added a Grove Digital Input that allows you to control the USB PowerControlV2 using two GPIO Lines (one enable and one control line) to switch on and off from a Grove Digital Port.   The Grove Enable Line, when high, disables the LIPOBATIN line and makes control of the device under the Grove Control Line.   When the Grove Enable Line is low, the LIPOBATIN line controls the relay as in the original USB PowerControl.   The Grove Enable Line is pulled down by a 43K resistor so if it is disconnected, the USB PowerControlV2 is compatible with the original USB PowerControl.

[callout size=”col-12″ title=”USB PowerControl / NE” button_title=”Buy” button_link=”https://store.switchdoc.com/search.php?search_query=USB+PowerControl+V2″  button_size=”normal” button_rounded=”true” button_color=”red”]

 

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

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 with LIPOBATIN
  • – Grove Digital Connector – ENABLE and CONTROL your USB Port
  • – 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

Software

The software for this device is simple.
We have now added a Grove Digital Input that allows you to control the USB PowerControl using two GPIO Lines (one enable and one control line) to switch on and off from a Grove Digital Port.   The Grove Enable Line, when high, disables the LIPOBATIN line and makes control of the device under the Grove Control Line.   When the Grove Enable Line is low, the LIPOBATIN line controls the relay as in the original USB PowerControl.   The Grove Enable Line is pulled down by a 43K resistor (pulled up by a 43K Ohm resistor on the EN board)  so if it is disconnected, the USB PowerControl is compatible with the original USB PowerControl.

Don’t use Grove?   Here is an adaptor to pin headers:  Grove to Pin Header Adaptor

The difference between the normal (0042) and the NE (0043) version of this board is the sense of the ENABLE Line.   It is active high for the 0042 board and active low for the NE (0043) board.

USBPowerControl

This code is taken from SmartPlantPi, a Raspberry Pi based plant watering system.

First you set up the GPIO pins you are going to use:

         USBControl = 16
         USBEnable = 19

         GPIO.setup(USBEnable, GPIO.OUT)
         GPIO.setup(USBControl, GPIO.OUT)
         GPIO.output(USBEnable, GPIO.HIGH)

To turn the USB on , you just have to follow this design pattern :

  
         GPIO.output(USBControl, GPIO.HIGH)
To turn the USB Off do this:
 
        GPIO.output(USBControl, GPIO.LOW)

USB PowerControlNE Board

First you set up the GPIO pins you are going to use:

         USBControl = 16
         USBEnable = 19

         GPIO.setup(USBEnable, GPIO.OUT)
         GPIO.setup(USBControl, GPIO.OUT)
         GPIO.output(USBEnable, GPIO.LOW)

To turn the USB on , you just have to follow this design pattern :

         GPIO.output(USBControl, GPIO.HIGH)
To turn the USB Off do this:
        GPIO.output(USBControl, GPIO.LOW)

Grove GPIO Control Circuitry for the USB PowerControl

This circuitry is provided to allow the USB PowerControlV2 to be controlled by either LIPOBATIN or the state of the CONTROL Line (J3 Pin 1). ENABLE (J3 Pin 2) controls whether the USB POWERCONTROLV2 is switched by LIPOBATIN or the CONTROL line.   Remember that LIPOBATIN is not a digital input.  It is designed to look at the voltage level of the battery.

The truth table for the USB PowerControlNE V2 is given below:

Grove GPIO Control Circuitry for NE

This circuitry is provided to allow the USB PowerControlV2 to be controlled by either LIPOBATIN or the state of the CONTROL Line (J3 Pin 1). ENABLE (J3 Pin 2) controls whether the USB POWERCONTROLV2 is switched by LIPOBATIN or the CONTROL line.   Remember that LIPOBATIN is not a digital input.  It is designed to look at the voltage level of the battery.

The truth table for the USB PowerControlNE V2 is given below:

 

LIPOBATIN

If you are using the LIPOBATIN to control the USB PowerControl there is no software.

This board was initially designed to sit in-between a Solar Power Controller (such as SunAir/SunAirPlus) and a Raspberry Pi / Arduino.   The LIPOBATIN 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 above 3.8V.  We provide a hysteresis circuit so the board won’t turn off until the voltage goes below around 3.3V.  This is an excellent board to shut on and off USB powered devices like a Raspberry Pi and Arduino.  It works just like a conventional relay, except that it requires virtually no current to keep it on or off.   Like a latching relay.

The USB PowerControl Hysteresis circuit on LIPOBATIN is based on a TA75S39 Operational Amplifier used as a comparator.  A comparator with hysteresis has two important thresholds: upper and lower. Unlike a simple comparator, however, the output of the comparator doesn’t depend solely on whether the input is above or below one of these thresholds. It depends on both the current state of the output and the current value of the input. If the output is high, it will stay high until the input voltage drops below the lower threshold. If the output is low, it will stay low until the input voltage rises above the upper threshold.

The diagram to the right shows a hysteresis ‘loop’ that describes how a comparator functions. The horizontal ‘X’ axis is the input, and represents the difference of the two input voltages. The vertical “Y” axis represents the comparator’s output state.

If the comparator is initially ‘OFF’, the MINUS input voltage has to become slightly above the PLUS input voltage before the comparator output turns ‘ON’. This is represented by moving right along the bottom part of the loop.

Once the comparator is ‘ON’, the MINUS input voltage needs to drop slightly below the PLUS input voltage before it turns ‘OFF’ again (moving left along the top of the loop).

The ‘ON’ state is set in the USB PowerControl to be 3.8V and the ‘OFF’ state is set to be about 3.3V.   The output of the comparator drives the input to the Load Switch.

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

“COut” is labeled TP3 on the USBPowerControl.

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.