Thankyou @mtnscott, that worked well in the Web IDE, I had to delete:
#include "application.h"
and add:
#include <math.h>
to get it to compile. It ran reliably and gave the same temperature as my digital thermometer.
Now I am going to compare with my port and work out what I got wrong!
By the way, did you notice _us which is used to store microseconds is an int, where as according to the definition of micros() is should be unsigned long?
Yeah thatâs another way to do it, you are just changing the default initialization of the constructor. Not really proper, but if itâs just for you then it will work just fine!
@Yasin all i did was copy @wgbartley 's code and add some Spark.variable() hooks so you could make REST GET requests for the info as strings. Iâm not sure what could be wrong so hopefully someone else with a DHT22 can chime in and offer a look at the code. CC: @mtnscott, @PaulRB
@PaulRB So⌠It all works. But I get quite wide variations with temperature⌠ranging 3-4 degrees Celsius with every reading. Humidity is fairly constant. I noticed you dropped a 4.7kohm resistor on the data line. Is this necessary? A lot of schematics Iâve seen for this donât include it. Does it need to be a 4.7kohm?
BDub & @Dom , Iâm a bit confused. The DHTxx sensors donât actually used the I2C protocol and work using a user-defined digital pin for communicating. What does this have to do with SCA and SCL? The DHTxx do NOT have a pull-up built in and it is usually recommended that one be added between VCC and GND, at the sensor, somewhat like you suggest.
I have had varying success with running DHT22 sensors at 3.3V versus 5v, with some not working at all. One a teensy 3, I have a DHT22 (aka RHT03) running at 3.3V with no pull-up just fine. One factor that I find affects is noise and the capacitor you recommend is a great idea. Another is keeping the connections between the DHTxx and the input pins short and making sure the ground bus is good. A larger cap (> 10uF electrolytic) between the VCC and GND on the prototype board may also help.