Found a solution changed 6 to 60 on the outer setInterval of the module
var dpin=B3;
var F;
var H;
function DHT22(pin) {
this.pin = pin;
}
DHT22.prototype.read = function (cb, n) {
if (!n) n=10;
var d = "";
var ht = this;
pinMode(ht.pin); // set pin state to automatic
digitalWrite(ht.pin,0);
// digitalWrite([ht.pin,ht.pin,ht.pin,ht.pin,ht.pin],0x0a);
this.watch = setWatch(function(t) {
d+=0|(t.time-t.lastTime>0.00005);
}, ht.pin, {edge:'falling',repeat:true} );
setTimeout(function() {pinMode(ht.pin,'input_pullup');},1);
setTimeout(function() {
clearWatch(ht.watch);
delete ht.watch;
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);
console.log(n,d.length,cks&0xFF,parseInt(d.substr(34,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});
}
},60); //////Changed value to 60 from 6
};
//var dht = require("DHT22").connect(dpin);
var dht=new DHT22(dpin);
setInterval(function () {
dht.read(function (a) {
F=(a.temp+40)*9/5-40;
H=a.rh;
console.log("Temp is "+F.toString()+" and RH is "+H.toString());
});
// });
}, 1000);
Sample output Temperature in F.
>echo(0);
=undefined
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
10 42 164 164
Temp is 71.96 and RH is 45.3
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.
Found a solution changed 6 to 60 on the outer setInterval of the module
Sample output Temperature in F.