MPY DeepSleep and power consumption
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
MPY DeepSleep and power consumption
Hello.
I am beginner with coding and lost with micropython machine.deepsleep().
I am planning to make a mqtt enabled DHT22 & ESP32 with 2 x 2000 mAh Li-Ion power bank, which shall run for at least for a few months without external power. Regarding to ESP32 datasheet, the power consumption in deep sleep shall be somewhere between 10-150 uA, but practically with command machine.deepsleep() I measured power consumption 4,75 mA. Typical power consumption with CPU frequency 80MHz and no WiFi activity after rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) is about 37mA. With 4,75 mA deep sleep power consumption 4000 mAh power bank lasts only maximum 35 days.
Question: is there plans to add some deeper sleep options for the machine.deepsleep in near future, or is there some implementation issue which makes such options to be impossible with micropython?
Micropython code version: esp32-idf3-20200827-unstable-v1.12-687-gcef678b2d.bin
Hardware version: ESP32-Wroom-32S development board, ESP32D0WDQ5 (revision 1)
Thank you for your kind replies in advance.
P.S. For other Finns beginning with IoT project with ESP32, you might be interested my micropython code at https://github.com/divergentti/kotiauto ... ster/esp32.
I am beginner with coding and lost with micropython machine.deepsleep().
I am planning to make a mqtt enabled DHT22 & ESP32 with 2 x 2000 mAh Li-Ion power bank, which shall run for at least for a few months without external power. Regarding to ESP32 datasheet, the power consumption in deep sleep shall be somewhere between 10-150 uA, but practically with command machine.deepsleep() I measured power consumption 4,75 mA. Typical power consumption with CPU frequency 80MHz and no WiFi activity after rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) is about 37mA. With 4,75 mA deep sleep power consumption 4000 mAh power bank lasts only maximum 35 days.
Question: is there plans to add some deeper sleep options for the machine.deepsleep in near future, or is there some implementation issue which makes such options to be impossible with micropython?
Micropython code version: esp32-idf3-20200827-unstable-v1.12-687-gcef678b2d.bin
Hardware version: ESP32-Wroom-32S development board, ESP32D0WDQ5 (revision 1)
Thank you for your kind replies in advance.
P.S. For other Finns beginning with IoT project with ESP32, you might be interested my micropython code at https://github.com/divergentti/kotiauto ... ster/esp32.
-
- Posts: 169
- Joined: Fri Aug 19, 2016 11:55 am
Re: MPY DeepSleep and power consumption
I suspect this is not a software issue. Are you sure that it’s the ESP32 that is drawing that much power and not something else on your development board? (I’m not familiar with it, so I can’t tell.)
If trying another (somewhat more expensive) board is an option, I know that the TinyPICO is optimized for low deepsleep power usage.
If trying another (somewhat more expensive) board is an option, I know that the TinyPICO is optimized for low deepsleep power usage.
- rcolistete
- Posts: 352
- Joined: Thu Dec 31, 2015 3:12 pm
- Location: Brazil
- Contact:
Re: MPY DeepSleep and power consumption
It depends on the board with ESP32, mainly on USB and voltage regulator IC's. I have one ESP32 board which consumes 16 mA when in deepsleep...
TinyPICO and Pycom (LoPy4, etc) boards are well optimised ESP32 boards, consuming about 10-20 uA in deepsleep.
TinyPICO and Pycom (LoPy4, etc) boards are well optimised ESP32 boards, consuming about 10-20 uA in deepsleep.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).
Re: MPY DeepSleep and power consumption
I like the TinyPICO. I am also messing with some of the esp32 boards on here https://www.ezsbc.com/ and getting down to 10ua in deepsleep.
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
Re: MPY DeepSleep and power consumption
You might be right. Perhaps the ESP32 do not consume so much, but other components on the dev board does. Here is video https://youtu.be/sr3KVNzvce4 about the test setup. MPY code puts ESP to sleep for 5 seconds and then wakes it up and blinks the led once.Christian Walther wrote: ↑Fri Sep 04, 2020 12:00 pmI suspect this is not a software issue. Are you sure that it’s the ESP32 that is drawing that much power and not something else on your development board? (I’m not familiar with it, so I can’t tell.)
If trying another (somewhat more expensive) board is an option, I know that the TinyPICO is optimized for low deepsleep power usage.
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
Re: MPY DeepSleep and power consumption
Have you tested how much the U-version (with a SMA connector) consumes?nohc wrote: ↑Mon Sep 07, 2020 1:45 amI like the TinyPICO. I am also messing with some of the esp32 boards on here https://www.ezsbc.com/ and getting down to 10ua in deepsleep.
I ordered a few -U version dev. boards and 2.4 GHz external RP-SMA antennas for longer distance WiFi and deep.sleep. If deep.sleep do not work as it should, I can use them anyways in my PIR-motion sensors, which controls led stripes via mqtt-messages.
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
Re: MPY DeepSleep and power consumption
I confirm that micropython is not issue with deep.sleep.
I installed Arduino 1.8.13 and board extensions for ESP32 and then ran sample code "Simple Deep Sleep with Timer Wake Up" done by Pranav Cherukupalli, and during sleep power consumption was 4.75mA as it was with micropython.
I installed Arduino 1.8.13 and board extensions for ESP32 and then ran sample code "Simple Deep Sleep with Timer Wake Up" done by Pranav Cherukupalli, and during sleep power consumption was 4.75mA as it was with micropython.
Re: MPY DeepSleep and power consumption
I only tested the ones linked below and they work great so far. I ended up ordering a bunch of the feather style as I plan on making some custom sensor shields and its easy to find feather templates to work from. The boards have worked as advertised so I have no reason to believe the one you ordered would not. Looks like those do consume a little more current (17ua) but that's still very good IMO.
On the feather board I did have to drive one of the pins and hold to get it down all the way. Pin 13 was leaking current and the led would dimmly light up in deepsleep using MP. It was reading like 80ua before in deepsleep and with the below it gets down to 9ua. I don't know that will be the case with the board you ordered but I will post that code below for reference.
https://www.ezsbc.com/index.php/feature ... 1ZYQXlKiWE
https://www.ezsbc.com/index.php/feature ... 1ZYa3lKiWE
On the feather board I did have to drive one of the pins and hold to get it down all the way. Pin 13 was leaking current and the led would dimmly light up in deepsleep using MP. It was reading like 80ua before in deepsleep and with the below it gets down to 9ua. I don't know that will be the case with the board you ordered but I will post that code below for reference.
Code: Select all
from machine import Pin
import machine
import time
p13 = Pin(13, Pin.OUT)
p13.value(1)
p13 = Pin(13, Pin.OUT, Pin.PULL_HOLD)
time.sleep(5)
machine.deepsleep(20000)
p13 = Pin(13, Pin.OUT, None)
https://www.ezsbc.com/index.php/feature ... 1ZYa3lKiWE
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
Re: MPY DeepSleep and power consumption
Today I created my first low power setup with ESP32-Wroom32-U and seems to be good so far.
Video about how it wakes up and starts responding to pings at https://youtu.be/p3QVtX6NBw8 and peak current seems to be around 27 mA. In deep sleep my multimeter does not show anything.
Code is simple. In the boot.py kick up WiFi, WebREPL and then establish mqtt client connection, read AM2302 sensor 3 times, calculate average and send it to the mqtt broker and then sleep.
Video about how it wakes up and starts responding to pings at https://youtu.be/p3QVtX6NBw8 and peak current seems to be around 27 mA. In deep sleep my multimeter does not show anything.
Code is simple. In the boot.py kick up WiFi, WebREPL and then establish mqtt client connection, read AM2302 sensor 3 times, calculate average and send it to the mqtt broker and then sleep.
Code: Select all
""" snip """
import time
import machine
import dht
from machine import Pin
from umqttsimple import MQTTClient
try:
from parametrit import CLIENT_ID, MQTT_SERVERI, MQTT_PORTTI, MQTT_KAYTTAJA, MQTT_SALASANA, DHT22_LAMPO, \
DHT22_KOSTEUS, PINNI_NUMERO, DHT22_LAMPO_KORJAUSKERROIN, DHT22_KOSTEUS_KORJAUSKERROIN, NUKKUMIS_AIKA
except ImportError:
print("Jokin asetus puuttuu parametrit.py-tiedostosta!")
raise
# dht-kirjasto tukee muitakin antureita kuin dht22
anturi = dht.DHT22(Pin(PINNI_NUMERO))
# virhelaskurin idea on tuottaa bootti jos jokin menee pieleen liian usein
anturivirhe = 0 # virhelaskuria varten
client = MQTTClient(CLIENT_ID, MQTT_SERVERI, MQTT_PORTTI, MQTT_KAYTTAJA, MQTT_SALASANA)
def lue_lampo_kosteus():
""" Luetaan 3 arvoa 2s välein ja lasketaan keskiarvo, joka lähtetään mqtt:llä """
lampo_lista = [] # keskiarvon laskentaa varten
rh_lista = [] # keskiarvon laskentaa varten
lukukertoja = 0
lampo_keskiarvo = 0
rh_keskiarvo = 0
while lukukertoja < 3:
try:
anturi.measure()
except OSError:
print("%s: Sensoria ei voida lukea!")
return False
lampo = anturi.temperature() * DHT22_LAMPO_KORJAUSKERROIN
print('Lampo: %3.1f C' % lampo)
if (lampo > -40) and (lampo < 100):
lampo_lista.append(lampo)
kosteus = anturi.humidity() * DHT22_KOSTEUS_KORJAUSKERROIN
print('Kosteus: %3.1f %%' % kosteus)
if (kosteus > 0) and (kosteus <= 100):
rh_lista.append(kosteus)
if len(lampo_lista) == 3:
lampo_keskiarvo = sum(lampo_lista) / len(lampo_lista)
rh_keskiarvo = sum(rh_lista) / len(rh_lista)
time.sleep(2)
lukukertoja = lukukertoja+1
return [lampo_keskiarvo, rh_keskiarvo]
def laheta_arvot_mqtt(lampo_in, kosteus_in):
lampo = '{:.1f}'.format(lampo_in)
kosteus = '{:.1f}'.format(kosteus_in)
try:
client.publish(DHT22_LAMPO, str(lampo))
except OSError:
print("%s: Arvoa %s ei voida tallentaa mqtt! ")
return False
try:
client.publish(DHT22_KOSTEUS, str(kosteus))
except OSError:
print("%s: Arvoa %s ei voida tallentaa mqtt! ")
return False
print('Tallennettu %s %s' % (lampo, kosteus))
return True
def restart_and_reconnect():
print('%s: Ongelmia. Boottaillaan.')
machine.reset()
# resetoidaan
try:
client.connect()
except OSError:
print("% s: Ei voida yhdistaa mqtt! ")
restart_and_reconnect()
while True:
try:
lampo, kosteus = lue_lampo_kosteus()
laheta_arvot_mqtt(lampo, kosteus)
except KeyboardInterrupt:
raise
print("Nukkumaan %s millisekunniksi!" % NUKKUMIS_AIKA)
machine.deepsleep(NUKKUMIS_AIKA)
Re: MPY DeepSleep and power consumption
That's awesome. Did you have to initialize the LC709203F fuel gauge chip on it to get it that low? Is it able to cycle in and out of deep sleep using the timer? Thanks.nohc wrote: ↑Mon Sep 07, 2020 1:45 amI like the TinyPICO. I am also messing with some of the esp32 boards on here https://www.ezsbc.com/ and getting down to 10ua in deepsleep.