EZKernel
Posts: 19
Joined: Sat May 25, 2019 4:39 pm

DHT22/AM2302 and I/O conflicts

Sat May 25, 2019 5:02 pm

Hi all, sorry that I am asking for help on my first post but I thought I might as well say hi. My background is in finance, accounting and data analysis so I know very little about electrical engineering and safety, I have done an energy physics course in university and that is not saying much. I do know python though and that's really what drew me to the raspberrypi.

I have setup a camera and a picamera script which loads the camera, and takes a shot every 5mins saving to SD card.
I also have another multiprocess script which tracks sensor states every .3 sec it is multiprocessed because I am getting readings from 6 different sensors (AM2302 being the troublesome one) and I am setting custom cooldowns on how often I can trigger a sensor read. AM2302 normally gets readings flawlessly. However, if any application or module start from what I understand accessing the SD card then my AM2302 returns a bogus reading of 3000%. This also happens if I try to convert the JPG taken by the picamera to GIF using wand/imagemagick on another script.

I bought a AM2302 module off of amazon, on a board with a 4.2k resistor and a capacitor, I put another 3x 2k resistors in series on the breadboard between 3.3v and data. It runs off of 3.3v and wire is quite long, I am using CAT6 for the bulk of the length.

The sensor is supposedly digital so in my understanding it should not be affected by my sd writes?

Any help would be appreciated

EZKernel
Posts: 19
Joined: Sat May 25, 2019 4:39 pm

Re: DHT22/AM2302 and I/O conflicts

Sun May 26, 2019 9:54 pm

after more research I have realised the problem is occurring because the sensor requires accurate and co-ordinated timing from the CPU in order to sample the data; when the CPU is used by other processes priority is lost and out comes an incorrect reading.

I have found these solutions.

someone wrote this C poller that works very well.
https://github.com/seblucas/lol_dht22

there are 3 more individuals that have written kernel drivers (.ko files)
https://github.com/Filkolev/DHT22-sensor-driver
https://github.com/KermsGit/dht22
https://github.com/edwardlintw/DHT22

however, I've come to a roadblock in setting up the correct environment before compiling these kernel modules. I am currently on 4.14 and I keep getting different errors from all the makes on the 3 links. The binary module does not load as it is incompatible with the kernel I am using.

If anyone could point me in the right direction as to how to compile these modules using the oldconfigs for the current kernel it would be most appreciated.

User avatar
joan
Posts: 14187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: DHT22/AM2302 and I/O conflicts

Sun May 26, 2019 10:08 pm

You are probably solving the wrong problem. I'd use a different sensor (e.g. BME280, Si7021 etc.) that works on the I2C bus.

I doubt that the kernel modules will be any better than user space modules at reading the DHT22.

Have a look at my user space http://abyz.me.uk/rpi/pigpio/examples.html#pdif2_DHTXXD (requires the pigpio daemon to be running). I doubt you will find anything more reliable.

EZKernel
Posts: 19
Joined: Sat May 25, 2019 4:39 pm

Re: DHT22/AM2302 and I/O conflicts

Sun May 26, 2019 11:26 pm

thanks for your reply Joan, I was figuring if they were kernel level processes they would get absolute process priority and others in the forums have said that it had worked for them. I agree with you that this sensor sucks. I actually ran across your website when someone compared it to lol_dht as well as a daemon built off of lol_dht - I was blindsighted by the kernel module and really wanted to learn the nitty gritty of compiling from scratch and debugging but that may be beyond my scope. I will try your solution tonight and post my results while I wait for another sensor as you have suggested

Return to “Troubleshooting”