Espruino Wifi Power Consumption in Deep Sleep at 2mA

Posted on
Page
of 2
Prev
/ 2
  • Tue 2020.03.03

    Hi @maze1980 I see that post #25 is identical to post #8

    Maybe the edit to post #9 from a week ago was missed? While your concern is valid, the additional note indicates deep sleep couldn't occur in that case. I believe that @narath addressed that, but I'll agree there doesn't appear to be a validation from him.

  • @Gordon - I was using the following commands to save:

    1. reset()
    2. Upload using IDE with Communication Mode > Save On Send > RAM
    3. save()
    4. dump() to check what was written

    Interestingly, the Blue LED is now showing again, and A13.read() no longer turns it off, nor does wifi.disconnect();

    I did download the latest edge firmware and flash it - unfortunately no change - power consumption still 2.3 mA

  • @maze1980 - thanks for pointing that out. I removed all the console lines - and the same power consumption.

    @Robin - I tried checking all the pin modes - they don't seem to change. I used this code:

    console.log("A0 = ",getPinMode(A0));
    console.log("A1 = ",getPinMode(A1));
    console.log("A4 = ",getPinMode(A4));
    console.log("A5 = ",getPinMode(A5));
    console.log("A6 = ",getPinMode(A6));
    console.log("A7 = ",getPinMode(A7));
    console.log("B0 = ",getPinMode(B0));
    console.log("B1 = ",getPinMode(B1));
    console.log("B3 = ",getPinMode(B3));
    console.log("B4 = ",getPinMode(B4));
    console.log("B5 = ",getPinMode(B5));
    console.log("B6 = ",getPinMode(B6));
    console.log("B7 = ",getPinMode(B7));
    console.log("B8 = ",getPinMode(B8));
    console.log("B9 = ",getPinMode(B9));
    console.log("B10 = ",getPinMode(B10));
    console.log("B13 = ",getPinMode(B13));
    console.log("B14 = ",getPinMode(B14));
    

    And got this output:

    A0 =  analog
    A1 =  analog
    A4 =  analog
    A5 =  analog
    A6 =  analog
    A7 =  analog
    B0 =  analog
    B1 =  analog
    B3 =  analog
    B4 =  analog
    B5 =  analog
    B6 =  af_output
    B7 =  af_output
    B8 =  analog
    B9 =  analog
    B10 =  analog
    B13 =  analog
    B14 =  analog
    
  • Tue 2020.03.03

    @narath thank you for the validation and pin mode output as that will assist us all.

    'Interestingly, the Blue LED is now showing again'
    'I did download the latest edge firmware and flash it'

    Please post process.env for Gordon, thanks.


    Regarding pin mode. Now I'm a bit befuddled. In post #22 I was under the impression that it would be intentional to set A0 and A1 to 'pulldown' however the output is showing 'analog'.
    Was this done on immediate power-up with no code saved and just uploading the getPinMode() code snippet?

    Please see Gordon's comment in post #24 before setting all to a known state. Has that suggestion been tried? When done, please post pre and post pin mode output to verify none are changing.

    I wish I could find the post, (first read by me around three months ago - @allObjects was this one of yours?) that provided some insight as to setting to a known state, and the consequences that might result if not done. (even after chip power on to it's default state)

    EDIT Thr 2020.03.05:
    Found it!! But specifically for nRF and not STM
    At minimum, read post #15 thru post #17
    http://forum.espruino.com/comments/14608­669/

    Also remember a comment, but I think pertained to USART port pins, about not leaving in a certain state as that left the oscillator on.   (still searching. . . . )   A S.W.A.G. hunch here, but in 'analog' mode, maybe related to PWM reads, possibly requiring that oscillator?

    Narath I know you are extremely detailed and vigilant, but is there a chance something else has changed in the setup? Originally, I started to think that the flash process disconnected the battery-resistor test circuit, and this was cured by that (thumbs up image) task. But, as has been indicated, other things changed, such as code line clean-up and technique etc.

  • Hey @Robin, you are right, I had been trying a lot of different things at once. Let me try to bring us back to a shared baseline. Here is process.env:

    >process.env
    ={
      VERSION: "2v04.378",
      GIT_COMMIT: "ca6e4731",
      BOARD: "ESPRUINOWIFI",
      FLASH: 524288, STORAGE: 65536, RAM: 131072,
      SERIAL: "41006e00-0b513532-39333638",
      CONSOLE: "USB",
      MODULES: "Flash,Storage,hea" ... ",neopixel,Wifi,AT",
      EXPTR: 536871212 }
    

    Here is the code - including the state checking:

    pinMode(A0, 'input_pulldown');
    
    function onInit() {
      A13.read();
    }
    
    function doStuff() {  
        console.log("doing stuff");
        setTimeout(function(){       
          console.log("Going to sleep again");
          setDeepSleep(1);
        }, 2000);
    }
    
    setSleepIndicator(LED1);
    
    setWatch(function() {  
       console.log("A0 pressed");
       doStuff();  
    }, A0, {repeat: true, edge: 'rising', debounce: 10});
    
    
    console.log("A0 = ",getPinMode(A0));
    console.log("A1 = ",getPinMode(A1));
    console.log("A4 = ",getPinMode(A4));
    console.log("A5 = ",getPinMode(A5));
    console.log("A6 = ",getPinMode(A6));
    console.log("A7 = ",getPinMode(A7));
    console.log("B0 = ",getPinMode(B0));
    console.log("B1 = ",getPinMode(B1));
    console.log("B3 = ",getPinMode(B3));
    console.log("B4 = ",getPinMode(B4));
    console.log("B5 = ",getPinMode(B5));
    console.log("B6 = ",getPinMode(B6));
    console.log("B7 = ",getPinMode(B7));
    console.log("B8 = ",getPinMode(B8));
    console.log("B9 = ",getPinMode(B9));
    console.log("B10 = ",getPinMode(B10));
    console.log("B13 = ",getPinMode(B13));
    console.log("B14 = ",getPinMode(B14));
    
    console.log("Going to sleep");
    setDeepSleep(1);
    

    Here is the console output:

    >A0 =  input_pulldown
    A1 =  analog
    A4 =  analog
    A5 =  analog
    A6 =  analog
    A7 =  analog
    B0 =  analog
    B1 =  analog
    B3 =  analog
    B4 =  analog
    B5 =  analog
    B6 =  af_output
    B7 =  af_output
    B8 =  analog
    B9 =  analog
    B10 =  analog
    B13 =  analog
    B14 =  analog
    Going to sleep
    >save()
    =undefined
    Compacting Flash...
    Calculating Size...
    Writing..
    Compressed 114368 bytes to 4919
    Running onInit()...
    

    Here is the dump - after reset, upload, save and then reset:

    >dump()
    function onInit() {A13.read();}
    function doStuff() {
      console.log("doing stuff");
        setTimeout(function(){
          console.log("Going to sleep again");
          setDeepSleep(1);
        }, 2000);
    }
    setWatch(function () {
      console.log("A0 pressed");
       doStuff();
    }, A0, { repeat:true, edge:'rising', debounce : 9.99927520751 });
    setSleepIndicator(B2);
    E.setFlags({ "deepSleep": 1, "pretokenise": 0, "unsafeFlash": 0, "unsyncFiles": 0 });
    pinMode(A0, "input_pulldown");
    digitalWrite(B2, 1);
    =undefined
    
    

    And here is the power consumption: 2.4 mA again.

    I'd certainly welcome any ideas.

  • Okay - so I tried a different tack. I had it do what I ultimately wanted it to do - wake on button, turn on wifi, send a GET request, turn off wifi and go to sleep. I had hoped to send the battery voltage with the GET request, but it looks like E.getBattery is only for the Pico.

    Is there a way to read the battery voltage level?

    I saved the code given below, and checked the power consumption - and low and behold - it appears to sleep at 0.64 mA !

    I am using a LiPo 3.7V 500mAh battery. I have it wired to the + and - terminal. Should I wire it to the 3.3V instead and skip the power regulator to possibly save power (hopefully without nuking the chip).

    I'm also ordering more Espruino's from Adafruit, as this is getting very exciting!

    Thanks,
    Narath

    
    var wifi = require("Wifi");
    var http = require("http");
    
    pinMode(A0, 'input_pulldown');
    
    var webhook_url = "WEBHOOK URL HERE";
    
    function wifiOff() {
      console.log("Trying to turn wifi off");
      wifi.disconnect();
      A13.read();
    }
    
    function wifiOn(callback) {
      console.log("Trying to turn wifi ON");
      wifi.connect("WIFI", {"password": "PASSWORD"},
                   function(ap){ 
        console.log("connected");
        callback();
      });
    }
    
    function get(url, done){
      console.log("GET");
      http.get(url, function(res) {
        res.on('data', function(data) {
          console.log("HTTP> "+data);
        });
        res.on('close', function(data) {
          console.log("Connection closed");
          done(data);
        });
      });
    }
    
    function onInit() {
      wifiOff();
    }
    
    setSleepIndicator(LED1);
    
    function doneClick(data) {
      console.log("Done! Go to sleep");
      wifiOff();
      setDeepSleep(1);
    }
    
    function sendClick() {
      console.log("Trying to connect");
      wifiOn(function(){
        get(webhook_url, doneClick);
      });
    }
    
    setWatch(function() {  
      sendClick();
    }, A0, {repeat: true, edge: 'rising', debounce: 10});
    
    setDeepSleep(1);
    
  • Nope, do NOT connect battery to 3.3V terminal... if the battery is really full - up to 4.2V - it puts too much stress on the mc, which has a limit of 3.6... neither STM nor ESP may survive... A good, low drop, low loss voltage regulator is the answer.

  • Thr 2020.03.05

    'I am using a LiPo 3.7V 500mAh battery. I have it wired to the + and - terminal. Should I wire it to the 3.3V instead and skip the power regulator to possibly save power (hopefully without nuking the chip).'

    I'll defer to @Gordon for the designer recommendation.

    LiPo and Lion have a tendancy to allow for a higher voltage when fully charged. I don't know if All the external parts have the same non 3V3 rating tolerance, protected by the regulator.

    IMO I wouldn't risk a $40 board without a definitive response from the designer, but what about a Buck 3V7 to 3V3 down converter? (I've orderd parts to make some test circuit current comparisons but the Corvid-19 has most of that delayed right now)


    '3.3 is a 3.3v output from the on-board Voltage regulator'

    The pin adjacent to B3 is an output.

    Note 'On-board 3.3v 250mA voltage regulator, accepts voltages from 3.5v to 5v' at:

    http://www.espruino.com/WiFi

    The schematic implies connections at VDD are 3V3

    https://github.com/espruino/EspruinoBoar­d/blob/master/WiFi/pdf/espruino_wifi_sch­.pdf


    'it appears to sleep at 0.64 mA'

    Your 0.64 vs 0.05

    'Current draw in sleep: < 0.05mA - over 2.5 years on a 2500mAh battery'
    http://www.espruino.com/WiFi

    Maybe time for that (0.05) test to be re-visited? or at least what the setup was then



    An Interesting read - regulator power consumption:

    Pixl and MDBT42Q deep sleep power figures?

    Post #15 thru post #17 answers the statement on floating pins I posed earlier in post #29 but for nRF devices and not STM devices, so not sure it would apply here with WiFi.

  • Ok, great - glad you're getting there! 0.64mA is still more than I'd expect though...

    Should I wire it to the 3.3V instead

    As others have said, please don't try that :) The Espruino WiFi actually has a pretty decent voltage regulator on board - the quiescent current (that drawn by the regulator) is something in the range of 0.002mA so there are definitely other issues :)

    Is there a way to read the battery voltage level?

    Not directly, since the battery voltage is never connected to the MCU. You can use E.getAnalogVRef() to get the MCU voltage, which will sit at 3.3v until the LiPo voltage drops below 3.4v(ish). If you google lipo discharge curve you'll see it's at about 98% discharged by that point.

    If you want to get a proper reading you'd need to set up a potential divider (maybe 2x 100k resistors) to halve the battery voltage, then put that into an ADC pin (with a small capacitor between it and GND to help keep the voltage constant) and read the value.

    Maybe time for that (0.05) test to be re-visited? or at least what the setup was then

    As I mentioned above, I actually ran the code and got this figure with up to date firmwares just a few days ago.

  • Thanks @Robin and @Gordon.

    I will stay away from connecting to 3.3V

    I will try E.getAnalogVRef() and if not enough warning will setup the divided resistors.

    Best,
    Narath

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino Wifi Power Consumption in Deep Sleep at 2mA

Posted by Avatar for narath @narath

Actions