Avatar for asez73

asez73

Member since Oct 2014 • Last active Mar 2019
  • 10 conversations
  • 172 comments

I have an Espruino board 1v4 and a Kickstarter Pico board...

Most recent activity

  • in Pico / Wifi / Original Espruino
    Avatar for asez73

    Hi,

    So I connected a Pico to an Original Espruino and tried to monitor the Original Espruino from the Pico.
    So far, I ended up with results only for busy indicator as I am running the original espruino board from USB connection so there is no deep sleep available yet.

    The code on the Originla Espruino just includes

      setBusyIndicator(LED1); // A13
      setSleepIndicator(LED2);  // A14
    

    The code on the Pico is

    /*
                  Measure time spent on LED1/LED2 by an original Espuino board
                  */
    
    var onPin=B10; // Non deep sleep (1===running or simple sleep) led from Original Espruino Board
    var onTime=0;
    var busyPin=B13; // Busy (1=== running, neither simple sleep, nor deep sleep) led from Original Espruino Board
    var busyTime=0;
    var deepSleepTime=0;
    var startedAt=getTime();
    
    function log() {
      let runningFor=getTime()-startedAt;
      console.log("Running for",runningFor,"s");
      console.log("On time (Busy + Sleep)",onTime,"s",Math.floor(onTime*100­0/runningFor)/10,"%\tbusyTime (Busy)",busyTime,"s",Math.floor(busyTime­*1000/runningFor)/10,"%\tdeepSleepTime",­deepSleepTime,"s",Math.floor(deepSleepTi­me*1000/runningFor)/10,"%");
    }
    
    function resetChronos() {
      onPin=B10;
      onTime=0;
      OLED2=B13;
      busyTime=0;
      deepSleepTime=0;
      startedAt=getTime();
    }
    
    function onInit() {
      resetChronos();
      log();
    }
    
    var idOnTimeWatch=setWatch(function (e) {
      onTime+=e.time-e.lastTime;
    }, onPin, { repeat:true, edge:'falling' });
    
    var idBusyTimeWatch=setWatch(function (e) {
      busyTime+=e.time-e.lastTime;
      log();
    }, busyPin, { repeat:true, edge:'falling' });
    
    var idDeepSleepTimeWatch=setWatch(function (e) {
      deepSleepTime+=e.time-e.lastTime;
      log();
    }, onPin, { repeat:true, edge:'rising' });
    
    
    
  • in News
    Avatar for asez73

    Hi,
    Just to mention that the schematics show 100 ohms resistor in series with each led.
    So, in your test 3, 20 ms on every 5000 ms should give us: 20 ms / 5000 ms*(3.3v-voltage drop of led) / 100 ohm.
    If we assume a voltage drop of 0,7v we get 0.104 mA for lighting the sole led1 20'ms every 5000 ms.
    That said, the way you connect your battery could keep usb drivers awaken and trying to detect some data connection. This is just an hypothesis 🤔

    I am very interested with this kind of problem too... Keep us informed of your results 😓

  • in Pico / Wifi / Original Espruino
    Avatar for asez73

    Well, in some cases, at wake up some data can be lost due to the time it takes to re setup the peripherals links (usarts, spi...). That's from deep sleep.

  • in Pico / Wifi / Original Espruino
    Avatar for asez73

    Hi,

    The title says it all: Is there any hope to get, at run time, the various instants at which all the run/sleep/deep sleep modes were entered by the interpreter? Cumulated times spents in each mode would be a way to quantify easily the power consumption...

    Ok, (re) found setBusyIndicator which should show when running and not sleeping: I have to test that...

    Aside of time measurements, it would also give an idea of the eventuals problems of lost data when getting out of deep sleep mode.

    Thanks for your attention.

  • in JavaScript
    Avatar for asez73

    However, Espruino is designed to run on very low level mcu's and it doesn't claim any real compatibility with nodejs or other standards.
    You should search this forum about that and read the reference rather than other sites.

    Maybe the Tessel board would suit you better?

  • in JavaScript
    Avatar for asez73

    Hi,

    Reading your question more carefully, your problem is the value of this in the setInterval, probably the global context which is not what you want.
    This can be resolved by sending the right context object for this as an added last argument in setInterval or seTimeout as below.

    ...
    var timeoutID = setTimeout(function (self) {
      console.log(self); 
    }, 500, this);
    ...
    

    So, your object, instance of class, will be called self in the setInterval/SetTimeout at execution time...

    You should look at the reference of setInterval and this non Espruino thread or this other one

  • in JavaScript
    Avatar for asez73

    Yes, I agree that your solution .getTime() seems to be the sole safe solution...
    Thank's again for your reactivity.

    There is no such thing as an uncoherent choice: But that's javascript standards... :)

    1. E.setTimezone takes hours,
    2. new Date().getTimezoneOffset() gives signed minutes,
    3. new Date().getTime() gives ms,
    4. *monthes are 0 based*


    I had dreamed, apparently, to just add the new Date().getTimezone() minutes to the minute parameter of new Date(..., minute, ...) rather than convert everything to ms since 1970, just for simple straight readability.

    To explain a bit more what makes me wondering so much: I get the gps time as 6 bytes in UTC time from ublox M8 binary protocol UBX-NAV-PVT or UBX-NVA-TIMEUTC for instance.
    Here is an excerpt of my code, (this[289].buffer is Uint8Array containing exactly the ublox binary packet (absolutly the all of it, header and checksum included) and d the DataView on it.
    The hidden magic trick here, is that if E.setTimezone(1) is system wide used, the UTC time will be wrong as it is so biaised and you can't see that reading the code: You have to be aware.

      var posGps= {
    ...
    
    get TIMEUTC() {
        if (this[289]===undefined) return undefined;
        let d=new DataView(this[289].buffer);
        return {
          iTOW: d.getUint32(6, true)/1000,
          tAcc: d.getUint32(6+4, true)/1e9,
          nano: d.getInt32(6+8, true)/1e9,
          dateUTC : new Date(d.getUint16(12+6, true), d.getUint8(14+6, true)-1, d.getUint8(15+6, true), d.getUint8(16+6, true), d.getUint8(17+6, true), d.getUint8(18+6, true)),
          valid: d.getUint8(6+19, true),
          receivedAt : new Date(this.receivedAt[289]*1000)
        };
      },
    ...
    }
    
  • in JavaScript
    Avatar for asez73

    Hi @Gordon,
    I am playing with time zones vs UTC & GMT those days and found this to be a problem:

    new Date().getTimezoneOffset()
    =-60
    >new Date(2019,1,7,10,34-60,19,0)
    =Date: Thu Feb 7 2019 09:34:19 GMT+0100
    >new Date(2019,1,7,9,34+60,19,0)
    =Date: Thu Feb 7 2019 09:34:19 GMT+0100
    >new Date(2019,1,7,8,49+60,19,0)
    =Date: Thu Feb 7 2019 08:49:19 GMT+0100
    >new Date(2019,1,7,0,34-60,19,0)
    =Date: Wed Feb 6 2019 23:34:19 GMT+0100
    >new Date(2019,1,7,0,34+60,19,0)
    =Date: Thu Feb 7 2019 00:34:19 GMT+0100
    

    So, if I use a negative minute, the hour will be correctly handled while using an over 60 minutes minute parameter will not increment the hour....

    This all about gps providing UTC time while I have to handle local day time and winter / summer changes. Beeing in continental Europe, I have an approximative approach (not world wide) which gave me the following functions to get summer / winter day light savings:

    // https://www.calendrier-365.fr/heure-d-et­e-heure-d-hiver.html
    
    function jourFinHiver(annee) { // last sunday of march
      return Math.floor(31.8 - ((((5 * annee) / 4) + 4) % 7));
    }
    
    function jourFinEte(annee) { // last sunday of october
      return Math.floor(31.8 - ((((5 * annee) / 4) + 1) % 7));
    }
    
    function hiver() {
      today= new Date();
      month=1+today.getMonth(); // so 1 based
      if ([1,2,11,12].indexOf(month)>=0) return true;
      if (month===3) return today.getDay() < jourFinHiver(today.getFullYear()); // TDB take care of first hours of day which is still in winter
      if (month===10) return today.getDay() >= jourFinEte(today.getFullYear()); // TDB take care of first hours of day which is still in summer
      return true;
    }
    
    // Set the system time zone in agreement with Uk & Europe day ligth savings (aka winter / summer time) UTCwinterToGMT = 0 for UK, 1 for France/Benelux/Germany...
    function setTimeZone(UTCwinterToGMT) {
      E.setTimeZone(UTCwinterToGMT + (hiver() ? 0 : 1));
    }
    
    // Only valid in Europe (UTC winter to GMT=+1) and UK (UTC winter to GMT = 0)
    function localDayTimeHour(UTCwinterToGMT) { // valid for UTC+1-UTC+2 in continental Europe
      setTimeZone(UTCwinterToGMT); // Handle time zone at system level
      return (new Date().getHours() ) % 24;
    }
    
    

    So references above are in french... Which is fine for me :)

  • in Puck.js, Pixl.js and MDBT42
    Avatar for asez73

    Just to get a bit deeper: should the button beeing waited for be a pull-up or a pull-down? At this level of power consumption, any leakage is costly.

Actions