guild icon
Toit
#pkg dhtxx: reports wrong temperature value if cold (T < 0ยฐC)
Thread channel in help
kaxori
kaxori 12/28/2024 06:21 PM
if temperature gets negative it returns wrong values:
T: 0.00, H: 64.60
T: 3276.90, H: 64.60

reason might be here:
parse_temperature_ data/ByteArray -> float: return (BIG_ENDIAN.uint16 data driver.Driver.TEMPERATURE_INTEGRAL_PART_) / 10.0


=> it works, but I think could be done nicer:
parse_temperature_ data/ByteArray -> float: return not (driver.Driver.TEMPERATURE_INTEGRAL_PART_ & 0x8000) ? (BIG_ENDIAN.uint16 data driver.Driver.TEMPERATURE_INTEGRAL_PART_) / 10.0 : -((BIG_ENDIAN.uint16 data driver.Driver.TEMPERATURE_INTEGRAL_PART_) & 0x7ff) / 10.0
(edited)
kaxoriOPkaxori
if temperature gets negative it returns wrong values: T: 0.00, H: 64.60 T: 3276.90, H: 64.60 reason might be here: ``` parsetemperature data/ByteArray -> float: return (BIG_...(edited)
floitsch
floitsch 12/28/2024 07:33 PM
So the first bit is a sign bit?
kaxori
kaxori 12/28/2024 07:34 PM
yes, but I still struggle with correct boolean expression
floitsch
floitsch 12/28/2024 07:35 PM
I will fix the package when I'm back from vacation. Please post a few values you get from the sensor so I can verify that the new code will work
๐Ÿ‘๐Ÿป1
kaxori
kaxori 12/28/2024 08:15 PM
DHT data: #[0x02, 0x61, 0x00, 0x01, 0x64]
333: T: 0.10, H: 60.90
DHT data: #[0x02, 0x61, 0x00, 0x00, 0x63]
334: T: 0.00, H: 60.90
DHT data: #[0x02, 0x62, 0x00, 0x00, 0x64]
335: T: 0.00, H: 61.00
DHT data: #[0x02, 0x63, 0x00, 0x00, 0x65]
336: T: 0.00, H: 61.10
DHT data: #[0x02, 0x64, 0x00, 0x00, 0x66]
337: T: 0.00, H: 61.20
DHT data: #[0x02, 0x65, 0x00, 0x00, 0x67]
338: T: 0.00, H: 61.30
DHT data: #[0x02, 0x64, 0x80, 0x01, 0xe7]
339: T: -0.10, H: 61.20
DHT data: #[0x02, 0x64, 0x80, 0x01, 0xe7]
340: T: -0.10, H: 61.20
DHT data: #[0x02, 0x63, 0x80, 0x01, 0xe6]
341: T: -0.10, H: 61.10
DHT data: #[0x02, 0x61, 0x80, 0x01, 0xe4]
342: T: -0.10, H: 60.90
DHT data: #[0x02, 0x60, 0x80, 0x02, 0xe4]
343: T: -0.20, H: 60.80
๐Ÿ‘1
kaxori
kaxori 12/28/2024 08:17 PM
Hope you have cold enough temperatures then.
enjoy your vacation.
๐Ÿ™1
kaxori
kaxori 01/02/2025 07:45 PM
you changed only the import
import io show BIG_ENDIAN`
:๐Ÿค”: I do not understand why this change removes the error. Could you please help me .
floitsch
floitsch 01/02/2025 07:46 PM
The PR with the fix hasn't been committed yet: https://github.com/toitware/toit-dhtxx/pull/12(edited)
The DHT22 supports negative temperatures which weren't read correctly.
Fixes #10.
kaxori
kaxori 01/02/2025 07:47 PM
:๐Ÿ˜ฌ: :๐Ÿค:
floitsch
floitsch 01/06/2025 11:15 AM
A new version of the package has been published.
๐Ÿ‘๐Ÿป1
10 messages in total