Le Potato with DHT22

Thank everyone used to make a comment on this topic.
I’m trying make DHT11 work too these days on Le Potato, and my platform is raspbian 11 installed on emmc5.0.

To me, I don’t think adafruit_dht under python is possible to work, because I found out that after sending out pull-down signal 18ms to dht11, the corresponding gpio pin takes like 5ms to switch to INPUT status and catch the voltage signals from DHT11. Under such circumstances, a few signals slip away thus the pulses can hardly reach 80 and causes error “a full buffer is not returned”.

After the above struggle, I got inspired by the comment left by angus. I think c can be faster and straightforward unlike python sometimes needs to load functions from other packages. So I started to combine these 2 things I found during my research. FYI, AVR-DHT/Files at master · efthymios-ks/AVR-DHT · GitHub and mraa/include/firmata at 8b1c54934e80edc2d36abac9d9c96fe1e01cb669 · libre-computer-project/mraa · GitHub.

In short, the programmer wrote his own dht library on avr device, and I tried to make it work on le potato board. The current major issue is where to include the files defining digitalwrite/read, bitset, pinmode and etc. for le potato?

Besides, so as to say Arduino IDE, I cannot find compatible board in board manager. I guess I just give up on this approach.

Also, If anyone has made successful readings from dht11 (80%+ plausible data per run) on le potato please guide me here. Thank you.

  1. MCU code will never work with Linux.
  2. DHT11 is already part of the Linux kernel. Check what the driver is doing here: linux/dht11.c at master · torvalds/linux · GitHub
  3. Use device tree overlays (since they use fast kernel drivers and not random userspace libraries). We don’t have any device to test.
  4. DHT11 uses the gpiod_to_irq function so it needs an IRQ enabled kernel.
sudo apt update
sudo apt install linux-image-lc-lts-arm64
1 Like

Thank you for the advices which make me one step closer.
Just some updates at this stage. Desperately seeking for advice and solution.

I tried to write the dts file based on what @angus mentioned above.
As the device tree concept is quite new to me, I tried to compile the dts file by using device-tree-compiler and added the output dtbo file back to customized overlay directory via below cmd,

dtc -I dts -O dtb -o dht11.dtbo dht11-overlay.dts
cat dht11.dtbo > /sys/kernel/config/device-tree/overlays/dht11/dtbo
/* dth11-overlay.dts 
 * Overlay to enable DHT-11/DHT-22 Temperature/Humidity Senor
 * I applied gpiox_7 with default high voltage, i.e. 86 0, as the dts is not including dt-bindings files
 */

/dts-v1/;
/plugin/;

/ {
	compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";

	fragment@0 {
		target-path = "/";
		__overlay__ {
				dht11: dht11@0 {
					compatible = "dht11";
					gpios = <&gpio 86 0>;
					status = "okay";
			};
		};
	};
};

By doing these I can find the corresponding overlay in two places,
“/proc/device-tree/dht11@0”;
“/sys/bus/iio/devices/iio:device1/”;

After all these have been done, I created a Demo.c to see how far I went,

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>


typedef unsigned char u8;
typedef unsigned short u16;

typedef struct	DHT11_SENSOR_DATA
{
	u16 temp;//temperature
	u16 hum;//humidity
}dht11_data;

int main ( void )
{
	int fd ;
	int retval ;
	dht11_data Curdht11_data;
	//fd = open ( "/proc/device-tree/dht11@0/gpios" , O_RDONLY) ;
	fd = open ("/sys/bus/iio/devices/iio:device1/subsystem/drivers_probe" , O_RDONLY);
	if ( fd == -1 )
	{
		perror ( "open dht11 error\n" ) ;
		exit ( -1 ) ;
	}
	//printf ( "open /proc/device-tree/dht11@0 successfully\n" ) ;
	printf("open /sys/bus/iio/devices/iio:device1/subsystem\n");
	sleep ( 2 ) ;
	while ( 1 )
	{
		sleep ( 1 ) ;
		retval = read ( fd , &Curdht11_data , sizeof(Curdht11_data) );
		if ( retval == -1 )
		{
			perror ( "read dht11 error" ) ;
			printf ( "read dht11 error" ) ;
			exit ( -1 ) ;
		}
		if(Curdht11_data.temp != 0xffff)
			printf ( "Temperature:%d.%d C,Humidity:%d.%d %%RH\n",Curdht11_data.temp>>8,Curdht11_data.temp&0xff,\
																 Curdht11_data.hum>>8,Curdht11_data.hum&0xff ) ;
	}
	close ( fd ) ;
}

However, the readings are still incorrect. I’m contemplating those drivers_probe and drivers_autoprobe file under subsystem folder at the moment…

One more thing to add…I just tried drivers_autoprobe
Shall I doubt my dht11 is broken?

EDIT: the dht11.ko has been found and “insmod” on path “/lib/modules/6.1.30-06317-g8f5da1e8aa88/kernel/drivers/iio/humidity” which is the current running kernel.

Some relevant dmesg log:

# successfully added the driver to the device tree;
# no info for cmd insmod dht11.ko, but lsmod does work (refer to the above screenshot);
[  148.509641] gpio irq setup: hwirq: 0x60 irqfirst: 0x59 irqlast: 0x6B pin[86].
# failed to cat files like in_temp_input/in_humidityrelative_input
[  290.463030] genirq: Setting trigger mode 3 for irq 51 failed (meson_gpio_irq_set_type+0x0/0x60)
[  312.326090] genirq: Setting trigger mode 3 for irq 51 failed (meson_gpio_irq_set_type+0x0/0x60)
[  465.180711] genirq: Setting trigger mode 3 for irq 51 failed (meson_gpio_irq_set_type+0x0/0x60)
  1. Use the libretech-wiring-tool ldto infrastructure rather than manually doing it.
  2. Use the proper GPIO defines for the overlay rather than manually calculating it yourself.
  3. The overlay should probe the driver and load the module automatically when enabled or merged.

This means that it’s not able to set the GPIO IRQ to count the pulses so you would not get valid data. Try using a GPIOAO pin.

Hello,

  1. tried compiling it through the libretech-wiring-tool tool
  2. modified dts file to include the dt library.
  3. tried pins like GPIOX_7/GPIOCLK_0/GPIOAO_5. For gpioao it was failed at creating overlay
  4. used ldto cmd to enable dht11.

    GPIOX_7 or GPIOCLK_0:
    failed at cat /sys/bus/iio/devices/iio:device1/in_humidityrelative_input

    GPIOAO_5:
    failed at creating the overlay

    I then tried ldto enable w1-gpio
    and checked the dmesg log showing successfully installed.
    Below screenshots for comparison;

So, my decision is to give in the device dht11 and turn to ds18b20 this time since w1-gpio overlay is embedded and no need for me to create anything myself.

  1. GPIOAO uses the &gpio_ao alias rather than &gpio.
  2. See how it’s done here: https://github.com/libre-computer-project/libretech-wiring-tool/blob/master/libre-computer/aml-s905x-cc/dt/pps-gpio-7j1-12.dts
  3. DHT11 default kernel code seems to require interrupt on both edges. That’s why it wasn’t working for you. Amlogic platforms have difficulty with double edge interrupt triggers since it needs to set two triggers (one for rising and one for falling). We’re researching this to see if we can resolve.
2 Likes