I built a project using a Pro Mini (328p 8MHz) and a rf24 module. I was putting it to sleep for circa 1 minute and waking up to transmit some data, all worked perfectly using the Rocketscream library. This was the code used;
for (int i = 0; i < 6; i++)
{
LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
SPI_OFF, USART0_OFF, TWI_OFF);
Now, I've designed a pcb and assembled it using a ATmega328PB, which to my surprise all works as it did with the Pro Mini. As it works I wanted to get the sleep mode working again. So sleep for 1 minute-ish, wake up and transmit the data. I came across the fork of Rocketscreams library, by Canique (see link if needed)
But the previous bit of code does not work. In the error message it states the snames of the SPI_OFF etc should be changed to SPI0_OFF but it still will not compile. The only bit of code which works is this bit (below) but I don't want to switch off BOD, due to running on batteries, so it's not going to be turning much off.
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
I renamed files and uninstalled the libraries, so it's not that they're classing but I'm stumped now.
AFAIK the only peripherals you need to turn off when going to the Power Down sleep are ADC and BOD. The others are turned off when the clock is stopped in either case. You may safely turn off the BOD - when walking up from sleep it is turned on.
Smajdalf:
AFAIK the only peripherals you need to turn off when going to the Power Down sleep are ADC and BOD. The others are turned off when the clock is stopped in either case. You may safely turn off the BOD - when walking up from sleep it is turned on.
Ah okay. That would make sense why the example only shows what you stated, in the op. I don’t understand why all the other things are turned off in my code for the 328P then.
Further help anybody;
So, I originally reduced the the consumption to 190uA when asleep with the pro mini but the lost I get with the 328PB is 5mA.
Now, one reason is that I’m running a bme280 and a nrf24l01 from the power rail, so I’m assuming they will always draw current, even if the 328PB is asleep.
To solve this, should I pull all pins low/high? I’ve read about floating pins but I can’t get my head around what to do with those. Anybody help there please. I’ve read the Nick Gammon post but it baffles me in all honesty.
Floating pins are not a problem in Power Down sleep unless you use the particular pin for wake up.
nRF24l01 can be also configured for power down sleep which will reduce its consumption for <1 uA. Look into the nRF library you are using if it has a way to do so.
If you have the better PA+LNA version the extra will probably consume more current - I am not sure if it can be put into sleep too.
IIRC BME can be put into some low power state too.
Smajdalf:
Floating pins are not a problem in Power Down sleep unless you use the particular pin for wake up.
nRF24l01 can be also configured for power down sleep which will reduce its consumption for <1 uA. Look into the nRF library you are using if it has a way to do so.
If you have the better PA+LNA version the extra will probably consume more current - I am not sure if it can be put into sleep too.
IIRC BME can be put into some low power state too.
Okay, will look into putting the modules to sleep. I would have researched this prior to making a pcb but the consumption was very low without doing so. I have not wired the IRQ pin for the nrf24l01, so not sure if I can put it to sleep or if thats just for an interrupt? We’ll see.
I took off the bme280 and rf24 modules and measured the consumption but nothing seemed to change. I’m using a cheap clamp on meter, so I’ll measure later with my Fluke. Cheers
Okay, thank you for confirming. I’ll read through the article tonight and try to figure out how to fit that in my code.
As it’s like looking at hieroglyphics currently, could you please throw me another tit bit. The the 328PB woken via a timer or an interrupt in that code? I’m wanting a timer, as I could have used the IRQ pin of the rf24 but I didnt connect that up.
I‘ll go through that properly tonight and then look how to put it on a timer, unless I can delay the rf24 or bme280 taking/sending data and use that as an interrupt.
I uploaded the codes, the first one, a blink sketch, which worked and then the second included the sleep modes etc with an external interrupt. In sleep mode the current draw settled around 30uA and with the interrupt (LED on) the draw was circa 1.2mA. So that’s incredible.
I’ll have a go at trying to put that into my code tomorrow and see what happens. I’ll read up on internal and external interrupts.