Skip to content

Commit

Permalink
Merge pull request #6 from hibikiledo/fix-negative-temp-support
Browse files Browse the repository at this point in the history
Fix broken support for negative temperature
  • Loading branch information
hibikiledo authored Dec 10, 2022
2 parents a841d38 + 23ac1c3 commit ad88a61
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions AM2320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool AM2320::measure() {
_humidity = humudity / 10.0;

int temperature = ((_buf[4] & 0x7F) << 8) | _buf[5];
if ((_buf[2] & 0x80) >> 8 == 1) { // negative temperature
if ((_buf[4] & 0x80) >> 7 == 1) { // negative temperature
_temperature = (temperature / 10.0) * -1; // devide data by 10 according to the datasheet
}
else { // positive temperature
Expand Down Expand Up @@ -90,7 +90,7 @@ bool AM2320::_read_registers(int startAddress, int numByte) {
return false; // return sensor not ready code
}
delayMicroseconds(1500); // as specified in datasheet
Wire.requestFrom(AM2320_ADDR, numByte + 4); // request bytes from sensor
Wire.requestFrom(AM2320_ADDR, numByte + 4); // request bytes from sensor +4 if for metadata from sensor
// see function code description in datasheet
for ( int i = 0; i < numByte + 4; i++) { // read
_buf[i] = Wire.read();
Expand Down

0 comments on commit ad88a61

Please sign in to comment.