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

Code:
Retrieving information from sensor: Read sensor: Error

Checksum error
Humidity (%): -1.00
Temperature (oC): -1.00
Temperature (oF): -1.00
Temperature (K): -1.00
Dew Point (oC): -1.00
Dew Point Slow (oC): -1.00

In a loop with new code.
Logged

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

Might it be helpful to output the entire data being received over serial so you can see how it mismatches?
Logged

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

I added the data viewing code where the checkum error would normally be shown, and now it shows (in a loop):

Code:
Retrieving information from sensor: Read sensor: OK
Humidity (%): 64.50
Temperature (oC): -24.30
Temperature (oF): -11.74
Temperature (K): 248.85
Dew Point (oC): -29.06
Dew Point Slow (oC): -29.09

Maybe the Arduino environment did not detect the code had changed?
« Last Edit: July 30, 2013, 04:13:30 pm by Dessimat0r » Logged

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

I re-uploaded with my data checking code, now it has frozen on

Code:
DHTLib Example program
LIB version: 0.0.2
---------------

Retrieving information

Weird.

Code:
detachInterrupt(intNumber);
// WRITE TO RIGHT VARS
uint8_t sum;
if (dht22) {
hum = word(bits[0], bits[1]) * 0.1;
temp = (bits[2] & 0x80) ? word(bits[2]&0x7F, bits[3]) * -0.1 : word(bits[2], bits[3]) * 0.1;
sum = bits[0] + bits[1] + bits[2] + bits[3]; 
} else {
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
hum    = bits[0];
temp = bits[2];
sum = bits[0] + bits[2];

if (bits[4] != sum) {
status = IDDHTLIB_ERROR_CHECKSUM;
state = STOPPED;

      Serial.print("idx: ");
  Serial.println(idx, DEC);
  Serial.print("data: ");
  Serial.print(bits[0], HEX); Serial.print(", ");
  Serial.print(bits[1], HEX); Serial.print(", ");
  Serial.print(bits[2], HEX); Serial.print(", ");
  Serial.print(bits[3], HEX); Serial.print(", ");
  Serial.print(bits[4], HEX); Serial.print(" =? ");
  Serial.println(bits[0] + bits[1] + bits[2] + bits[3], HEX);
  Serial.print("Checksum: ");
  Serial.println(sum);
} else {
status = IDDHTLIB_OK;
state = ACQUIRED;
}
break;
« Last Edit: July 30, 2013, 04:18:33 pm by Dessimat0r » Logged

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

I am also getting -1 when that segment is commented out. But either it seems I get some values every time it's reset or simply -1 every time. LEt me try resetting it a few times. I don't know why that serial code causes any issues. Is it in a critical section?

Code:
Retrieving information from sensor: Read sensor: Error

Checksum error
Humidity (%): -1.00
Temperature (oC): -1.00
Temperature (oF): -1.00
Temperature (K): -1.00
Dew Point (oC): -1.00
Dew Point Slow (oC): -1.00

Edit: I can't seem to get any readable values now.
« Last Edit: July 30, 2013, 04:29:33 pm by Dessimat0r » Logged

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

first: Arduino always recompile the code and libs involved in a sketch, so if you updated the files,m saved it, Arduino should use the new code.

Second: About putting prints on the interrupt is not a good idea, first because remember that you are in an interrupt, so interrupts are disabled, and you are sharing stack with whatever is running before the interrupt is called, so as less code as you can put in an interrupt is better.

As something to try:If you want, you can make a new method to print all the vars, so after you make an adckireAndWait and after it finish, you call this new method to print all kind of private vars of the class (idx, count, data....etc), to check what you get. If you have an oscilloscope you can check that all bits are received in a good way or determine which one is failing or misinterpreted
Logged

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

Code:
Retrieving information from sensor: Read sensor: idx: 5
data: 2, 96, 80, F3, 8B =? 20B
Error

Checksum error
Humidity (%): -1.00
Temperature (oC): -1.00
Temperature (oF): -1.00
Temperature (K): -1.00
Dew Point (oC): -1.00
Dew Point Slow (oC): -1.00
Logged

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

what code did you use?
are you printing in HEX or DEC

I updated the branch so I added a new example that use the new method, can you try it?
Logged

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

This is the debug-printing code:

Code:
void idDHTLib::debugPrint() {
      Serial.print("idx: ");
  Serial.println(idx, DEC);
  Serial.print("data: ");
  Serial.print(bits[0], HEX); Serial.print(", ");
  Serial.print(bits[1], HEX); Serial.print(", ");
  Serial.print(bits[2], HEX); Serial.print(", ");
  Serial.print(bits[3], HEX); Serial.print(", ");
  Serial.print(bits[4], HEX); Serial.print(" =? ");
  Serial.println(bits[0] + bits[1] + bits[2] + bits[3], HEX);
}


I will try yours smiley
Logged

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

Code:
/Users/dessimat0r/Documents/Arduino/libraries/idDHTLib/idDHTLib.cpp: In member function 'void idDHTLib::printVars()':
/Users/dessimat0r/Documents/Arduino/libraries/idDHTLib/idDHTLib.cpp:209: error: 'bist' was not declared in this scope
/Users/dessimat0r/Documents/Arduino/libraries/idDHTLib/idDHTLib.cpp:219: error: 'sum' was not declared in this scope
Logged

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

I made it work:


Code:
Retrieving information from sensor: Read sensor: Error

Checksum error
Humidity (%): -1.00
Temperature (oC): -1.00
Temperature (oF): -1.00
Temperature (K): -1.00
Dew Point (oC): -1.00
Dew Point Slow (oC): -1.00
Printing vars:
bits[0]: 2
bits[1]: 92
bits[2]: 80
bits[3]: F1
bits[4]: 85
sum: 517
idx: 5
cnt: 7
--------------
Logged

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

is basically the same, and as you report it has type errors
I'm analyzing the output that you give to me

update: great, now i have two output to see what is happening! Be patient
« Last Edit: July 30, 2013, 05:11:09 pm by niesteszeck » Logged

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

there is something strange, how do you managed to print the sum, 'cause I realize that sum is a local var. Another thing is that the sum in some cases is bigger than 256 and sum is a uint_8 so just for test purpose I make it class global and set as int and added more info to print. So can you try this new code?
Logged

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

Oh, I added all the numbers together again. That's a good point smiley
Logged

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

Code:
Retrieving information from sensor: Read sensor: Error

Checksum error
Humidity (%): -1.00
Temperature (oC): -1.00
Temperature (oF): -1.00
Temperature (K): -1.00
Dew Point (oC): -1.00
Dew Point Slow (oC): -1.00
Printing vars:
bist[0]: 0x2 d2
bist[1]: 0xFC dFC
bist[2]: 0x80 d80
bist[3]: 0xF3 dF3
bist[4]: 0x71 d71
sum: 0x271 d625
idx: 5
cnt: 7

It seems that there is a mistake with dec/hex but doesn't matter too much smiley
« Last Edit: July 30, 2013, 05:15:53 pm by Dessimat0r » Logged

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