Avatar for Frida

Frida

Member since Sep 2013 • Last active Dec 2019
  • 24 conversations
  • 192 comments

Most recent activity

  • in ESP8266
    Avatar for Frida

    Are you a spammer?
    Page show only facebook.

  • in ESP32
    Avatar for Frida

    Just a thought! Have you set the 'udev' rules for ESP32?

  • in ESP32
    Avatar for Frida

    Ok, time to bring the toys back.
    With this test I have set a LED to pin, active low.

    First test.

    function tt () {
      ht = {};
      //ht.pin = D0; // esp8266
      ht.pin = D12; // esp32 pico4
    
      setInterval (function () {
        var d = "";
        ta = getTime ();
        tb = 0;
    
        pinMode (ht.pin, 'opendrain');
    
        ht.watch = setWatch (function (t) {
          d = 0 + | (t.time-t.lastTime> 0.000050); // 50 usec (time in sec)
        }, ht.pin, {edge: 'falling', repeat: true});
    
        //pinMode(ht.pin, 'opendrain');
    
        setTimeout (function () {
          pinMode (ht.pin, 'input_pullup');
          tb = getTime ();
          console.log (tb-ta);
        }, 1000);
    
        setTimeout (function () {
          Clear watch (ht.watch);
          console.log ('d =' + d);
          console.log (process.memory ());
        }, 200);
    
    
      }, 3000);
    }
    
    TT ();
    
    

     
    It only gives me short pulses, and not for 1 second, as expected.
    If I remove clearWatch (ht.watch), I get a short pulse, then full pulse length and it uses all the memory.

    On esp8266 there are no problems.

    Next test.

    function tt () {
      ht = {};
      //ht.pin = D0; // esp8266
      ht.pin = D12; // esp32 pico4
    
      setInterval (function () {
        var d = "";
        ta = getTime ();
        tb = 0;
    
        //pinMode(ht.pin, 'opendrain');
    
        ht.watch = setWatch (function (t) {
          d = 0 + | (t.time-t.lastTime> 0.000050); // 50 usec (time in sec)
        }, ht.pin, {edge: 'falling', repeat: true});
    
        pinMode (ht.pin, 'opendrain');
    
        setTimeout (function () {
          pinMode (ht.pin, 'input_pullup');
          tb = getTime ();
          console.log (tb-ta);
        }, 1000);
    
        setTimeout (function () {
          Clear watch (ht.watch);
          console.log ('d =' + d);
          console.log (process.memory ());
        }, 200);
    
    
      }, 3000);
    }
    
    TT ();
    
    

    Here pinMode has been moved to after set_Watch and I can determine pulse length on LED.
    Also works on esp8266.

    And now for a workaround, so it works on both esp8266 and esp32 pico4 as I have.

    Hope this is something you can use?

    // testWatch02
    
    function DHT22 (pin) {
      this.pin = pin;
    }
    
    DHT22.prototype.read = function (cb, n) {
      if (! n) n = 10;
      var d = "";
      var ht = this;
    
      // start watching for state change
      ht.watch = setWatch (function (t) {
        d = 0 + | (t.time-t.lastTime> 0.00005);
      }, ht.pin, {edge: 'falling', repeat: true});
    
      pinMode (ht.pin, 'opendrain'); // PB obs It sets the output low immediately
    
      // raise pulse after 10ms
      setTimeout (function () {pinMode (ht.pin, 'input_pullup'); pinMode (ht.pin);}, 10);
    
      // stop looking after 100ms
      setTimeout (function () {
        if (ht.watch) {ht.watch = clearWatch (ht.watch); }
    
    d = d.substr (1); // PB you are a genius
        var cks =
            parseInt (d.substr (2.8) 2) +
            parseInt (d.substr (10.8), 2) +
            parseInt (d.substr (18.8), 2) +
            parseInt (d.substr (26.8), 2);
        if (cks && (((cks & 0xFF) == parseInt (d.substr (34.8), 2))) {
          cb ({
            raw: d,
            rh: parseInt (d.substr (2.16), 2) * 0.1,
            temp: parseInt (d.substr. (19.15), 2) * 0.2 * (0.5-d [18])
          });
        } else {
          if (n> 1) setTimeout (function () {ht.read (cb, - n);}, 500);
          // else cb ({err: true, checksumError: cks> 0, raw: d, temp: -1, rh: -1});
          else cb ({err: true, checksumError: cks> 0, raw: d, temp: -1, rh: -1, n: n});
        }
      }, 100);
    };
    
    DHT22.prototype.getName = function () {
    return 'Frida';
    };
    / *
    exports.connect = function (pin) {
        return new DHT22 (pin);
    };
    * /
    
    
    function dd () {
      esp = 0;
      if (esp) {
        pin = D0; // esp8266
        // esp8266 version 2v00.68 (c) 2018 G.Williams
        var ESP8266 = require ('ESP8266');
        ESP8266.setCPUFreq (80);
        console.log (ESP8266.getState ());
      } else {
        pin = D12; // esp32 pico4
        // esp32 pico4 version 2v02 (c) 2018 G.Williams
        console.log (ESP32.getState ());
      }
    
    // var dht = require ("DHT22a"). connect (pin);
      var dht = new DHT22 (pin);
    
      console.log (dht.getName ());
    
      setInterval (function () {
    
        dht.read (function (a) {
          console.log ("Temp is" + a.temp.toFixed (1) .toString () +
                      ", RH is" + a.rh.toFixed (1) .toString () +
                      "\ Nraw:" + a.raw +
                      "\ nn:" + a.n +
                      "\ Nerr:" + a.err +
                      ", cse:" + a.checksumError);},
                 1);
    
        setTimeout (function () {
          console.log ("E-Flags: [" + E.getErrorFlags () + "] \ n \ n");},
                   1000);
    
      }, 3000);
    
    }
    
    
    dd ();
    
    // save ();
    

    And some outputs.

    Temp is 35.1, RH is 92.3
    raw:010000001110011011000000010101111111­111110
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 92.4
    raw:010000001110011100000000010101111111­111111
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 92.5
    raw:010000001110011101000000010101111100­000000
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 92.6
    raw:010000001110011110000000010101111100­000001
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 92.7
    raw:010000001110011111000000010101111100­000010
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 92.8
    raw:010000001110100000000000010101111100­000011
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 92.9
    raw:010000001110100001000000010101111100­000100
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 93.0
    raw:010000001110100010000000010101111100­000101
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 93.1
    raw:010000001110100011000000010101111100­000110
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    Temp is 35.1, RH is 93.2
    raw:010000001110100100000000010101111100­000111
    n: undefined
    err:undefined, cse:undefined
    E-Flags: []
    
    

    Happy coding.

  • in ESP32
    Avatar for Frida

    Have you tried putting all unused pins to output?

  • in Other Boards
    Avatar for Frida
                       case 4: {
                            // temp
                            temp = (data[14] | data[15] << 8) / 10;
                            break;
                        }
                        case 6: {
                            // humidity
                            humidity = (data[14] | data[15] << 8) / 10;
                            break;
                        }
    

    You use the same dataset for both temp and humidity, is it correct?

  • in ESP8266
    Avatar for Frida

    I'm using version 2v00.17 on my Sonoff.
    Have downloaded espruino_2v00.17_esp8266.tgz.
    esptool.py --port /dev/ttyUSB0 erase_flash
    cleans sonoff,
    and

    root=$(pwd)/espruino_2v00.17_esp8266
    esptool.py --port /dev/ttyUSB0 --baud 230400 write_flash \
      --flash_freq 40m --flash_mode qio --flash_size 512KB \
      0x00000 $ root/boot_v1.6.bin \
      0x01000 $ root/espruino_esp8266_user1.bin \
      0x7C000 $ root/esp_init_data_default.bin \
      0x7E000 $ root/blank.bin
    installs on Sonoff.

    > Reset ();
    = undefined
      ____ _
    | __ | ___ ___ ___ _ _ | _ | ___ ___
    | __ | _ - | . | _ | | | | | . |
    | ____ | ___ | _ | _ | | ___ | _ | _ | _ | ___ |
              | _ | espruino.com
      2v00.17 (c) 2018 G.Williams
    Espruino is open source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash folder 512KB: 256/256, manuf 0xe0 chip 0x4014
    >
    
  • in ESP8266
    Avatar for Frida

    It is not only 'ESP8266', 'PICO' also has problems.

  • in ESP8266
    Avatar for Frida

    Some tests:

    Serial2.setup(9600,{});
    
    
    ERROR: *** PB *** baudRate = 9600
    ERROR: *** PB *** pinRX = 255
    ERROR: *** PB *** pinTX = 255
    ERROR: *** PB *** pinCK = 255
    ERROR: *** PB *** pinCTS = 255
    ERROR: *** PB *** bytesize = 8
    ERROR: *** PB *** PB0 = 11
    ERROR: *** PB *** PB1 = 22
    ERROR: *** PB *** PB2 = 33
    ERROR: *** PB *** parity = 0
    ERROR: *** PB *** stopbits = 1
    ERROR: *** PB *** PB3 = 44
    ERROR: *** PB *** PB4 = 55
    ERROR: *** PB *** PB5 = 66
    {  }
    

    By default setup, PB0, PB1 and PB2 are not touched.

    Serial2.setup(9600,{bytesize:7});
    
    ERROR: *** PB *** baudRate = 9600
    ERROR: *** PB *** pinRX = 255
    ERROR: *** PB *** pinTX = 255
    ERROR: *** PB *** pinCK = 255
    ERROR: *** PB *** pinCTS = 255
    ERROR: *** PB *** bytesize = 7
    ERROR: *** PB *** PB0 = 0
    ERROR: *** PB *** PB1 = 0
    ERROR: *** PB *** PB2 = 0
    ERROR: *** PB *** parity = 0
    ERROR: *** PB *** stopbits = 1
    ERROR: *** PB *** PB3 = 44
    ERROR: *** PB *** PB4 = 55
    ERROR: *** PB *** PB5 = 66
    { "bytesize": 7 }
    

    With this setup, PB0, PB1 and PB2 are overwritten.

    typedef struct {
      int baudRate;            /// FIXME uint32_t ???
      Pin pinRX;
      Pin pinTX;
      Pin pinCK;               ///< Clock, or PIN_UNDEFINED
      Pin pinCTS;              ///< Clear to send, or PIN_UNDEFINED
      unsigned char bytesize;  ///< size of byte, 7 or 8
      uint8_t PB0;              // insert PB
      uint8_t PB1;              // insert PB
      uint8_t PB2;              // insert PB
      unsigned char parity;    ///< 0=none, 1=odd, 2=even
      unsigned char stopbits;  ///< 1 or 2
      uint8_t PB3;              // insert PB
      uint8_t PB4;              // insert PB
      uint8_t PB5;              // insert PB
      bool xOnXOff;            ///< XON XOFF flow control?
      bool errorHandling;      ///< Whether to forward parity/framing errors
    } PACKED_FLAGS JshUSARTInfo;
    
    

    In the file 'jsserial.c' and in the function 'jsserialPopulateUSARTInfo' there are:

      jsvConfigObject configs[] = {
          {"rx", JSV_PIN, &inf->pinRX},
          {"tx", JSV_PIN, &inf->pinTX},
          {"ck", JSV_PIN, &inf->pinCK},
          {"cts", JSV_PIN, &inf->pinCTS},
          {"bytesize", JSV_INTEGER, &inf->bytesize},
          {"stopbits", JSV_INTEGER, &inf->stopbits},
    

    I do not know what it's doing, but it returns 4 bytes for 'bytesize' and 'stopbits', like 32 bits, but in 'JshUSARTInfo' they are set up as 'chars'

    That is, 'bytesize' overwrites 'parity, stopbits and xOnXOff'.

    It's worse with 'stopbits' because it will overwrite 'xOnXOff' and 'errorHandling' as well as write in an illegal address.

    Maybe we could get a 'JSV_CHAR' to these two.

    If I'm taking a'PICO 'and using:

    Serial2.setup(9600,{});
    
    No errors. Minified 2163 bytes to 70 bytes.
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v00 (c) 2018 G.Williams
    >{  }
    

    There's nothing going on.

    
    Serial2.setup(9600,{bytesize:8});
    
    
    No errors. Minified 2173 bytes to 80 bytes.
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v00 (c) 2018 G.Williams
    >Uncaught InternalError: Unsupported serial stopbits length.
     at line 1 col 32
    ...al2.setup(9600,{bytesize:8}),console.­log(Serial2._options),c...
                                  ^
    > 
    

    Which shows that stopbits are overwritten by 0.

    Hope it is understandable.

Actions