Power Switch for Feathers

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
olaf_the_snowman
 
Posts: 3
Joined: Thu Aug 11, 2022 3:19 am

Power Switch for Feathers

Post by olaf_the_snowman »

Hi,

I wanted to add a "simple and intuitive" (or "slightly more advanced"?) power switch to a Feather with the following requirements:
- Single button to turn the device on/off
- Option to turn off the Feather in software (e.g. when battery is low)
- Most importantly: Soft-shutdown that allows the Feather to save some internal state after OFF-button is pressed and before shutdown
...i.e. pretty much what everyone is used to from handheld battery powered devices in their pockets these days!

I came up with the circuit shown in the attachment:
- Remove pullup from the ENable pin (to me this would be the hardest step, but cutting something is always easier than fixing it afterwards)
- Add a momentary pushbutton to the enable pin: While the button is pressed, the board should be powered as normal
- Connect a GPIO to the enable pin and some diodes as shown below: Once the microcontroller is booted up, the first thing it does in the init() function would be to pull this GPIO high. From then on the button can be released and the board will keep on running.
- Connect another GPIO to the switch with a voltage divider: This one is supposed to check the button state. Once pressed (or pressed for at least 5 seconds or whatever), shutdown functions are executed and then the first GPIO is pulled low, such that the regulator is turned off.

Does this seem like a reasonable circuit or did I miss something? I'm particularly puzzled about the voltage divider for reading the switch, since it would have to cover the range from about 5V to 3V and transform it to something the microcontroller could interpret as a digital 1. Of course one could donate an analog pin, but maybe someone has yet another idea...

Also, I assume the quiescent current in the off state should be mostly determined by the "shutdown current" or whatever is specified for the regulator, and there are hopefully no other leakages? And this could only be reduced further by much more complicated circuits involving Mosfets and the like?

Thanks for any comments,
Olaf
Attachments
feather_switch.png
feather_switch.png (10.03 KiB) Viewed 161 times

User avatar
XRAD
 
Posts: 754
Joined: Sat Nov 19, 2016 3:28 pm

Re: Power Switch for Feathers

Post by XRAD »

maybe you can use the CTRL line through your code to shut down via this type of switch, once all data saved:

https://www.pololu.com/product/2808

I have used these in many projects....

User avatar
olaf_the_snowman
 
Posts: 3
Joined: Thu Aug 11, 2022 3:19 am

Re: Power Switch for Feathers

Post by olaf_the_snowman »

Some functionality like the polulu switches is pretty much what I want, yes. Except I don't see how these modules could match up with a Feather or any other development board with integrated charging circuitry. As I understand it, they'd have to go in between the charging circuit and the voltage regulators, which would mean no Feather, but two separate boards with the polulu switch in between...

User avatar
XRAD
 
Posts: 754
Joined: Sat Nov 19, 2016 3:28 pm

Re: Power Switch for Feathers

Post by XRAD »

Yes, when I wire these in, I use a separate USB 1s or 2s lipo 1A charger unit...super small and cheap component

Looks like your 4 major power needs are ?:
1) turns off w soft shutdown on v drop to 'x'
2) turns off w soft shutdown on button press
3) turns on/boot w button press
4) charges battery whether on of off

do you plan to have the feather charging circuit active while your feather program is in use? I did not see that in your initial post. I thought that feathers were designed to use whichever power source provided greater voltage BATT v USB. So then, if you only use your program while not charging, I think Pololu would work. Otherwise, the feather will use USB power...(assuming a 1s lipo plugged into charger port)

Also, I have used a super low drain 555 timer monostable mode delayed timer off switch simple circuit which will give you an 'x' seconds soft shutdown window to conclude your code..... The pololu 'off' button will not allow a delay.

also, I have used code that allows a single button with press millis timer to do different functions; ie: 1 sec hold turn ON, >2 sec hold turn off, etc

this is a cool project which I am sure many of us could use.......anyone else with ideas? Have to go Battlebots on now :)

User avatar
olaf_the_snowman
 
Posts: 3
Joined: Thu Aug 11, 2022 3:19 am

Re: Power Switch for Feathers

Post by olaf_the_snowman »

Thanks XRAD, the 4 requirements should be pretty much it. I wanted the "normal operation" to only happen, after the button is pressed, and not auto-start whenever USB is connected.

However, I thought about the Polulu switches again and came up with an alternative solution, that might get away with just a single GPIO. See the circuit sketched below, and ignore the red parts for now.

Let's go through all the cases I can think of:

1) Startup
a) Without USB and only battery connected: Once the momentary button is pressed, the Polulu should switch on, powering the feather, which will soon end up in the init() routine. Here the first thing I do is to set the GPIO as input and read it's value. If it's high, I know that I'm in battery mode and the button was really pressed and I should be doing whatever I usually do.
b) With battery and USB connected: The Feather will startup by taking power from USB and boot, even though the Polulu switch is still off and the battery is not charging. In the init() routine I find that we booted without the button being pressed, so I know we are in USB mode. I set the pin as output and send a 1, such that the Polulu switches on and the battery starts charging. Since the button was not pressed, I do not really want to run my main routines, so instead I'll go into a loop where I'll just wait for the button to be pressed and eventually continue the init() function or keep on waiting.
c) While waiting for the button, I turn off the Polulu switch every 5 minutes or so, to check, whether USB is still connected. If it is, I turn it back on and keep on waiting. If there is no more USB power, the microcontroller goes off and I don't have to worry.

2) Normal operation
In all cases of normal operation, I keep the pin as input, regularly monitor its value and use it for whatever I want. E.g. once it goes high for 5 seconds or so, I start the shutdown process.

3) Shutdown
a) After saving whatever I wanted to save, I wait until the button is no longer pressed to ensure that the Polulu switch does not go back to ON immediately. Eventually I set the pin as output and pull it low. The Polulu switch should now go off and so should the Feather.
b) If the feather does not go off and I reach the next couple of instructions, I know that there must be USB power available. I turn the Polulu back on, such that the battery charging can continue. Then I'll call init() again, which will find that the switch is not pressed and wait indefinitely for the power button to be pressed again.

Now tell me which absurd combination of buttons and connections I forgot and why this solution would not work. It seems very simple and elegant to me at the moment...

My only grief if that the battery is constantly drained through the voltage divider, so I added the red circuitry: Using a total of 13 MOhms and a small cap, I can hopefully reuse this line to monitor the battery level with reasonable accuracy, which I wanted to do anyways. Hopefully the switching circuit is not affected by the impedance or whatever...
Attachments
feather_switch_v3.png
feather_switch_v3.png (16.94 KiB) Viewed 129 times

User avatar
XRAD
 
Posts: 754
Joined: Sat Nov 19, 2016 3:28 pm

Re: Power Switch for Feathers

Post by XRAD »

two possible issues:

1) Monitoring voltage: When monitoring voltage of a 'second power source,' this typically works perfectly reading V divider through analog pin. But I have found issues when monitoring 'same' power source (a single external battery) which is also the same battery used to run the feather processor (basically inaccurate readings). Unless, you are monitoring only the 3.3v processor internal regulator (depending on feather processor)..... of course, this might have been my build design.....

2) I did not see your charging circuit plan, but I am pretty sure you can't charge the lipo batt back through the pololu switch for at least 2 reasons. If the pololu switch closed a 'reed' or mechanical type relay, then yes. Or yes if the charger is located off the feather...

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”