nigeljohnson73
Posts: 9
Joined: Wed Nov 20, 2019 11:59 pm

dtoverlay and multiple DHT22/11

Mon Dec 16, 2019 10:42 pm

Hi there, why can't you use dtoverlay to attach more than one DHT11/22 device to different pins?

I don't want to use python or c, I want to use shell script, sorry, its a choice :)

When I'm testing with python and the circuit python stuff it will detect and read my 2 DHT22 devices on BCM pins 18, and 24.

I can use

Code: Select all

sudo dtoverlay dht11 gpiopin=18
and it works fine when I cat the device0files. When I subsequently use

Code: Select all

sudo dtoverlay dht11 gpiopin=24
it fails. If I remove the first one on pin 18, I can then add the one on pin 24. Since I can add multiple w1-gpio I thought this was something specific to the DHT11 overlay.

I did find the DHT22 overlay here: https://github.com/KermsGit/dht22 and this still will not attach as a second device either, as a second DHT22 or as a first DHT22 after adding a DHT11.

Since circuitPython can read multiple devices, why can't the overlay?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2577
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: dtoverlay and multiple DHT22/11

Wed Dec 18, 2019 10:55 am

The reason the overlay can't be loaded multiple types is that there are name clashes. DT nodes and properties are like directories and files, and by trying to instantiate the overlay more than once you are trying to get different versions of some "directories" and "files" to share names. The solution (one that has been used on some overlays) is to generate unique names for the content, which can be done by adding an "address" (an "@<n>") to the end of the node names, and assigning a unique-per-instance value to the address (via the "reg" property). In the case of the dht11 overlay the GPIO number is unique to each instance, so we can use that as the address.

I've modified the dht11 overlay to add addresses to the relevant nodes, and you can download a trial build from here:
https://drive.google.com/file/d/1ccSTIs ... sp=sharing
Copy the downloaded dht11.dtbo to /boot/overlays and you should find you can have several loaded at once.

Because this is a low-risk change it's already been added to our Linux repo, but I'd still appreciate some feedback that it solves the problem for you.

nigeljohnson73
Posts: 9
Joined: Wed Nov 20, 2019 11:59 pm

Re: dtoverlay and multiple DHT22/11

Wed Dec 18, 2019 8:32 pm

Phil, Thanks!!!! I think that has done it. The flakey nature of reading from these devices makes it hard to tell if it's gotten any worse, but, adding the dtoverlay commands adds the iio devices in the correct order as I'd expect and then I can query the temp files.

I did start to get a connection error with one device after letting things sit for 20 minutes, but switching the unit out for a spare seems to have fixed that for now.

Attempting to read them (Separately) but in quick succession seems to be more flakey than usual, is that just the flakiness or is there some shared comms going on? I'm happy to accept regular flakiness :)

The DHT11 overlay does correctly spit out the DHT22 values, which isn't true of WiringPi's C (or Adafruits python) example of calling a DHT11 read on a physical DHT22 so I'm guessing that is handled in the overlay correctly.

Code: Select all

[email protected]:~ $ sudo dtoverlay dht11 gpiopin=24
[email protected]:~ $ sudo dtoverlay dht11 gpiopin=18
[email protected]:~ $ ls /sys/bus/iio/devices
iio:device0  iio:device1
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:16:52 GMT 2019
22300
21100
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:16:57 GMT 2019
cat: '/sys/bus/iio/devices/iio:device0/in_temp_input': Input/output error
21200
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:17:03 GMT 2019
22200
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:17:08 GMT 2019
cat: '/sys/bus/iio/devices/iio:device0/in_temp_input': Input/output error
21200
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:17:13 GMT 2019
22200
21200
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:17:54 GMT 2019
22200
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:18:42 GMT 2019
cat: '/sys/bus/iio/devices/iio:device0/in_temp_input': Input/output error
21200
[email protected]:~ $ date; cat /sys/bus/iio/devices/iio:device0/in_temp_input; cat /sys/bus/iio/devices/iio:device1/in_temp_input
Wed 18 Dec 20:18:57 GMT 2019
22100
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device0/in_temp_input
21900
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device1/in_temp_input
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device1/in_temp_input
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device1/in_temp_input
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device1/in_temp_input
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device1/in_temp_input
cat: '/sys/bus/iio/devices/iio:device1/in_temp_input': Input/output error
[email protected]:~ $ cat /sys/bus/iio/devices/iio:device1/in_temp_input
21100
[email protected]:~ $ 

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2577
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: dtoverlay and multiple DHT22/11

Wed Dec 18, 2019 8:40 pm

I have no experience with the DHT11 devices - the overlay just enables an existing Linux driver and configures its GPIO pin. If it is working at all then the overlay has done its job. Any unreliability is down to something else - the driver, timing jitter, wiring, physics etc.

nigeljohnson73
Posts: 9
Joined: Wed Nov 20, 2019 11:59 pm

Re: dtoverlay and multiple DHT22/11

Thu Dec 19, 2019 5:54 pm

In that case, Happy Nige!!!! :) Thanks again

Return to “Device Tree”