Avatar for asez73


Member since Oct 2014 • Last active May 2022
  • 10 conversations

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

Most recent activity

  • in Porting to new Devices
    Avatar for asez73

    Hi @Gordon, how about a new generation of Espruino boards based on NRF52840? More ram, flash and ultra low powerwith ble integrated... šŸ˜Ž

  • in JavaScript
    Avatar for asez73

    Hi all,

    Just as an example, I am doing that sort of things with a ublox sam-m8q gps using their binary protocol.
    The example below is for the paragraph 31.18.20 UBX-NAV-STATUS (0x01 0x03).
    Their messages are pure packed c struct with properly aligned words, dwords and so on and most of those have a fixed length. That was designed for C, C++ definitely.

    However, I am not using an array, just a buffer containing a single data packet.

    I would store more than one in an Array (javascript standard) of ArrayBuffer(s) and then getters or setters with this kind of Dataview code, not pre splitted buffers with their contents separated. Thats may be slower but it's memory savy.

    gps.Status = function() {
          if (this[0x0103]===undefined) return undefined;
          let d=new DataView(this[0x0103].buffer);
          return {
              iTOW: d.getUint32(6, true)/1000,
              gpsFix: d.getUint8(10, true), 
              flags: d.getUint8(5+6, true),
              fixStat: d.getUint8(6+6, true),
              flags2: d.getUint8(7+6, true),
              ttff: d.getUint32(8+6, true)/1000,
              msss: d.getUint32(12+6, true)/1000, 
              receivedAt : new Date(this.receivedAt[0x0103]*1000)
  • in Pico / Wifi / Original Espruino
    Avatar for asez73


    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() {
    function onInit() {
    var idOnTimeWatch=setWatch(function (e) {
    }, onPin, { repeat:true, edge:'falling' });
    var idBusyTimeWatch=setWatch(function (e) {
    }, busyPin, { repeat:true, edge:'falling' });
    var idDeepSleepTimeWatch=setWatch(function (e) {
    }, onPin, { repeat:true, edge:'rising' });
  • in News
    Avatar for asez73

    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


    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


    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) {
    }, 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)