I’m looking to add an on/off switch with my Power Shield design that allows the end-user to turn off the whole device.
Any suggestions on where I could integrate a power switch?
I’m looking to add an on/off switch with my Power Shield design that allows the end-user to turn off the whole device.
Any suggestions on where I could integrate a power switch?
Are you designing your own power shield or using the Particle Power Shield in a design?
How much current does the whole device require when it’s on, and what is the quiescent current requirement when it’s off?
I’m using the official Particle power shield. It’s supplying everything properly through usb or battery power.
My conundrum is finding a way to integrate a power switch in between the power shield and the particle connections.
bump
Still trying to find away to cut in on the power/battery shield and be able to turn it off and on.
I’m also looking for this for an upcoming project.
Instead of switching off completely you could enter deep sleep, then wake the device using the wkp pin. a momentary switch should do the job, kinda like how the power button on your computer works. its not powered completely off but will be pretty low power draw…
you could also incorporate auto power off after a given time to save power too.
This is a great idea I'll look at revising my code to put the device into deep sleep after x amount of minutes.
If I did this how would I wake the device back up? Would pushing the switch on the wkp pin do that? In my particular use case I'm hoping to fully enclose/waterproof the device and then charge it with a wireless power charger.
Yep in deep sleep it will wake after the given time elapsed or the wkp pin is triggered.
and some demo code to show how easy it is! a button and a 10k pull-down resistor does the job nicely
void setup() {
attachInterrupt(WKP, shutdown, RISING); //declare the interrupt rising so button pulls to vcc
//rest of your setup code
}
void loop() {
//your loop code
}
void shutdown() {
System.sleep(SLEEP_MODE_DEEP, 99999); //sleep for ages :)
}
Awesome that make sense! Just so I’m totally clear though (I’m fairly new to this) I could also run shutdown()
within my function or after a given time? Maybe something like this:
void setup() {
attachInterrupt(WKP, shutdown, RISING); //declare the interrupt rising so button pulls to vcc
//rest of your setup code
}
void loop() {
//your loop code
unsigned long time = millis();
if( lastActive + 600000 < time){ //if it's been longer than 10 minutes go to sleep
shutdown();
}
}
void particleVar () { //this runs based on Cloud API Variable
//other stuff here
unsigned long lastActive = millis();
}
void shutdown() {
System.sleep(SLEEP_MODE_DEEP, 99999); //sleep for ages :)
}
Yeah that should work
Are you using the power shield too? There is a sleep mode for the battery gauge you could call to save power too
I will be using the Power Shield, yes. Since my device will be fully enclosed I'll likely explore a way to turn off the battery gauge on the shield.
Is there documentation for that somewhere? I'm looking at the Datasheet but may be missing it.
Sorry i was thinking of the sparkfun battery shield! but it does use the same battery gauge chip, so there is a sleep option that drops power consumption from 50uA to 0.5uA.
@mohit I think you did the port of the library, any chance of getting the sleep and wake functions added to the library? the sparkfun lib has them implemented but in a slightly different way (ie - i tried to write the functions for you but couldnt work out the bit moving stuff ) . Also the clear alert doesn’t clear the alert bit? does reading the register clear the bit automatically? I only noticed that because i wanted to compare the functions to write the sleep wake ones
Will the power shield be open sourced? i cant see it on the spark git links
@mohit I think you did the port of the library, any chance of getting the sleep and wake functions added to the library?
I'm not finding the library, is this the firmware that runs on the Particle by default? I did find this one which is for the battery gauge but as you mentioned it doesn't seem to contain sleep.
Is that the one you were asking about @Hootie81?
Yep thats the one i was asking about, its available in the libraries in the webIDE too
Have a look at the library for the Sparkfun battery shield here it has the sllep function you might want to implement.
Thanks @Hootie81 I’m finually starting to understand all this a bit better.
I have been trying to wrap my head around this line:
attachInterrupt(WKP, shutdown, RISING); //declare the interrupt rising so button pulls to vcc
If I understand this correctly it’s needed only to put the device asleep at the push of the button but not to wake the device up, is that correct?
The reason i ask is that my project will currently have 2 ways the device will go to sleep:
particle.function()
I’m not thinking I want to use a button to put the device to sleep but will want one to wake it back up.
Thanks for all your help on this.
Yeah that was just the line to put the device to sleep. You can leave that out and the button won’t put it to sleep.
Hi All,
I just found this, I’m looking to integrate a power on/off button on a photon project.
My project uses a power shield, too.
Am I right in thinking that following the above code that contains:
void setup() {
attachInterrupt(WKP, shutdown, RISING); //declare the interrupt rising so button pulls to vcc
//rest of your setup code
}
Should allow me to go into deep sleep with a button push while the photon is awake, and then rewake it when I press it again from sleep?
How about if I want to have a long press enter the deep sleep - in other words, only go into sleep with a 3 second press or so?
How do I also put the power shield in lowest power mode?
Thx
For long-press you can have a look at the ClickButton
library or run you own scheme with a combo of RISING/FALLING interrupts.