I have successfully gotten the DHT22 to work on my Photon, but for both the Xenon & Argon it always return zeros.
I’ve identified from forum postings the #include statement needs to be changed and there is a fix best retrieved by using piettetech_dht and ensuring it has the January 2019 update. Both are true.
I am sending the data via the .publish to ThinkSpeak (not using serial as in the examples if that makes a difference) and I’ve tried float, int & double declarations for the variables.
The DHT22 definitely works with Xenon - I have tried the sensor myself. Could you share how you are connecting it and the simple code just to get temperature and humidity from the sensor?
This is the code. (cannibalized from another post). Beyond confirming I have the January 2019 version of PietteTech_DHT.h, I’ve added delays between reads. The voltage displays with correct data, the other two are always zero. When I run it on the photon (battery commented out) observations start up after a cycle or two.
// This #include statement was automatically added by the Particle IDE.
#include <PietteTech_DHT.h>
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22
PietteTech_DHT(DHTPIN, DHTTYPE);
SYSTEM_MODE(AUTOMATIC);
void setup() {
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a
// very slow sensor)
delayMicroseconds(40);
double DHT_temp = dht.getTempFarenheit();
delayMicroseconds(40);
double DHT_humid = dht.getHumidity();
// Now we'll take some readings...
//Temperature
int temperature_analog = DHT_temp; // read DHT sensor
float temperature_percentage = (10 + ( (temperature_analog/50) ) );
//Humidity
int humidity_analog = DHT_humid; // read DHT sensor
float humidity_percentage = (10 + ( (humidity_analog/50) ) );
//Battery Life
if(BATT){
float voltage = analogRead(BATT) * 0.0011224;
Particle.publish("voltage", String(voltage),60,PUBLIC);
// Send a publish devices...
delay(4000);
Particle.publish("DHT_temperature", String(temperature_analog),60,PUBLIC);
// Particle.publish("DHT_temp_percentage", String(temperature_percentage),60,PUBLIC);
delay(4000);
Particle.publish("DHT_humidity", String(humidity_analog),60,PUBLIC);
// Particle.publish("DHT_humid_percentage", String(humidity_percentage),60,PUBLIC);
}
I just looked at this and it was the Seeed_DHT11 library as I was using the DHT11 supplied in the Grove Starter Kit for Particle Mesh and not the DHT22. Sorry to mislead. I had a look at the application I used for the Photon and that was PIETTETECH_DHT library. I just tried the @Moors7 BLE example with a Xenon - DHT11 reading which appears to have a 1 in 3 read failure - BLE works fine!