DHT22 on VIM3 Pro (With Ubuntu 20.04)

Hello everyone! I’m trying to configure my DHT22 on my VIM3 Pro v14.
I’m using Ubuntu 20.04 with kernel 4.9.241, Python 3.13.

How can I do it?
Thank you! :smiley:

@SpheLC Hello there, Welcome to the community!

DHT22 Uses the one wire protocol to communicate, which the VIM3 supports.
There is no python library that unfortunately supports interfacing with it directly, so you will need to go into the system bus (sys/bus/w1) to see your device get detected and be able to read the data.

Please check out the documentation and see if you can read/get data from your module.
https://docs.khadas.com/products/sbc/common/applications/gpio/1wire

Cheers

Hi, thank you for the answer!
I tried to enable One Wire Bus writing on /boot/env.txt but, in the /sys/bus/w1/devices/ directory, there is only the w1_bus_master1 folder, nothing else

Istantanea_2023-08-22_11-20-45

@SpheLC could you confirm all the hardware is proper, wiring to the correct pin and including the necessary pull up resistor ?

Yes, the wiring is right. Sometimes it shows another folder, called 00-a80000000000, but when I go inside it, it shows this:

Istantaneja_2023-08-22_11-20-45

Not aware why that could be, I don’t have a module to test with, unfortunately.

You can maybe try this example module: GitHub - edwardlintw/DHT22: Linux Kernel Driver of DHT22 Humidity and Temperature Sensor

note: you will need to remove the onewire attribute from /boot/env.txt which you placed earlier, and also change the DEFAULT_GPIO to 433 as mentioned by the GPIO description in the dht22.h file

diff --git a/dht22.h b/dht22_new.h
index 4334117..7eb29f4 100644
--- a/dht22.h
+++ b/dht22_new.h
@@ -16,7 +16,7 @@
 #ifndef _DHT22_H
 #define _DHT22_H
 
-#define DEFAULT_GPIO            4
+#define DEFAULT_GPIO            433
 #define DEFAULT_AUTOUPDATE_SEC  10          /* re-trigger DHT22 after 10 sec */
 #define AUTOUPDATE_SEC_MIN      3           /* 3 seconds */
 #define AUTOUPDATE_SEC_MAX      60000       /* 10 min */

Hardware need not be changed.

It needs some changes on some paths, and I don’t know what I need to put there.
This driver is made for the Raspberry Pi 3, I prefer to have a driver for Khadas VIM3.
If there is a way to decode the temperature and humidity only with Python, that will be fantastic!

Istantanea_2023-08-22_11-20-45

@SpheLC The driver can work on VIM3 as well, it’s only basis is on linux kernel driver so it has no issue.

Here is updated Makefile path:

obj-m += dht22.o

KDIR = /lib/modules/$(shell uname -r)/build
CC=gcc
ccflags-y=-Wno-error

all:
	make -C $(KDIR) M=$(shell pwd) modules

poll: poll.c
	$(CC) -o poll -lc -lpthread poll.c

clean:
	rm -rf *.o *.ko .*cmd .tmp* core *.i *.mod.c modules.* Module.* poll

you can replace this in the given makefile and compile all on the vim3 itself, make sure to run sudo apt-get install build-essential to make sure you have all the necessary compilers and tools.

To make the sample polling app, to test if your configuration works perfectly, do
make poll && ./poll

Ok, Thank you!
There is one problem, if I run sudo apt-get build-essential it tells: E: Invalid build operation

I think I only need to run the Makefile

My apologies, I will update that command and makefile soon.

update:
@SpheLC please check if it works now.

@SpheLC can you check that uart3 attribute is not present in /boot/env.txt under overlays.
After that please check the original guide under onewire protocol from docs and see if anything appears under /sys/bus/w1/devices/.

There is no need to apology! ;]

By the way, it doesn’t work if even without “uart3”, I already tried

Ok, in that case I will have to check it with a module and report from my side soon.

Oh, I see now that you’ve edited the message! It gives me an error when I do make poll && ./poll:

gcc -o poll -lc -lpthread poll.c
/usr/bin/ld: /tmp/cctnmRaU.o: in function `main':
poll.c:(.text+0x8c): undefined reference to `pthread_create'
/usr/bin/ld: poll.c:(.text+0xc4): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make: *** [Makefile:11: poll] Error 1

Hi, do you have news?

Hello @SpheLC
I will share a device tree overlay to try shortly.

Regards.

@SpheLC can you try this example ?

You can use pin 13 of the VIM3’s GPIO and make this change in the code

-- static int DHTPIN = 7;
++ static int DHTPIN = 1;
$ gcc dht22.c -o dht22 -lwiringPi -lpthread -lrt -lm -lcrypt
$ ./dht22

Ok, I connected the DHT22 to the pin 13 (it is called SPDIF_OUT) and it outputs this:
immagine
I did all the steps but it seems to not work… I’m thinking that my VIM3 is broken lmao.

I think that there is some setting somewhere to change.

@SpheLC I have tried on my side with my DHT22 module, but I was not able to register the module to work properly. I need to investigate the issue for this later but it seems very hard to work with this module’s communication protocol.