Fixed negative temperature bug.

This commit is contained in:
2024-01-08 14:44:06 +01:00
parent 2038a1aa9d
commit bb81f2d6de
9 changed files with 33730 additions and 33710 deletions

View File

@@ -57,3 +57,8 @@ First (more or less) working version.
### Fixed ### Fixed
- One of the digital outputs was inverted. - One of the digital outputs was inverted.
## [1.1.2] - [2024-01-08]
### Fixed
- Negative temperature where converted wrong: -1 became -32767. This was because of a weird format the sensor uses.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -758,6 +758,12 @@ int main() {
if (!NO_I2C_AVAILABLE) if (!NO_I2C_AVAILABLE)
ReadAM2315(&humidity, &temperature); ReadAM2315(&humidity, &temperature);
// Bit 15 of AM2315 temperature is sign (1 = negative). Bit 14-0 is absolute value of teperature
if (temperature&0x8000) {
temperature = temperature & 0x7FFF; // remove sign bit
temperature = -temperature; // make proper signed integer of negative number
}
// Format telemetry string // Format telemetry string
sprintf(tmp_string, "%.1f,%.1f", (float)temperature/10, (float)humidity/10); sprintf(tmp_string, "%.1f,%.1f", (float)temperature/10, (float)humidity/10);
// Copy string (including NULL terminator) to final destination (can not be done without temporary string due to char/uint8_t issues) // Copy string (including NULL terminator) to final destination (can not be done without temporary string due to char/uint8_t issues)