Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Detection of USB Power Failure
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Detection of USB Power Failure

by TomHumbleAndHandsome on Tue Nov 30, 2021 1:43 pm

The documentation for ItsyBitsy M0 says

"You can always put any voltage you like into BAT and the circuitry will switch between BAT and USB dynamically for you. That means you can have a Batter backup that only gets enabled when USB is disconnected."

Great feature but I want my C++ program to detect that switch so that I can turn off my TFT display when I'm on battery power.

There's got to be a way to do this, I just haven't figured it out yet!

The documentation for the 2.8" TFT doesn't tell me what to expect for power consumption either but that's a subject for another post!

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Re: Detection of USB Power Failure

by sj_remington on Tue Nov 30, 2021 2:02 pm

Taking a look at the schematic diagram,
https://learn.adafruit.com/introducing- ... /downloads
one approach would be to add a 22K+33K voltage divider between VBUS (pin 3 on the board) and GND, with the tap to a digital pin.

Read the pin to detect 5V on VBUS.

sj_remington
 
Posts: 227
Joined: Mon Jul 27, 2020 4:51 pm

Re: Detection of USB Power Failure

by TomHumbleAndHandsome on Tue Nov 30, 2021 2:10 pm

Thanks SJ - I'll probably go that route but my background is software, so "voltage divider" sounds like something I would never have contemplated before.

Is a voltage divider something simple for an electronics newbie or am I destined to fry a few boards during my learning stage?

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Re: Detection of USB Power Failure

by sj_remington on Tue Nov 30, 2021 2:16 pm

A voltage divider, or some other approach, is required to reduce the 5V on VBUS to safe levels for a 3.3V digital input;
http://hyperphysics.phy-astr.gsu.edu/hb ... oldiv.html

It is about the simplest possible circuit but extremely useful, so you will see it used everywhere.

In this case, connect one end of a 22K resistor to VBUS (pin 3), the other end to a digital input AND to one end of a 33K resistor. The other end of the 33K resistor goes to GND (pin 2).

The division ratio is 33/55, so 5V is reduced to 3V.

ALWAYS use this technique, or better, use 5V to 3.3V level shifters, to connect 5V digital sensors to a 3.3V input.
https://www.adafruit.com/category/864

sj_remington
 
Posts: 227
Joined: Mon Jul 27, 2020 4:51 pm

Re: Detection of USB Power Failure

by TomHumbleAndHandsome on Tue Nov 30, 2021 2:31 pm

Thanks, sounds simple enough that even a software guy can do it!

Are 1/8 watt resistors good or do I need 1/4 watt?

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Re: Detection of USB Power Failure

by sj_remington on Tue Nov 30, 2021 2:37 pm

Power dissipation for a resistor is V^2/R

(5V)^2/ (55000 Ohms) = 0.00045 Watts.

The digital input draws no current.

sj_remington
 
Posts: 227
Joined: Mon Jul 27, 2020 4:51 pm

Re: Detection of USB Power Failure

by TomHumbleAndHandsome on Tue Nov 30, 2021 2:40 pm

That's comforting! Thanks, you solved this issue and chances are good I'll be using this a lot.

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Re: Detection of USB Power Failure

by TomHumbleAndHandsome on Tue Nov 30, 2021 2:51 pm

Actually, instead of reading that on a digital input, then powering down the TFT display based on the value of the digital input, it would seem logical to just use the output of the voltage divider as the backlight input for the TFT, taking the micro processor right out of the loop.

Here's where I think my question of power would matter. And I don't know what the TFT power requirements are either (Adafruit forgot to mention it for the 2.8" TFT but the 2.2" display uses 100mA).

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Re: Detection of USB Power Failure

by sj_remington on Tue Nov 30, 2021 3:29 pm

Voltage dividers cannot be used as power supplies! You will need to learn some circuit basics if you want to continue on this path.

The usual approach for powering an LED or backlight is to use a voltage dropping or current limiting resistor.

Steps are:

1. Measure the current I required to power the backlight when powered by 3.3V, or look it up in the display data sheet.
2. Calculate the value of the voltage dropping resistor using Ohm's law R = V/I, where V = voltage to be dropped, or 5.0-3.3 = 1.7V.
3. If R is not a standard value resistor, connect the next higher standard value resistor from VBUS to the backlight power input.
4. Increase R to reduce brightness or current draw, if you wish.

sj_remington
 
Posts: 227
Joined: Mon Jul 27, 2020 4:51 pm

Re: Detection of USB Power Failure

by TomHumbleAndHandsome on Tue Nov 30, 2021 4:18 pm

Thanks, I'll remember that. I'll just use the voltage divider as an input.

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Re: Detection of USB Power Failure

by TomHumbleAndHandsome on Sun Dec 19, 2021 4:26 pm

SJ, Here's an update - I'm calling it RESOLVED... However:

Adafruit's definition of the Itsybitsy USB pin says:

USB - This is the same pin as the MicroUSB connector's 5V USB power pin.
This should be used as an output to get 5V power from the USB port.

This implies to me that it would have no voltage (zero volts) when USB is not plugged in. However in actuality, it seems to float back up to 3.12v when running on LiPo battery input, making the output of the voltage divider 3/5 x 3.12 = 1.9v which my digital input read as "true."

All is not lost, I just ran the same line to an analog input instead and now I accomplish my goal of detecting if I'm running from battery or Line power.

I've got to add that this probably would have been easy peasy for someone else and there could be a different solution.
For example; I think (but I'm not sure) that this USB line is "floating" when the USB is not connected - that is to say, maybe I could add a pull-down resistor to it and get my desired "zero volts" on that pin...
But tossing in a pull-down resistor when you're not sure what you're doing is dangerous so I'll stick with my analog input solution!

Thanks for your help

TomHumbleAndHandsome
 
Posts: 59
Joined: Mon Feb 15, 2021 6:38 pm

Please be positive and constructive with your questions and comments.