Pages: [1] 2   Go Down
Author Topic: [LIB] Interrupt driven DHT11 Lib (idDHT11)  (Read 15926 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

Hello, I'm working with DuinOS and the DHT11 library has some problems working with it 'cause the timing. 'cause of this i had improved the library to use ineterrupts on pins and liberate the cpu meanwhile. I have proved it in a Mega2560 with arduino 1.03 and is working bery well.

You can get this lib at
https://github.com/niesteszeck/idDHT11
« Last Edit: March 22, 2013, 03:11:26 pm by niesteszeck » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13915
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks good!

I can see only one remark that is STOPPED is with double P smiley-wink

I'll make a link in the playground article - http://playground.arduino.cc/Main/DHT11Lib - to this thread so people can find it easier!
(done)
« Last Edit: March 22, 2013, 02:00:58 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Sorry for that (I speek spanish as my native language)
Now is corrected
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13915
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No need to apologize for a great job!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Camarillo, California (US)
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi can someone help please with newb question.  Trying to read temp/rh with the dht11.  In the code samples and examples I came across a VERY cool code example that not only reads temp/rh BUT reads dewpoint calcs.  Which is very useful for me.  Only problem is that being a NEWB Im sure that Im doing something wrong in loading the code to the Arduino.

Arduino Mega 2560
Mega shield

So code that has information I want is here-

http://playground.arduino.cc//Main/DHT11Lib?action=sourceblock&num=1

but when I try to compile/upload, i get the error message "DHT11 does NOT have a name"  ARRGGHH....

now I notice that along with this code there are two other files
one labeled
dht11.h (code is here http://playground.arduino.cc//Main/DHT11Lib?action=sourceblock&num=2)

the other labeled
dht11.cpp (code is here http://playground.arduino.cc//Main/DHT11Lib?action=sourceblock&num=3)

so not sure (because I am a newb) if these are necessary? help define the name of the DHT or what.. 

Can someone help please..

thanks again for your patience in advance..
Logged

my skype is chuck.colby in camarillo ca

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

Hello, your question isn't related to this specific lib. You are using example code and source files from the original DHT11 lib. THIS lib that I published here is another version, that works different (interrupt driven way) and has his own example codes. If you want you can try it downloading it from the link to github in the original post of this thread.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13915
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@niesteszeck

Can this DHT22 patch be included in the library?   - http://forum.arduino.cc/index.php?topic=175356.0 -

imho it is worth the effort to merge!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

I'm talking on the other thread. If the modification is working on a dht22 sensor, I'll analyze how to mix both sensors in the same library, other way we have to make 2 libraries. Other thing is that I dont have a dht22 sensor, so any modification must be proved by others (or someone can gift me one smiley-grin)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13915
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It should be quite easy to add DHT22 support into one library
- add a flag that indicates the type and select the right - bits to data -  function in the end.

the code in the other thread looks good to me, so I think you can start designing/integrating to create a first beta.

« Last Edit: July 03, 2013, 01:53:22 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Yes sure, but the modification to DATA section on the interrupt that is proposed on http://forum.arduino.cc/index.php?topic=175356.0 I need to confirm that is actually working to integrate into the other library.

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13915
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or you can build it into the lib and you have something to be verified by someone.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

That's right. I'll make it for DHT22 to, but give me some time to do it, I'm working and don't have to much time to my personal projects, so please be patient. I'm goig to continue this conversation on the other thread
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to use multiple dht11 sensors with this library?
The test so far only reports -7 for second sensor.
Logged

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

I'm not pretty sure if it's working with two sensors, but I have two, and when I was developing it I used the 2. If I'm not wrong it should work with two sensors. The only thing is that you have to use 2 different pins that has interrupts

In a quick review, I can say that looks like the interrupt is not being called. What method are you calling to get the -7 value, can you share the code.

A small example that is based on the example that comes with the lib:
Code:
/*
  Board          int.0  int.1  int.2  int.3  int.4  int.5
 Uno, Ethernet  2  3
 Mega2560  2  3  21  20  19  18
 Leonardo  3  2  0  1
 Due          (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
 */

#include <idDHT11.h>

int idDHT11pinA = 2; //Digital pin for comunications
int idDHT11intNumberB = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
int idDHT11pinB = 3; //Digital pin for comunications
int idDHT11intNumberB = 1; //interrupt number (must be the one that use the previus defined pin (see table above)

//declaration
void dht11_wrapperA(); // must be declared before the lib initialization
//declaration
void dht11_wrapperB(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11A(idDHT11pinA,idDHT11intNumberA,dht11_wrapperA);
idDHT11 DHT11B(idDHT11pinB,idDHT11intNumberB,dht11_wrapperB);

// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapperA() {
  DHT11A.isrCallback();
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapperB() {
  DHT11B.isrCallback();
}


if you test this small example (need to be completed the loop and setup functions), please tell me how it goes. If it works, you can make a pull request to add an example that use 2 sensors on github, so everyone wins. If not, we can review why and analyze if it will be possible and add this functionality to the lib, anyway, everyone wins smiley.
« Last Edit: March 21, 2014, 03:22:20 pm by niesteszeck » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the long wait, i was swamped by another aspect of my project.
Now it's working. The problem was the missing
Code:
DHT11B.acquire();
Is there any other reason than debugging purpose for this part of code?
Code:
while (DHT11A.acquiring())
    ;
  int result = DHT11A.getStatus();
  switch (result)
  {
    case IDDHTLIB_OK:
      Serial.println("OK");
      break;
    case IDDHTLIB_ERROR_CHECKSUM:
      Serial.println("Error\n\r\tChecksum error");
      break;
    case IDDHTLIB_ERROR_ISR_TIMEOUT:
      Serial.println("Error\n\r\tISR Time out error");
      break;
    case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
      Serial.println("Error\n\r\tResponse time out error");
      break;
    case IDDHTLIB_ERROR_DATA_TIMEOUT:
      Serial.println("Error\n\r\tData time out error");
      break;
    case IDDHTLIB_ERROR_ACQUIRING:
      Serial.println("Error\n\r\tAcquiring");
      break;
    case IDDHTLIB_ERROR_DELTA:
      Serial.println("Error\n\r\tDelta time to small");
      break;
    case IDDHTLIB_ERROR_NOTSTARTED:
      Serial.println("Error\n\r\tNot started");
      break;
    default:
      Serial.println("Unknown error");
      break;
  }
because it work just fine without it, and i didn't figured out how to change it for the second sensor.

Here is the modified code. Sorry for the bad formating  smiley-red
Code:
/*
  Board          int.0  int.1  int.2  int.3  int.4  int.5
 Uno, Ethernet  2  3
 Mega2560  2  3  21  20  19  18
 Leonardo  3  2  0  1
 Due          (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
 */

#include <idDHT11.h>

int idDHT11pinA = 2; //Digital pin for comunications
int idDHT11intNumberA = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
int idDHT11pinB = 3; //Digital pin for comunications
int idDHT11intNumberB = 1; //interrupt number (must be the one that use the previus defined pin (see table above)

//declaration
void dht11_wrapperA(); // must be declared before the lib initialization
//declaration
void dht11_wrapperB(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11A(idDHT11pinA, idDHT11intNumberA, dht11_wrapperA);
idDHT11 DHT11B(idDHT11pinB, idDHT11intNumberB, dht11_wrapperB);




void setup()
{
  Serial.begin(115200);
  Serial.println("idDHT11 Example program for two sensors");
  Serial.print("LIB version: ");
  Serial.println(IDDHT11LIB_VERSION);
  Serial.println("---------------");
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapperA() {
  DHT11A.isrCallback();
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapperB() {
  DHT11B.isrCallback();
}
void loop()
{
  Serial.print("\nRetrieving information from sensors: ");
  Serial.print("Read sensor: ");
  //delay(100);
  DHT11B.acquire();
  DHT11A.acquire();
  while (DHT11A.acquiring())
    ;
  int result = DHT11A.getStatus();
  switch (result)
  {
    case IDDHTLIB_OK:
      Serial.println("OK");
      break;
    case IDDHTLIB_ERROR_CHECKSUM:
      Serial.println("Error\n\r\tChecksum error");
      break;
    case IDDHTLIB_ERROR_ISR_TIMEOUT:
      Serial.println("Error\n\r\tISR Time out error");
      break;
    case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
      Serial.println("Error\n\r\tResponse time out error");
      break;
    case IDDHTLIB_ERROR_DATA_TIMEOUT:
      Serial.println("Error\n\r\tData time out error");
      break;
    case IDDHTLIB_ERROR_ACQUIRING:
      Serial.println("Error\n\r\tAcquiring");
      break;
    case IDDHTLIB_ERROR_DELTA:
      Serial.println("Error\n\r\tDelta time to small");
      break;
    case IDDHTLIB_ERROR_NOTSTARTED:
      Serial.println("Error\n\r\tNot started");
      break;
    default:
      Serial.println("Unknown error");
      break;
  }
  
  Serial.println("************************************************************");
  Serial.println("*********************************Sensor 1*******************");
  Serial.println("************************************************************");
  Serial.print("Humidity (%): ");
  Serial.println(DHT11A.getHumidity(), 2);

  Serial.print("Temperature (oC): ");
  Serial.println(DHT11A.getCelsius(), 2);

  Serial.print("Temperature (oF): ");
  Serial.println(DHT11A.getFahrenheit(), 2);

  Serial.print("Temperature (K): ");
  Serial.println(DHT11A.getKelvin(), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(DHT11A.getDewPoint());

  Serial.print("Dew Point Slow (oC): ");
  Serial.println(DHT11A.getDewPointSlow());
  Serial.println("************************************************************");
  Serial.println("*********************************Sensor 2*******************");
  Serial.println("************************************************************");
  Serial.print("Humidity (%): ");
  Serial.println(DHT11B.getHumidity(), 2);

  Serial.print("Temperature (oC): ");
  Serial.println(DHT11B.getCelsius(), 2);

  Serial.print("Temperature (oF): ");
  Serial.println(DHT11B.getFahrenheit(), 2);

  Serial.print("Temperature (K): ");
  Serial.println(DHT11B.getKelvin(), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(DHT11B.getDewPoint());

  Serial.print("Dew Point Slow (oC): ");
  Serial.println(DHT11B.getDewPointSlow());

  delay(2000);
}
« Last Edit: March 23, 2014, 02:12:31 pm by Tero521 » Logged

Pages: [1] 2   Go Up
Jump to: