WiFi_Kit_series icon indicating copy to clipboard operation
WiFi_Kit_series copied to clipboard

ESP32 WiFi Lora Board - deep-sleep power consumption

Open rmh78 opened this issue 6 years ago • 120 comments

Hardware:

Board: Heltec ESP32 WiFi Lora Board Core Installation/update date: 25/nov/2017 IDE name: Arduino IDE Flash Frequency: 80Mhz Upload Speed: 921600

Description:

I want to set the esp32 to deep sleep mode and measure the power consumption. The esp32 specification says that the power consumption should be in the µA range. My measurement is between 3mA and 10mA in deep-sleep mode. I'm powering the board with 3.7V lipo on the 3.3V input pin.

Sketch:

#include "esp_sleep.h"

#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  60       /* Time ESP32 will go to sleep (in seconds) */

void setup() {
  Serial.begin(115200);
  delay(1000); 

  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_sleep_pd_config(ESP_PD_DOMAIN_MAX, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
}

void loop(){
  delay(5000);
  esp_deep_sleep_start();
}

rmh78 avatar Nov 27 '17 20:11 rmh78

Seems you did't turn off the OLED's charger pump and set OLED into sleep mode, you may test with fellow codes:

display.sendCommand(0x8D); //into charger pump set mode display.sendCommand(0x10); //turn off charger pump display.sendCommand(0xAE); //set OLED sleep

Heltec-Aaron-Lee avatar Nov 28 '17 04:11 Heltec-Aaron-Lee

display.sendCommand(0x8D); what additional library and initialization is needed for the three commands? thanks for your help & info

urs8000 avatar Nov 28 '17 19:11 urs8000

@Heltec-Aaron-Lee STILL NOT WORKING I changed my sample program and added the lines of code to turn off the OLED charger pump and the OLED itself. But the power consumption stays the same (about 5mA). Any other suggestions to reduce power consumption down in the µA range. It would be great if you can provide us with an arduino sketch.

This is my changed program. Please double-check it.

#include <Wire.h>
#include "SSD1306.h"
#include "esp_sleep.h"

#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  20       /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int bootCount = 0;

SSD1306 display(0x3c, 4, 15);

void setup() 
{
  Serial.begin(115200);
  delay(1000); 

  initOled();
  display.drawString(0, 0, "hello world");
  display.display();
  delay(2000); 

  sendCommand(0x8D); //into charger pump set mode
  sendCommand(0x10); //turn off charger pump
  sendCommand(0xAE); //set OLED sleep

  delay(5000);
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_sleep_pd_config(ESP_PD_DOMAIN_MAX, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
  esp_deep_sleep_start();
}

void loop()
{
}

void initOled() 
{
  pinMode(16,OUTPUT);
  digitalWrite(16, LOW);    // set GPIO16 low to reset OLED
  delay(50); 
  digitalWrite(16, HIGH);   // while OLED is running, must set GPIO16 in high

  display.init();
  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_10);
  display.clear();
}

void sendCommand(unsigned char command)
{
  Wire.beginTransmission(0x3C); // oled adress
  Wire.write(0x80); // command mode
  Wire.write(command);
  Wire.endTransmission();
}

rmh78 avatar Nov 28 '17 22:11 rmh78

thanks

I‘ll try it soon

regards, urs

ATTENTION: be careful using the program without changing the delay(2000); ---> delay(20000); I had a lot of trouble getting a connection to reflash it (also using Rst/Prg )

Results: mine does not wake up after deep_sleep_start. no idea why.

urs8000 avatar Nov 28 '17 22:11 urs8000

Same trouble here, I'm stucked with 10 mA with everything sleeping.. Any solution ? Thanks

gbiohazard avatar Dec 03 '17 12:12 gbiohazard

I removed the oled display and the board is still draining 10mA.

gbiohazard avatar Dec 03 '17 12:12 gbiohazard

Is there any news about this?

apeman76 avatar Dec 29 '17 23:12 apeman76

powering at 5v : i have similar measurements, with LoRa and DHT-> 94 mA, without Lora active 46 mA and in deep sleep 11 mA. sleep and wake up works fine powering at 3.3v, i get 31mA but thats it, no sleep, how did u poer at 3.3 directly?

baxtery avatar Jan 14 '18 18:01 baxtery

@baxtery Have You got DHT sensor (temp and humid) working with OLED?

kovir avatar Feb 15 '18 15:02 kovir

Same issue, in deep sleep mode 11mA. Any news ? Thanks

agirolami87 avatar Mar 08 '18 10:03 agirolami87

This maybe can help reduce the consumption : https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/issues/17#issuecomment-368258052

"If you power the device from the 3.3V pin the battery charger won't be enabled"

DeuxVis avatar Mar 08 '18 10:03 DeuxVis

@DeuxVis I already tried in my tests, but without improvements.

agirolami87 avatar Mar 08 '18 10:03 agirolami87

I have 2 boards, both have this issue, in deep sleep power consumption is ~17 mA. So it can't be used on battery power. Please tell us if this is a software issue or a hardware design issue.

unimatrix099 avatar Mar 14 '18 09:03 unimatrix099

Also, where can we review the hardware design/schematic?

unimatrix099 avatar Mar 14 '18 09:03 unimatrix099

Hi,

It is hardware design issue. TM.

gbiohazard avatar Mar 14 '18 09:03 gbiohazard

I'm thinking to use this board for my project but 10mA in deep sleep will be a very big problem. Did someone solve this problem ?

ToninoTarsi avatar Mar 16 '18 12:03 ToninoTarsi

@gbiohazard Thank you

unimatrix099 avatar Mar 17 '18 11:03 unimatrix099

@gbiohazard any clue where the specific issue is?

ayhoung avatar Mar 19 '18 08:03 ayhoung

Here are the tests I made (initially on https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-1/10247)

Using Heltec LoRa board: Deep sleep 10.2mA Deep sleep OLED Off 10.2mA Deep sleep OLED unsoldered 10mA Deep sleep OLED and BMS (battery managing system (mcp73831 ?)) and LED remvoed : 2.6mA Deel sleep without : OLED, BMS, LED, CP210x : 2.6mA

Using Esp32 Core Board (LED removed): Deep sleep 4.5µA

Using ESP32 Core Board (LED removed) and NiceRF LoRa1276 (sx1276 based module): Deep sleep 1.76mA

Analysis: The sx127x can reach 1µA in deep sleep, so the total would be 5.5µA. BUT, the crystal used is a TCXO, which remains powered continuously. As I explained in thethingsnetwork topic, you'll have to power off the crystal (e.g. using µC pin and Mosfet) to achieve the expected low power consumption in deep sleep mode. If you still want to deep sleep µC while the LoRa is in listing mode (µC wake up by interrupt), the µC pin must be able to hold its state in deep sleep (the esp32 can on specific RTC pins).

See:

esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num) Enabling HOLD function will cause the pad to latch current values of input enable, output enable, output value, function, drive strength values. This function is useful when going into light or deep sleep mode to prevent the pin configuration from changing.

Sorry for my english (FR).

gbiohazard avatar Mar 19 '18 09:03 gbiohazard

i think we should design a PCB with a step up, a mosfet, esp32 and an SX1276 and wait for someone in china to copy it and sell it cheap on aliexpress :)

baxtery avatar Mar 19 '18 09:03 baxtery

but if we power off the sx, does OTAA still work after waking up from deepsleep?

baxtery avatar Mar 19 '18 09:03 baxtery

@kovir I did it! use the PIN 22 ;)

mpatafio avatar Mar 26 '18 10:03 mpatafio

I did try to wirite 0x00 to REG_TCXO - and get same consumption.

Do you have some working schematic how should TXCO powering look?

I did check schematics now and my measuring are for 32k clock...

dio1 It is off when in sleep and has only slight jump when sending Ok connected scope and it is only powered on while transmitting... Sending is set to SF7.

dscf0298

goran-mahovlic avatar Mar 28 '18 18:03 goran-mahovlic

But then you can check this module it claims StandBy current is 1uA and it does not have pin to enable disable TXCO so it should be somehow possible to disable it with registers... Dorji

There is some code in pdf files So I will try this at home ...

void sx1276_7_8_Standby(void) { //SPIWrite(LR_RegOpMode,0x09); //Standby//Low Frequency Mode SPIWrite(LR_RegOpMode,0x01); //Standby//High Frequency Mode SPIWrite(REG_LR_DIOMAPPING2,0x40); //DIO4 01 } /********************************************************** **Name: sx1276_7_8_Sleep **Function: Entry sleep mode **Input: None **Output: None **********************************************************/ void sx1276_7_8_Sleep(void) { //SPIWrite(LR_RegOpMode,0x08); //Sleep//Low Frequency Mode SPIWrite(LR_RegOpMode,0x00); //Sleep//High Frequency Mode SPIWrite(REG_LR_DIOMAPPING2,0x40); //DIO4 01 }

goran-mahovlic avatar Mar 29 '18 07:03 goran-mahovlic

Without removing any hardware parts I am down to 4mA. And putting the same code on ESP32 Devkit V1 board got 5mA 1mA more is probably because LED that is connected directly to 3.3V And I can see online that this board has problems with low power to...

So I would say that SX part is maybe not the problem.

Problem could be that we maybe need to check is ESP really going to right SLEEP mode. I have read that for true ultra low power you need to recompile few files to enable only one CPU core and set 32KHz as a main oscillator in LPM. I did try something but still have higher consumption then in original repo...

Removing BMS and LEDS did not lower consumption got 4-5mA with and without BMS.

Put BMS back did not put LEDS back and now I have 2.56mA (It was 4 without LEDS, maybe I did change something in code but I do not think I did)

My instrument cannot get consumption in mA while SX is sending so Im powering from USB until first send, and after that I disconnect USB... It seams that connecting it just to USB first and disconnecting it from USB did the trick with lowering to 2.5mA - If I just start same code just from battery it drains 10mA. After that it just powering up every minute and sends messages and goes into sleep consuming 2.5mA

https://gist.github.com/goran-mahovlic/72833b26fd61ecc04fcf0f74bffad575

https://youtu.be/Dt8NZsSrXiM

goran-mahovlic avatar Mar 31 '18 11:03 goran-mahovlic

Hi Goran, Thank you so much for taking the time to describe this issue. I tested with 3 different boards and thought I was crazy.

I have the same issue: If I plug my board into a USB-plug (and the Linux recognizes the new device), the power consumption is around 3mA. If I only power form Lipo (or a USB Power Bank), it is 11.7mA (with some sensors). If I power with Computer first and then hotswap to Battery, 3mA remain.
With 3mA my Battery application could last almost half a year (4x18650 with 3500mA), but 11,7mA is really a pain.
I thought I would change the startup code and began with disabling the Serial (Serial.end()) port before esp_deep_sleep_start(), but that would have been too nice :-) Then I digged depper in "/home/nemo/arduino-1.8.5/hardware/espressif/esp32/cores/esp32", but couldn't find the startup code for the serial port. Do you have any idea? Or is it hidden in Rom?

johannes-777 avatar Jun 19 '18 23:06 johannes-777

There is only one thing I have read after my post in TTN forum, but did not have time to try: https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-2/11973/568

When you put the ESP32 into deep sleep the GPIO pins go into high impedance mode, which is not good for devices on the SPI bus, such as LoRa. With the SPI bus high Z the LoRa device (also in sleep mode) takes the sleep current up to 120uA, not good. If you add pullup resistors on the 3 SPI pins and the LoRa device select pin, sleep current of an ESP32 and LoRa device is 7uA. Also note that although you should be able to leave the LoRa NRESET pin floating (it has its own internal pullup) if your driving it with the ESP32 then add an external pullup resistor, the ESP32 in deep sleep drags this pin low.

goran-mahovlic avatar Jun 20 '18 06:06 goran-mahovlic

One important thing to understand is that NSS (SPI Cable Select) is active low. In deep sleep mode, the esp32 releases all outputs state to low, so the LoRa chip becomes active again. The trick is to use the rtc_gpio_hold_en(gpio_num_t gpio_num) function to keep HIGH the NSS pin.

But wait, in deep sleep mode, only some specific pins are available to control: RTC pins.

  • GPIO18, used for NSS on the Heltec LoRa 32, isn't an RTC pins.
  • In deep sleep mode, GPIO18 will always go low
  • In deep sleep, LoRa chip will always be in standby mode (about 1.5 mA).

With my LoRa1276 (NiceRF) module, it stays <1µA when the esp32 is in deep sleep (GPIO04 NSS)

gbiohazard avatar Jun 20 '18 06:06 gbiohazard

Chip Select and Active Low is a good point :-) I will try this out and might be able to safe 1-2mA.
However, I don't see this connected to the "Plug me into a proper USB host first if you want low power Problem." Only after the USB-Serial converter is recognized by a host, the deep sleep power drops from around 10 to 3mA. However, if it restarts on Battery, it will be 10mA again.
This might be a bad design issue. I read that the firebeetle-esp32 has a good low power of less than 1mA. Which boards can you recommend?

johannes-777 avatar Jun 20 '18 07:06 johannes-777

So, if the schematics at https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/tree/master/SchematicDiagram are correct, and I'm reading the info on the CP2102 correctly at https://www.silabs.com/documents/public/data-sheets/CP2102-9.pdf and https://www.silabs.com/community/interface/knowledge-base.entry.html/2004/04/20/cp210x_current_draw-OUVM then it appears that if you start with a USB host, the CP2102 goes active, and then goes to Suspend after the USB is disconnected. If you just power up on battery, then it stays active looking for a USB connection. Apparently if there were a way to force the reset pin low you would get the Suspend level of power usage, but this board feeds the 5V bus from VBAT as part of the LDO circuit. If there was another diode in the LDO circuit between 5V and pin 1 of the U1 LDO ( and possibly a weak pulldown on pin 9 !RST of the CP2102 it would likely eliminate the problem; alternatively, if there was a way to use software to pull pin 9 !RST of the CP2102 low - by wiring it to an IO pin ( 3.3v vs 5v issue to solve ) then you could also force the state. So as others have said elsewhere, it is a hardware design issue on this board.

Depending on the board layout, it may be possible to cut a trace to isolate 5V from VBAT; you would be required to power the board separately from the USB even when using the USB, but it might solve the power drain when not on USB.

bradmcl avatar Jul 08 '18 01:07 bradmcl