Photon can no longer read DHT22 Temp Humidity sensor

I revisited my Photon that could read the DHT22 Sensor a while ago (about 2 years ago) Now running the same code it does not read the sensor.

My code did not change and the library “Adafruit_DHT.h” was updated about 3 years ago.

I also tried the example that comes with the library. Same result.

I also tried the sensor with an Arduino and it works fine. (at 3.3v and 5.0v)

Wiring is the same: Pin 1 to 3.3v, pin 2 to D2 with pullup 10k to 3.3v, pin 4 to GND.

Any thoughts what might have changed?

Hi Chaz- Can you share the code you are using on the sensor?

This code does not work because the Library “Adafruit_DHT.h” does not work on the Photon! It used to before, but not now.
Also <Adafruit_DHT_Particle> does not work

I did find that these libraries work: Something changed in the code of the library Adafruit_DHT.

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_Sensor.h>  // not used but required by DHT.h
// This #include statement was automatically added by the Particle IDE.
#include <DHT.h>

My code below, but you can also use the example code that comes with Adafruit_DHT
I am using the DHT22 Sensor as I was before.

#include "Adafruit_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

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11                            // DHT 11 
#define DHTTYPE DHT22                                // DHT 22 (AM2302)
//#define DHTTYPE DHT21                            // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
                Serial.begin(9600); 
                Serial.println("DHTxx test!");

                dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
                delay(5000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a 
// very slow sensor)
                float h = dht.getHumidity();
// Read temperature as Celsius
                float t = dht.getTempCelcius();
// Read temperature as Farenheit
                float f = dht.getTempFarenheit();
  
// Check if any reads failed and exit early (to try again).
                if (isnan(h) || isnan(t) || isnan(f)) {
                                Serial.println("Failed to read from DHT sensor!");
                                Serial.println(h);
                                Serial.println(t);
                                Serial.println(f);
                                return;
                }

// Compute heat index
// Must send in temp in Fahrenheit!
                float hi = dht.getHeatIndex();
                float dp = dht.getDewPoint();
                float k = dht.getTempKelvin();

                Serial.print("Humid: "); 
                Serial.print(h);
                Serial.print("% - ");
                Serial.print("Temp: "); 
                Serial.print(t);
                Serial.print("*C ");
                Serial.print(f);
                Serial.print("*F ");
                Serial.print(k);
                Serial.print("*K - ");
                Serial.print("DewP: ");
                Serial.print(dp);
                Serial.print("*C - ");
                Serial.print("HeatI: ");
                Serial.print(hi);
                Serial.println("*C");
                Serial.println(Time.timeStr());
}

PS: I notice that the libraries that DON’T work with the Photon use this “fastpin” calls. I’m not sure where to find to documentation on “pinSetFast(_pin)” and “pinResetFast(_pin);” ?
Maybe these aren’t good for the Photon?

In any event I did a file compare on DHT.cpp that is used for the arduino and the DHT.cpp that is available in the Particle IDE library and they are identical! That is the one that WORKS for the Photon.

Maybe someone could fix the DHT library code so that it checks the device (Photon / Argon etc.) and uses the code that works for that device???

Right now I am using:
#include <Adafruit_Sensor.h>
#include <DHT.h>

which WORKS for the Photon. Hope this helps others with the same problem.

They would be here

These libraries definitely did work in the past and if they don't anymore due to the use of fast pin manipulation I'd rather have the potentially/allegedly impaired fast pin features restored.

@rickkas7?

Found it - thanks.

I am surprised that Particle relies on outside libraries for simple device interfaces.

Anyway - as I said the Arduino compatible library is there and it works. I don’t know enough to edit or create a new library myself (or even how to revert to older library versions that did work.)

It’s a bit cumbersome vs. the Arduino IDE, but it all works now.

@ChazL @ScruffR
You can have a look at the case I made a few days ago: “OS Target after 1.5.x does not work with my Console or in HTTP properly”
In my case this is due to the Adafruit_DHT lib not working properly.
Now using PietteTech_DHT library with success.
This happened since the firmware went from 1.5.2 to 2.0.0

Yes. I ran the tests with the old DHT.h library and after ~ 20 reads it stalled the firmware.
I went to the PietteTech_DHT library also and it works fine - tested > 3,000 reads and no stalls.

That is now the go-to solution for the Photon using DHT22.

I think Particle should have a series of sensor libraries that don’t rely on the community. The DHT series is used a lot, although I now should consider the I2C sensors that don’t have the weird bit-banging requirements of DHT’s

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.