Heltec-Aaron-Lee / WiFi_Kit_series

Arduino source codes and toolchain for WiFi_Kit_series made by HelTecAutomation.
GNU Lesser General Public License v2.1
732 stars 305 forks source link

ESP32 WiFi Lora Board - deep-sleep power consumption #6

Open rmh78 opened 6 years ago

rmh78 commented 6 years ago

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();
}
Heltec-Aaron-Lee commented 6 years ago

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

urs8000 commented 6 years ago

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

rmh78 commented 6 years ago

@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();
}
urs8000 commented 6 years ago

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.

gbiohazard commented 6 years ago

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

gbiohazard commented 6 years ago

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

apeman76 commented 6 years ago

Is there any news about this?

baxtery commented 6 years ago

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?

kovir commented 6 years ago

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

agirolami87 commented 6 years ago

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

DeuxVis commented 6 years ago

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"

agirolami87 commented 6 years ago

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

unimatrix099 commented 6 years ago

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 commented 6 years ago

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

gbiohazard commented 6 years ago

Hi,

It is hardware design issue. TM.

ToninoTarsi commented 6 years ago

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 ?

unimatrix099 commented 6 years ago

@gbiohazard Thank you

ayhoung commented 6 years ago

@gbiohazard any clue where the specific issue is?

gbiohazard commented 6 years ago

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).

baxtery commented 6 years ago

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 commented 6 years ago

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

mpatafio commented 6 years ago

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

goran-mahovlic commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

johannes-777 commented 6 years ago

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?

goran-mahovlic commented 6 years ago

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.

gbiohazard commented 6 years ago

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.

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

johannes-777 commented 6 years ago

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?

bradmcl commented 5 years ago

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.

lois-lee commented 5 years ago

@urs8000 Mine is also not waking up after the esp_deep_sleep_start() call, did you ever fix the problem?

urs8000 commented 5 years ago

@lois-lee my Heltec-WiFi board is working with the original code above from @rmh78 Tested with the new Arduino Setup (WIN10/IDE 1.8.5) and board=Heltec_WIFI_Kit_32 I do not longer work with that boards. (also not with lora version)

myszko commented 5 years ago

According with my tests the issue is related to the USB mode as mentioned previously by @bradmcl. Even with ESP32 on sleep mode and OLED disabled the node still drains 8-10mA. If I connect the USB to a PC and the PC recognizes it and after that disconect the cable, the current reduces to 1,3mA. This happens because the CP2102 goes to SUSPPEND MODE. For my case 1,3 mA is fine.

However the question is if there is any way (SW or HW) to force the CP2102 to susppend mode. Does anyone have any idea on this issue?

johannes-777 commented 5 years ago

@myszko: How did you measure 1,3mA? I use the UM25 USB Meter and it shows 3mA. Is there a new version of the board? Concerning the CP2102 I have no idea how to force it to sleep mode, other than plugging it into a usb-connector and unplugging it.
@urs8000: My esp32 never had a problem waking up from deepsleep UNTIL I deployed them in a bigger home automation project (12 sensors - not toooo big) and within 2 months two sensors did not wake up one time after 5 minutes of deep sleep. After hitting the reset button, everything worked fine, but the uneasy feeling remains. Any ideas?

urs8000 commented 5 years ago

@schabauerj sorry I've no long term experience with ESP32. How did you wake it up? Probably using the ULP as a watchdo could help if it does not wake up on your method...

divya0056 commented 5 years ago

@rmh78, Used your code and added Lora init , before the serial begin. Removed the power led. Noticed a strange behavior. If the serial speed is low there is more power used. So with serial. begin(1000000), and LoRa. sleep there got power down to 550 -600uah or around 0.5mah. it's prob cp2102 using most of the power.

andrelmbraga commented 5 years ago

@divya0056 Hello my friend, if I understand u achieved 0,5mA with the Heltec Board. Did u use the V1 board or V2? Did u change anything on the hardware? Can you share ur code pls?

jonashoechst commented 5 years ago

@divya0056 @myszko I got a power consumption of ~3,1 mAh (with suspended CP2102) which is still much higher than your 1,3 / 0,5 mAh. Can you describe all the things you did?

kampto commented 5 years ago

I have V2 Lora(sx1276) board with nothing connected to it for test purposes, Not calling the Wifi, RF or OLED librarys. Deep sleep current is 3ma as measured inline of LiPo battery. Thats as low as I can get.
I have Wemos ESP32 dev board and in deep sleep it draws <0.1ma.

divya0056 commented 5 years ago

Disconnect the lipo battery power for vcc 3v.

On Tue, Jan 29, 2019, 9:02 PM kampto <notifications@github.com wrote:

I have V2 Lora(sx1276) board with nothing connected to it for test purposes, Not calling the Wifi, RF or OLED librarys. Deep sleep current is 3ma as measured inline of LiPo battery. Thats as low as I can get. I have Wemos ESP32 dev board and in deep sleep it draws <0.1ma.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/issues/6#issuecomment-458782481, or mute the thread https://github.com/notifications/unsubscribe-auth/AMpwyeRvZwpPjdHo3sg0PSEpkQYBcJ5zks5vIP08gaJpZM4QsRgJ .

kampto commented 5 years ago

"Disconnect the lipo battery power for vcc 3v."

Sure, If I avoid everything and just power the chip itself the draw will be low, But this heltec board using LiPo regulator is high at 3ma compared to others. Difficult for long term battery operation

Heltec-Aaron-Lee commented 5 years ago

@divya0056 @kampto when in deep sleep mode, some GPIO need set input mode. use this example: https://github.com/HelTecAutomation/Heltec_ESP32/blob/master/examples/Low_Power/Low_Power.ino

kampto commented 5 years ago

@divya0056 @kampto when in deep sleep mode, some GPIO need set input mode. use this example: https://github.com/HelTecAutomation/Heltec_ESP32/blob/master/examples/Low_Power/Low_Power.ino

I tried that sketch exactly and with the correct Heltec_ESP32 package loaded. The "LoRa.sleep();" and "LoRa.end();" are not declared so it wont compile.
Anyway i've been using the Radiohead RF95 library and called a "rf95.sleep();" and set all those GPIO you listed to input. So same thing? But same result, about 3ma in sleep. Has anyone successfully gotten <1ma in sleep on this board without modifying the HW?

SloMusti commented 5 years ago

I have tested the above mentioned low power example with Helltec V2 board and managed to reach 1.44mA@3.7V during sleep periods. Any thoughs on further minimizing this to uA range?

leocastro536 commented 5 years ago

yo encontre que poniendo el pin 11 cmd del esp32 se podia llegar a (80-90)uAh, conecte el pin 11 del esp32 a 3.3v y funciono.

frankheisig71 commented 5 years ago

Hi guys, maybe a little late, but I had the same problem with TTGO LoRa32 (V1) deep sleep power consumption and I managed it by cutting the LDO from 5V circuit and by soldering the LiPo directly to LDO. Fortunately the LDO is wired to 5V-circuit by a more or less good reachable single track coming from right top (on my picture) to the right top corner of pin 1 of LDO. After this change CP2102 is powered only by 5V USB and working if USB is plugged. The on board LiPo-charger of course is not working. No problem for me, because I decided to use a discrete charging module with temperature tracking and batterie protection. But you may wire pin 3 of charger and pin 1 of LDO by a shottky diode - should work. Deep sleep power consumption now is 900uA.

Cut

(sorry for the bad picture quality...)

Skipper-is commented 5 years ago

Ah that is awesome! I'm currently stuck on 10.4mA during deep sleep. May have to give detaching the lipo charger and cutting the LDO off from the CP2102 to see how much improvement that gives me

Heltec-Aaron-Lee commented 5 years ago

@Skipper-is Only WiFi LoRa 32 V2 can down to 900uA in deep sleep. The V1 boards because of no low power design.

Anyway, you can choose from our LoRa Node Family, all of the new nodes products were well low power designed.

frankheisig71 commented 5 years ago

@Heltec-Aaron-Lee: The described cut-track-method manages to have 900uA on a V1 board. Of course, one may use a V2 board, but ... V1: 1pc 9$ at aliexpress (2pc. w/o OLED - 18$) V2: hard to get for less than 18$ (1pc.) And - it may help to find a usage for the 28 lying useless in ones drawer..
:-)

Heltec-Aaron-Lee commented 5 years ago

@frankheisig71 Oh, I wonder you still can buy a V1 board? We stopped producing it about 1 year ago, Is it possible it's just a bad copy? http://community.heltec.cn/t/wifi-kit-8-bad-copy/92