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'+'0000001010001100000000010101111111101110'; // rh=65.2 t= 35.1
//d='00'+'0000001010001100100000000110010101110011'; // rh=65.2 t=-10.1
//d='00'+'0000001010001100000000000110010111110011'; // 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[18]); // 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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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.
TVE's firmware downloaded today and used in the test.