Pages: [1] 2 3 ... 5   Go Down
Author Topic: [LIB] Interrupt driven DHTLib (DHT11 & DHT22 = idDHTLib)  (Read 7152 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As turgo kindly ask if someone can add DHT22 functionality to the idDHT11 lib, I make a new lib that can use DHT11 and DHT22 sensors based on the suggestions by pylon.
You can get it from
https://github.com/niesteszeck/idDHTLib

I have tested it with a DHT11 sensor on a Mega2560 on pin 19 (int4), but I don't have a DHT22 sensor to prove it, so if you have one and can confirm that it is working, please let me know to get out the beta label of the code.


EDIT: Finally is ready. Thanks All for the testing
« Last Edit: August 07, 2013, 11:13:13 am by niesteszeck » Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

DHT22 not working, I'm afraid. I did have trouble getting the non-interrupt version to work, however, which I solved by rearranging the construction order of various objects. For some reason the DHT object construction had to be first even though it did nothing meaningful in its constructor, so I wouldn't rule out a problem there. However, I do still have the idDHT object ctor first. I'll try with the barebones example next.

Edit: Scrub that. Now it's working. I didn't even do anything! But temperature is negative and invalid. It's reading -39c when it's actually 25c or so. Humidity might be correct but not sure.
« Last Edit: July 28, 2013, 01:10:44 pm by Dessimat0r » Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I 'changed' was seemingly taking the Arduino with sensor upstairs to my bedroom, where it is warmer. The sensor shows -2.00 temp until 25c (reading on another temperature monitor not connected to Arduino) / -39.50c on Arduino. After it reads the values, those values can be obtained but then appears to be permanently 'acquiring' after another acquire() call.

Tested on Uno R3.
Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I added some wait time between the acquisitions rather than starting a new one straight after getting the results (1 sec) from the one one and it's working a little better, but a lot of the time it's showing -1 for temp and hum. The temperature is still negative and incorrect whenever it shows something not -1.
« Last Edit: July 28, 2013, 02:49:17 pm by Dessimat0r » Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to say, the other Adafruit lib worked great without checksum errors once the problems were fixed, so my wiring should not be at fault.
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 46
Posts: 2883
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Whatever you do you need a 2 second delay between calls to the DHTXX, 2.5 seconds is better. It sounds like you are polling it too fast.

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still getting frequent checksum errors even with 2.5secs. The data and checksum are probably corrupt somehow after being retrieved in idDHTLib.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, thanks for testing it, I'll check it why is failing when I have some time. Please be patient.

any info that you can add that can be useful will be great
Best regards
« Last Edit: July 29, 2013, 11:02:50 am by niesteszeck » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I supose you are using the example code and you are using the dht22Callback instead of the dht11Callback.

I preferred that you use example code to test it, so we can check the same code to find the bug
« Last Edit: July 29, 2013, 01:26:54 pm by niesteszeck » Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using the dht22callback smiley I'll try with the example code today, if you want smiley
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are telling that the addafruit lib is working, but it still can be some signal/wiring problem. For example the DHT11 module that I use is equipped whit the pullup resistor, are you using one similar? or just the naked sensor without nothing extra (I think for DHT11 is a ~5K pull up, and a 1K for the DH22, but please confirm on the datasheet). I'm just trying to think about all possibilities, 'cause I don't have a sensor to pass over the oscilloscope here and be sure that the signal is right, remember that some small noise in the line can trigger an interrupt, so maybe, really a remote possibility, is the line that triggers to much interrupts so the data get corrupted. If you have an oscilloscope, please, can you check the signal against the datasheet of the sensor.

I someone have any idea? Please I'll be glad to discuses any aproach
Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using both the pull up resistor and cap smiley Like I say, no checksum errors or anything with the Adafruit lib, if the constructor is initialised in front of all the constructors (I removed parts of my code to find out which bit was causing the issues, and the two codes looked the same, except for the constructor order, and I thought 'hmmm, it couldn't be this, could it? that really makes no sense..'. But to rule out any memory issues I'll try it with the simple example.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please share a sample code that present that problem and a one that "solve" (where the initialization happens) so I can test it with my dht11 sensor, maybe it happens to
Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Broken:

Code:
#define DHTTYPE DHT22
#define DHTPIN 2     // what pin we're connected to

#include <DHT.h>
DHT dht(DHTTYPE, DHTPIN);

int   dht_chk  = -10;
float dht_hum  = 0;
float dht_temp = 0;

unsigned long dht11lastcheck = 0;

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

void loop() {
if ((millis() > 5000) && (dht11lastcheck + 5000 < millis())) {
Serial.println(millis());
dht_hum  = dht.readHumidity();
dht_temp = dht.readTemperature(false);
dht11lastcheck = millis();
dht_chk = 0;
}
}

I can't seem to find any working version this code, which is a little strange. Before I did it by re-arranging the constructors when I had some more in a bigger version of the code. The DHT pin is correct.
« Last Edit: July 30, 2013, 12:34:20 pm by Dessimat0r » Logged

Liverpool, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This DHTTester code works:

Code:
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#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() {
  // 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.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
  }
}

Any major differences?
Logged

Pages: [1] 2 3 ... 5   Go Up
Jump to: