dht22(4)

dht224

Driver for dhtxx and am320x temperature and humidity sensors

Part of gpioths(4).

Usage

To compile this driver into the kernel, place the following line in your kernel configuration file:

device gpioths

Alternatively, to load the driver as a module at boot time, place the following line in loader.conf(5):

gpioths_load="YES"

Overview

The gpioths driver supports the DHTxx and AM320x family of temperature and humidity sensors. The driver automatically reads the values from the sensor once every 5 seconds, and makes the results available via sysctl(8) variables.

Hardware

The gpioths driver provides support for the following devices:

DHT11DHT12
DHT21DHT22
AM3201AM3202

The supported devices are all similar to each other, varying primarily in accuracy and resolution. The devices require a single wire for data communications, using a custom protocol which is not compatible with Maxim's 1-wire(tm). The AM320x devices also support connection to an i2c bus, but this driver supports only the single-wire connection option.

Sysctl variables

Sysctl variables are used to access the most recent temperature and humidity measurements.

dev.gpioths.<unit>.temperature

The current temperature in integer deciKelvins. Note that sysctl(8) will convert those units to display in decimal degrees Celsius.

dev.gpioths.<unit>.humidity

The current relative humidity, as an integer percentage.

dev.gpioths.<unit>.fails

The number of failed attempts to communicate with the sensor since the last good access. Cleared whenever a set of measurements is successfully retrieved.

FDT configuration

On an fdt(4) based system, a gpioths device node is typically defined directly under the root node, or under a simplebus node that represents a collection of devices on a board.

The following properties are required in the gpioths device subnode:

compatible

Must be "dht11".

gpios

A reference to the gpio device and pin for data communications.

Example of adding a sensor with an overlay

/dts-v1/;
/plugin/;
#include <dt-bindings/gpio/gpio.h>
/ {
    compatible = "wand,imx6q-wandboard";
};
&{/} {
    dht0 {
        compatible = "dht11";
        gpios = <&gpio5 15 GPIO_ACTIVE_HIGH>;
    };
};

Hints configuration

On a device.hints(5) based system, such as MIPS, these values are configurable for gpioths:

hint.gpioths.<unit>.at

The gpiobus(4) instance the gpioths instance is attached to.

hint.gpioths.pins

A bitmask with a single bit set to indicate which gpio pin on the gpiobus(4) to use for data communications.

Releases

18 releases since FreeBSD 12.2-RELEASE; the text changed 6 times.

  1. 12.2
  2. 12.3
  3. 12.4
  4. 13.0
  5. 13.1–13.2
  6. 13.3–13.5
  7. 14.0–16.0

History

The gpioths driver first appeared in FreeBSD 11.1.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.