Avatar for narath

narath

Member since Feb 2020 • Last active Mar 2020
  • 1 conversations
  • 18 comments

Most recent activity

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    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

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    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);
    
  • in Pico / Wifi / Original Espruino
    Avatar for narath

    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.

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    @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
    
  • in Pico / Wifi / Original Espruino
    Avatar for narath

    @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

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    Hey guys, unfortunately - Gordon was right - without me clearly knowing what I had changed to fix it - it returned to it's previous power consumption. I did get an oscilloscope, but unfortunately no current probe (I have a shunt resistor, but have no differential probe, so have not tried reading it yet). I did get an analog meter as well, and it gets the same power reading.

    @Gordon, here is my current code on the device:

    pinMode(A0, 'input_pulldown');
    A13.read();
    
    setSleepIndicator(LED1);
    
    function doStuff() {
      console.log("doing stuff");
    
      setTimeout(function(){
          console.log("Going to sleep again");
          setDeepSleep(1);
        }, 500);
    }
    
    setWatch(function() {  
      console.log("A0 pressed");
      doStuff();
    }, A0, {repeat: true, edge: 'rising', debounce: 10});
    
    console.log("Going to sleep");
    setDeepSleep(1);
    

    @Robin, seems reasonable to explicitly set the pinmodes: pinMode looks like it can be all of these: analog', 'input', 'input_pullup', 'input_pulldown', 'output', 'opendrain', 'af_output' or 'af_opendrain'.

    These are the pinModes I expect to set, what would you recommend the others be set to:

    pinMode(A0, 'input_pulldown');
    pinMode(A1, 'input_pulldown');
    A13.read();
    

    The pins I expect to set are: A4, A5, A6, A7, B0, B1, B3, B4, B5, B6, B7, B8, B9, B10, B13, B14

    Best,
    Narath

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    I will be getting an oscilloscope this weekend and will do more testing (esp launching wifi and then disconnecting before sleep), but so far this seems very promising. Thank you both for your help.

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    And then when going to sleep got this!! 0.03 mA - in the microAmp category - woot!

  • in Pico / Wifi / Original Espruino
    Avatar for narath

    Okay - I am a believer!

    Great suggestion by @Robin

    Time for a 1% resistor and battery only circuit to prove out the meter will actually read that on the low end? e.g. the meter can actually read below 2uA

    I used a 100K resistor on the battery circuit and verified getting uA readings.

    Then tested the espruino with the A13.read() and got the readings seen below with pressing the button (no wifi, just turns on, then sets sleep mode)

Actions