DHT11/22 Temp and Humidity Sensors

I never realized we have a GPIO driver for DHT11/22 sensor.

I was having problems compiling the DT Overlay.
The FreeBSD manpage gives this:
Code:
gpios = <&gpio5 15 GPIO_ACTIVE_HIGH>;
The GPIO_ACTIVE_HIGH setting is faulty.
Code:
# dtc -O dtb -o rockpro64-gpioths.dtbo -@ rockpro64-gpioths.dts
Error at rockpro64-gpioths.dts:12:33: Expected numbers in array of cells
                gpio = <&pio 1 4 GPIO_ACTIVE_HIGH>;
                                 ^
Error at rockpro64-gpioths.dts:12:33: Expected ; at end of property
                gpio = <&pio 1 4 GPIO_ACTIVE_HIGH>;
                                 ^
Error at rockpro64-gpioths.dts:12:33: Failed to find root node /.
                gpio = <&pio 1 4 GPIO_ACTIVE_HIGH>;
                                 ^
Failed to parse tree.

Simply changing it to 0 does the trick.(Sets the pin high)

/boot/dtb/overlays/rockpro64-gpioths.dts
Code:
/dts-v1/;
/plugin/;

/ {
    compatible = "rockchip,rk3399";
    fragment@0 {                   
        target-path = "/";
        __overlay__ {
                dht0 {
                compatible = "dht11";
                pinctrl-names = "default";
                gpios = <&gpio1 4 0>;
                status = "okay";
            };
        };
    };
};

Add to /boot/loader.conf :
Code:
gpioths_load="YES"
fdt_overlays="rockpro64-gpioths.dtbo"


dmesg | grep gpioth
Code:
gpioths0: <DHT11/DHT22 Temperature and Humidity Sensor> on ofwbus0

sysctl -a | grep gpioths
Code:
gpioths0: <DHT11/DHT22 Temperature and Humidity Sensor> on ofwbus0
    value:    /boot/kernel/gpioths.ko
    value:    /boot/dtb/overlays/rockpro64-gpioths.dtbo
dev.gpioths.0.fails: 0
dev.gpioths.0.humidity: 70
dev.gpioths.0.temperature: 24.1C
dev.gpioths.0.%parent: ofwbus0
dev.gpioths.0.%pnpinfo: name=dht0 compat=dht11
dev.gpioths.0.%location:
dev.gpioths.0.%driver: gpioths
dev.gpioths.0.%desc: DHT11/DHT22 Temperature and Humidity Sensor
dev.gpioths.%parent:
 
On the DHT11/22, you need a separate data wire for each sensor, right? I'm using a 1-wire temperature/humidity sensor, it's called the WallTH. Problem is (and I think the DHT shares that, as do most inexpensive humidity sensors): If installed outdoors, they will occasionally get condensation on them. And that kills the humidity sensor: if you do it occasionally, they just get inaccurate; if you do it repeatedly, they report insane values. For example, right now it is raining outdoors, and the good weather station reports 94% humidity (which I believe). The two WallTH sensors report 101% and 145%. I've also recently seen them report negative humidity.

I'm still looking for an inexpensive embeddable humidity sensor that survives outdoors, which is easy to wire (no more than 3 wires, and ideally not dedicated wires). Not a high-priority project, just for curiosity.
 
On the DHT11/22, you need a separate data wire for each sensor, right?
Just doing that now. Adding additional sensors.
Yes it appears each sensor needs a GPIO pin versus One Wire Temp DS1820 which uses a daisy chained OW bus.
The DHT22 is advertised as more accurate version of DHT11.
I found my additional sensors in a tub, AM2302. These should be usable.

It does appear that DHT11/22 offers a 4 pin version which works with I2C.
I do imagine with that you could daisychain. I don't think the driver supports i2c from my source code reading.
/usr/src/sys/dev/gpio/gpioths.c
I really appreciate the exquisitely commented code.
I see this too in the source:
* AM2301: Same as DHT21, but also supports i2c interface.
* AM2302: Same as DHT22, but also supports i2c interface.
My AM2302 modules are only 3 wire.
I see nothing in the code body about i2c.
 
Temperature is easy. I use various DS182x sensors, some outdoors (lots of heatshrink and coating, carefully protected from direct rain). Humidity is hard, once condensation happens.
 
We have lift-off:
Code:
# dmesg | grep gpioth
gpioths0: <DHT11/DHT22 Temperature and Humidity Sensor> on ofwbus0
gpioths1: <DHT11/DHT22 Temperature and Humidity Sensor> on ofwbus0

# sysctl dev.gpioths
dev.gpioths.1.fails: 0
dev.gpioths.1.humidity: 61
dev.gpioths.1.temperature: 22.5C
dev.gpioths.1.%parent: ofwbus0
dev.gpioths.1.%pnpinfo: name=dht0 compat=dht11
dev.gpioths.1.%location:
dev.gpioths.1.%driver: gpioths
dev.gpioths.1.%desc: DHT11/DHT22 Temperature and Humidity Sensor
dev.gpioths.0.fails: 0
dev.gpioths.0.humidity: 67
dev.gpioths.0.temperature: 22.2C
dev.gpioths.0.%parent: ofwbus0
dev.gpioths.0.%pnpinfo: name=dht1 compat=dht11
dev.gpioths.0.%location:
dev.gpioths.0.%driver: gpioths
dev.gpioths.0.%desc: DHT11/DHT22 Temperature and Humidity Sensor
dev.gpioths.%parent:

So my approach in this case was to complicate my overlays with additional details.
Long filenames but descriptive.
rockpro64-gpioths-dht1-pin18.dtbo
I added an incremented dht* name and GPIO header pin number.
That way I can add and remove individual sensors.
The other approach is to jam them all into one overlay.
But when you want to make a change you must recompile.
I like prebuilt dtbo so I can pick and choose.
All it takes that way is add your precompiled binaries as multiple overlays to /boot/loader.conf
Code:
fdt_overlays="rockpro64-gpioths-dht0-pin16.dtbo,rockpro64-gpioths-dht1-pin18.dtbo,rockpro64-w1-gpio-pin15.dtbo"

Raspberry Pi has that excellent overlay port misc/raspberrypi-userland that offers pre-compiled binary overlays.
Its is a great way to get to work quickly..I try and emulate it on all boards.
 
I had trouble with the HINT based method.
From the handbook:
hint.gpioths._unit_.at
hint.gpioths.pins


The pins setting is missing a required unit number.
hint.gpioths._unit_.pins

hint.gpioths.pins
A bitmask with a single bit set to indicate which gpio pin on the
gpiobus(4) to use for data communications.
I am not sure what a bitmask means here.

The pins do not translate properly like they do with One Wire. ie.. Pin1=1 Pin2=2 Pin3=3

Here is my decoder. Enter this value to obtain the desired pin.
Pin 0= 0
Pin 1= 2
Pin 2= 4
Pin 3= 8
Pin 4= 16
Pin 5= 32
Pin 6= 64
Pin 7= 128
Pin 8= 256
Pin 9= 512
Pin 10= 1024
Pin 11= 2048
Pin 12= 4096
Pin 13= 8192
Pin 14= 16384
Pin 15= 32768
Pin 16= 65536
Pin 17= 131672
Pin 18= 262144
Pin 19= 524288
Pin 20= 1048576
Pin 21= 2097152
Pin 22= 4194304
Pin 23= 8388608
Pin 24= 16777216
Pin 25= 33554432
Pin 26= 67108864

So this is what the /boot/loader.conf setting looks like for 6 sensors.
Code:
gpioths_load="YES"
hint.gpioths.0.at=gpiobus1
hint.gpioths.0.pins=8192
hint.gpioths.1.at=gpiobus1
hint.gpioths.1.pins=262144
hint.gpioths.2.at=gpiobus1
hint.gpioths.2.pins=1048576
hint.gpioths.3.at=gpiobus1
hint.gpioths.3.pins=4194304
hint.gpioths.4.at=gpiobus1
hint.gpioths.4.pins=2097152
hint.gpioths.5.at=gpiobus4
hint.gpioths.5.pins=2097152

Very bizarre the pin number scheme. I took me until pin 9 to recognize the pattern. Much change and try.

This worked on both APU2 and RockPro64.

Code:
# dmesg | grep gpioths
gpioths0: <DHT11/DHT22 Temperature and Humidity Sensor> at pin 13 on gpiobus1
gpioths1: <DHT11/DHT22 Temperature and Humidity Sensor> at pin 18 on gpiobus1
gpioths2: <DHT11/DHT22 Temperature and Humidity Sensor> at pin 20 on gpiobus1
gpioths3: <DHT11/DHT22 Temperature and Humidity Sensor> at pin 22 on gpiobus1
gpioths4: <DHT11/DHT22 Temperature and Humidity Sensor> at pin 21 on gpiobus1
gpioths5: <DHT11/DHT22 Temperature and Humidity Sensor> at pin 21 on gpiobus4

Code:
sysctl dev.gpioths | grep temp & sysctl dev.gpioths | grep humidity
dev.gpioths.5.temperature: 23.2C
dev.gpioths.4.temperature: 23.6C
dev.gpioths.3.temperature: 39.2C
dev.gpioths.2.temperature: 24.1C
dev.gpioths.1.temperature: 23.9C
dev.gpioths.0.temperature: 23.6C
dev.gpioths.5.humidity: 55
dev.gpioths.4.humidity: 57
dev.gpioths.3.humidity: 8
dev.gpioths.2.humidity: 55
dev.gpioths.1.humidity: 52
dev.gpioths.0.humidity: 56
 
Back
Top