Skip to content

DHT reading may be "None" if read too soon after boot #16

Closed
@jerryneedell

Description

@jerryneedell

We ra into a strange behavior that some DHT code was failing only after a RESET if loaded as code.py (or main.py) it ran OK via REPL. After much head scraping and false starts it looks like a simple reason.

The code was doing a reading from the dot and checking the value against a limit.

humidity = dht.humidity
if humidity > 50. :
    do something

this failed if dht.humidity returns a None.
Normally it will only return a None if it also throws a Runtime error
But not if time.monotonic() is < .5
In that case, it just silently skips the reading
see
https://github.com/adafruit/Adafruit_CircuitPython_DHT/blob/master/adafruit_dht.py#L141

This check is to make sure readings are not too close together. After one successful read, it will just return the last value read.

One fix would just have the diver always delay the first reading until time.monotonic() > .5
This is only an issue for the first .5 sec after boot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions