# Unable to get results from DHT22

**URL:** <https://community.particle.io/t/unable-to-get-results-from-dht22/28361>\
**Category:** Getting Started\
**Created:** [January 5, 2017, 12:51am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361 "2017-01-05T00:51:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kebabman](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kebabman/32/12667_2.png) [@kebabman](https://community.particle.io/u/kebabman)\
**Post date:** [January 5, 2017, 12:51am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/1 "2017-01-05T00:51:03Z")

</div>

Hi,

I have a core from the origional kickstarter project, however only recently have I had the time to sit down and play with the unit.

I did a firmware update (including the depp firmware update) and setup with a basic breadboard and a DHT22 to capture temp/humidity, my code flashes fine and runs however it appears to never be able to display the data on either serial or the particle console, code is below;

```auto
#include "PietteTech_DHT/PietteTech_DHT.h" // Uncomment if building in IDE

// system defines
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN 3 // Digital pin for communications
#define DHT_SAMPLE_INTERVAL 2000 // Sample every two seconds

/*
 * NOTE: Use of callback_wrapper has been deprecated but left in this example
 * to confirm backwards compabibility. Look at DHT_2sensor for how
 * to write code without the callback_wrapper
 */

double temperature;
double humidity;

// globals
unsigned int DHTnextSampleTime; // Next time we want to start sample
bool bDHTstarted; // flag to indicate we started acquisition
int n; // counter

void dht_wrapper(); // must be declared before the lib initialization

PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

void dht_wrapper() {
  DHT.isrCallback();
}

void setup()
{
    WiFi.on();
    Particle.connect();
          // Variables Exposed to Cloud
    Particle.variable("temperature", temperature);
    Particle.variable("humidity", humidity);
    Particle.variable("time", Time.now());
    Particle.publish("message: ", "I'm alive!");
    Serial.begin(9600);
    DHTnextSampleTime = 0; // Start the first sample immediately
}

void loop()
{
    

  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
	if (!bDHTstarted) { // start the sample
	    Particle.publish("message: ", "In loop() and trying to acquire from sensor");
	    DHT.acquire();
	    bDHTstarted = true;
	    Particle.publish("message: ", "Finished getting data from sensor");
	}

	if (!DHT.acquiring()) { // has sample completed?

	    // get DHT status
	    Particle.publish("message: ", "Going to check the result");
	    int result = DHT.getStatus();

	    Serial.print("Read sensor: ");
	    Particle.publish("message: ", "Read sensor");
	    switch (result) {
		case DHTLIB_OK:
		    Serial.println("OK");
		    Particle.publish("message: ", "Good Data");
		    break;
		case DHTLIB_ERROR_CHECKSUM:
		    Serial.println("Error\n\r\tChecksum error");
			Particle.publish("message: ", "Checksum sensor");    
		    break;
		case DHTLIB_ERROR_ISR_TIMEOUT:
		    Serial.println("Error\n\r\tISR time out error");
		    Particle.publish("message: ", "ISR time out error");	    
		    break;
		case DHTLIB_ERROR_RESPONSE_TIMEOUT:
		    Serial.println("Error\n\r\tResponse time out error");
		    Particle.publish("message: ", "Response time out error");	    
		    break;
		case DHTLIB_ERROR_DATA_TIMEOUT:
		    Serial.println("Error\n\r\tData time out error");
		    Particle.publish("message: ", "Data time out error");	    
		    break;
		case DHTLIB_ERROR_ACQUIRING:
		    Serial.println("Error\n\r\tAcquiring");
		    Particle.publish("message: ", "Error Acquiring from sensor");
		    break;
		case DHTLIB_ERROR_DELTA:
		    Serial.println("Error\n\r\tDelta time to small");
		    Particle.publish("message: ", "Delta time to small");	    
		    break;
		case DHTLIB_ERROR_NOTSTARTED:
		    Serial.println("Error\n\r\tNot started");
		    Particle.publish("message: ", "Not started");	    
		    break;
		default:
		    Serial.println("Unknown error");
		    Particle.publish("message: ", "WTF");	    
		    break;
	    }

        humidity = DHT.getHumidity();
        temperature = DHT.getCelsius();
	
        Serial.printlnf("Humidity\t: %.2f %%", humidity);
        Serial.printlnf("Temperature\t: %.2f °C", temperature);
        Particle.publish("Humidity", String(humidity) + "%");
        Particle.publish("Temperature", String(temperature) + " °C");

	    n++; // increment counter
	    bDHTstarted = false; // reset the sample flag so we can take another
	    DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL; // set the time for next sample
	}
    }

}

```

The particle console displays the “Finished getting data from sensor” message but never moves on to displaying the actual data

Any help would be appreciated!

Rhys

---

<div class="post-metadata">

**Author:** ![Ric](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ric/32/514_2.png) [@Ric](https://community.particle.io/u/Ric)\
**Post date:** [January 5, 2017, 1:37am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/2 "2017-01-05T01:37:21Z")

</div>

Do you see the “Going to check the result” message get published? If not, you should check that your DHT22 is connected properly; either it’s not or it’s possible that you have a defective device.

---

<div class="post-metadata">

**Author:** ![kebabman](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kebabman/32/12667_2.png) [@kebabman](https://community.particle.io/u/kebabman)\
**Post date:** [January 5, 2017, 1:58am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/3 "2017-01-05T01:58:10Z")

</div>

Thanks for the response, I have swapped out for a second DHT I have with no change, also I put both DHT’s into an arduino uno and they have worked fine

---

<div class="post-metadata">

**Author:** ![Ric](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ric/32/514_2.png) [@Ric](https://community.particle.io/u/Ric)\
**Post date:** [January 5, 2017, 2:20am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/4 "2017-01-05T02:20:58Z")

</div>

Back to my first question; do you see the “Going to check the result” message get published?  
I ran your code on my Photon, and it works fine there. I’m not sure why it would be any different on a Core.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [January 5, 2017, 2:52am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/5 "2017-01-05T02:52:50Z")

</div>

Post a picture of your setup and wiring.

---

<div class="post-metadata">

**Author:** ![Ric](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ric/32/514_2.png) [@Ric](https://community.particle.io/u/Ric)\
**Post date:** [January 5, 2017, 6:42am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/6 "2017-01-05T06:42:18Z")

</div>

I dug out one of my old Cores, and I am getting the same results you are. DHT.acquiring() always returns true, so it never makes it past that test. I tried powering it from 3v3 and from Vin, with and without a 1k pullup resistor on the data line (it works without that on the Photon, but I’ve seen some tutorials that use it, and others that do not).

**After Edit:** I compiled against 0.6.0 (above), then I tried 0.5.3 and 0.4.9. It finally worked with 0.4.9. The PietteTech library uses interrupts, and there is a known issue with interrupts and the Core in firmware versions 0.5.3 and up. See this [link](https://community.particle.io/t/interrupts-disabled-on-core-fw-0-5-3-and-later/26393).

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 5, 2017, 7:28am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/7 "2017-01-05T07:28:14Z")

</div>

@ric, does reenabling interrupts in `setup()` or `STARTUP()` cure the problem for you on 0.5.3ff?

It should work, but extra confirmation always helps 😉  
[https://github.com/spark/firmware/issues/1136](https://github.com/spark/firmware/issues/1136)

---

<div class="post-metadata">

**Author:** ![kebabman](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kebabman/32/12667_2.png) [@kebabman](https://community.particle.io/u/kebabman)\
**Post date:** [January 5, 2017, 8:42am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/8 "2017-01-05T08:42:19Z")

</div>

Adding interrupts(); to setup() on firmware 0.6 has fixed everything, getting good consistent results from the core/dht22 now

Thanks - pretty sure I wouldn’t have figured this one out myself!

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [January 5, 2017, 10:40am UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/9 "2017-01-05T10:40:42Z")

</div>

Do take a look at how many publishes you’re pushing out without any noticeable delays. Currently I can count 5 of them right after one another, which will exceed the publish limit. Do take that into consideration;)

---

<div class="post-metadata">

**Author:** ![Ric](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ric/32/514_2.png) [@Ric](https://community.particle.io/u/Ric)\
**Post date:** [January 5, 2017, 4:14pm UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/10 "2017-01-05T16:14:30Z")

</div>

> [@ScruffR](#):
>
> does reenabling interrupts in setup() or STARTUP() cure the problem for you on 0.5.3ff?

Sometimes (on 0.6.0), but sometimes I'm getting an SOS (invalid case), so I think my Core has other problems. I haven't used it in a long time. It may be in need of a deep update.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [January 6, 2017, 5:45pm UTC](https://community.particle.io/t/unable-to-get-results-from-dht22/28361/11 "2017-01-06T17:45:38Z")

</div>

@kebabman Here is an interesting article on Hackaday showing how bad the DHT 22 sensor is, it’s worse than I thought and it’s not something that can be fixed via software coding. Figure I would share it with you.

> **[Humidity Sensor Shootout](https://hackaday.com/2017/01/03/humidity-sensor-shootout/)**
>
> If you want to measure humidity (and temperature, and maybe even barometric pressure) in a device that you’re building, have a look at this comprehensive test of seven different options. We&#…
