You are reading a single comment by @Frida and its replies. Click here to read the full conversation.
  • When I saw you have a lot of trouble with DHT22 and the like. I decided to look into it.
    So I took the datablad, and made a simulator in my propeller from Parallax.
    I don't have this sensor, so I don't know if it will work.
    Then I took Gordon's proposals and twisted a bit. See post #1

    My connection between esp8266-01 and propeller are via a resistor of 330ohm, just to be safe.
    I chanced the time from 6ms to 20ms. On my system, if I am under 13 ms I begin to lose pulses.

    Try it and see if it can be used.

    // DHTxx_01 - esp8266-01
    
    // Sensor object constructor
    function HT(device, pin) {
      this.device = device;
      this.pin = pin;
    }
    // sensor query method...
    /** read sensor as either...
          read(callback);
          read(callback,number_of_tries); - default=3
          */
    HT.prototype.read = function (cb,n) {
      if (!n) n=3;
      var d = ""; 
      var ht = this;
      pinMode(ht.pin); // set pin state to automatic
      digitalWrite(ht.pin,0);
      this.watch = setWatch(function(t) {
        d+=0|(t.time-t.lastTime>0.00005); // 030, 070 usec (time in sec) // PB
      }, ht.pin, {edge:'falling',repeat:true} );
      setTimeout(function() {pinMode(ht.pin,'input_pullup');},1); // (time in msec) // PB
      setTimeout(function() {
        clearWatch(ht.watch);
        delete ht.watch;
    	//00+0000 0010 1000 1100 0000 0001 0101 1111 1110 1110
    	//00+0000 0010 1000 1100 1000 0000 0110 0101 0111 0011
    	//   r                   t                   c 
    	//d='00'+'000000101000110000000001010111­1111101110'; // rh=65.2 t= 35.1
    	//d='00'+'000000101000110010000000011001­0101110011'; // rh=65.2 t=-10.1
    	//d='00'+'000000101000110000000000011001­0111110011'; // rh=65.2 t= 10.1
        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))) {
          var o = { raw:d };
          if (ht.device=="DHT11") {
            o.rh = parseInt(d.substr(2,8),2);
            o.t = parseInt(d.substr(18,8),2);
          } else {
            o.rh = parseInt(d.substr(2,16),2)*0.1;
            //o.t = parseInt(d.substr(19,15),2)*0.2*(d[18]-0­.5);
            o.t = parseInt(d.substr(19,15),2)*0.2*(0.5-d[1­8]); // PB
          }
          //cb(o);
          cb({o:o, n:n}); // PB
    
        } else {
          if (n>1) setTimeout(function() {ht.read(cb,--n);},500);
          //else cb({err:true, raw:d});
          else cb({err:true, checksumError:cks>0, raw:d, temp:-1, rh:-1, n:n});
        }
      //},6);
      },20); // time in msec (min 15 virker) 6 20 // PB
    };
    
    
    //*************** start here ******************
    // esp8266
    var ESP8266 = require('ESP8266');
    //ESP8266.setCPUFreq(80);
    console.log(ESP8266.getState());
    
    
    // Test with
    var dht = new HT("DHT22",D0);
    setInterval(function() {
      dht.read(print);
    },3000);
    
    

    TVE's firmware downloaded today and used in the test.

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v85.1127 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 512KB:256/256, manuf 0xc8 chip 0x4013
    >echo(0);
    {
      "sdkVersion": "1.5.3(aec24ac9)",
      "cpuFrequency": 160, "freeHeap": 10296, "maxCon": 10,
      "flashMap": "512KB:256/256",
      "flashKB": 512,
      "flashChip": "0xc8 0x4013"
     }
    =undefined
    {
      "o": {
        "raw": "010000000001001101000000010101111110101­101",
        "rh": 7.7, "t": 35.1 },
      "n": 3 }
    {
      "o": {
        "raw": "010000000001001110000000010101111110101­110",
        "rh": 7.8, "t": 35.1 },
      "n": 3 }
    {
      "o": {
        "raw": "010000000001001111000000010101111110101­111",
        "rh": 7.9, "t": 35.1 },
      "n": 3 }
    {
      "o": {
        "raw": "010000000001010000000000010101111110110­000",
        "rh": 8, "t": 35.1 },
      "n": 3 }
    {
      "o": {
        "raw": "010000000001010001000000010101111110110­001",
        "rh": 8.1, "t": 35.1 },
      "n": 3 }
    {
      "o": {
        "raw": "010000000001010010000000010101111110110­010",
        "rh": 8.2, "t": 35.1 },
      "n": 3 }
    {
      "o": {
        "raw": "010000000001010011000000010101111110110­011",
        "rh": 8.3, "t": 35.1 },
      "n": 3 }
    
    
About

Avatar for Frida @Frida started