Go Down

Topic: [LIB] Interrupt driven DHTLib (DHT11 & DHT22 = idDHTLib) (Read 7 times) previous topic - next topic

Dessimat0r

Code: [Select]
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.

Dessimat0r

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

Dessimat0r

#32
Jul 30, 2013, 11:10 pm Last Edit: Jul 30, 2013, 11:13 pm by Dessimat0r Reason: 1
I added the data viewing code where the checkum error would normally be shown, and now it shows (in a loop):

Code: [Select]
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?

Dessimat0r

#33
Jul 30, 2013, 11:13 pm Last Edit: Jul 30, 2013, 11:18 pm by Dessimat0r Reason: 1
I re-uploaded with my data checking code, now it has frozen on

Code: [Select]
DHTLib Example program
LIB version: 0.0.2
---------------

Retrieving information


Weird.

Code: [Select]
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;

Dessimat0r

#34
Jul 30, 2013, 11:27 pm Last Edit: Jul 30, 2013, 11:29 pm by Dessimat0r Reason: 1
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: [Select]
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.

niesteszeck

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

Dessimat0r

Code: [Select]
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

niesteszeck

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?

Dessimat0r

This is the debug-printing code:

Code: [Select]
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 :)

Dessimat0r

Code: [Select]
/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

Dessimat0r

I made it work:


Code: [Select]
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
--------------

niesteszeck

#41
Jul 30, 2013, 11:54 pm Last Edit: Jul 31, 2013, 12:11 am by niesteszeck Reason: 1
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

niesteszeck

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?

Dessimat0r

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

Dessimat0r

#44
Jul 31, 2013, 12:14 am Last Edit: Jul 31, 2013, 12:15 am by Dessimat0r Reason: 1
Code: [Select]
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 :)

Go Up