Skip to content

DHT11/DHT22 — load new sample (dht_measure)

What it does: Requests new temperature and humidity readings from the DHT sensor and stores them in the library's internal buffer.

dht_measure

Inputs

  • No data inputs.

Output

  • None (statement block).

When to use it

  • In the loop before reading the values using the dht_read_temp and dht_read_humidity commands.
  • After initializing the sensor with the dht_init block.
  • DHT sensors are slow. For DHT22/AM2302, expect a measurement period of around 2 s.

Tips and pitfalls

  • Without this block, the old values from the previous measurement are read.
  • Don't call him too often. It is convenient to read DHT22/AM2302 about once every 2s. There is no point in calling this function more often, it will always return the same data.
  • The library may throw OSError on a communication error.

Usage example

example_dht

Open Example in ESP IDE

Generated Python example

try:
    dhts.measure()
    time.sleep(1)
except OSError as e:
    print("Error reading DHT")