maradona88
Posts: 7
Joined: Thu Jun 04, 2015 10:29 pm

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Thu Jun 04, 2015 10:48 pm

Hi,
I am using RHT03 temperature sensor with my Raspberry Pi 2, and I cannot make it work properly.
As for wiring, I used the same schematic as for DHT22, as they are similar(correct me if I am wrong).
Pin 1:VCC - 3.3V
Pin 2: Data - GPIO26 (Pull up resistor to 3.3V - 10k)
Pin 3: NC
Pin 4: Ground

Also, I used code from : https://github.com/adafruit/Adafruit_Python_DHT

I unpacked the archives, installed it and when I run some of the examples I get:
Failed to get reading. Try again!

I am newbie in working with PI, so maybe I am missing something.

I would appreciate any help.

danjperron
Posts: 3526
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Fri Jun 05, 2015 11:20 am

Try to follow my one step by step post.

On this one I used Joan's pigpio with a slight change to implement the DHT11 but you could used Joan's DHT22 directly.


viewtopic.php?p=672406#p672406

maradona88
Posts: 7
Joined: Thu Jun 04, 2015 10:29 pm

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Tue Jun 09, 2015 9:32 pm

danjperron wrote:Try to follow my one step by step post.

On this one I used Joan's pigpio with a slight change to implement the DHT11 but you could used Joan's DHT22 directly.


viewtopic.php?p=672406#p672406
Thanks for your help.
I had a bad wiring, so that was the problem...
Btw, I want to make three boards with RHT03 and I got two of them to work but third not. These are three same boards, I checked the wiring now and there is no mistake now.
Two RHT03 work fine but the third one no. I don't get any response from RHT03. How can I tell if RHT03 is dead?
Is it possible that I need to change something on that third one, like pull-up resistor, VCC to 5V?

Best regards!

danjperron
Posts: 3526
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Wed Jun 10, 2015 1:00 am

On power up the sensor needs to have the data line high.

If the data line is low on the first ~3 seconds, it won't work!

brownleeb
Posts: 3
Joined: Sun Oct 12, 2014 8:37 pm

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Mon Jun 15, 2015 1:09 pm

I have been trying to find solutions to the DHT22 on an RPi for some time.
Joan's pigpio service was working great, and while I had other issues with my system that limited my reliability, I very rarely had any hangs or problems.
I wanted to point out tho that Gordon has added RHT03 code into the wiringpi examples (not sure when), and I have found it quite reliable (so far). The benefit in my case is that it eliminates the need for pigpiod and that overhead.
I was easily able to write a python wrapper to be able to call the function.
I should provide the caveat, I am using a Pi 2. Have not yet tested elsewhere.

paulv
Posts: 564
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Mon Jun 15, 2015 2:44 pm

If you care to post the python code of your wrapper, some of us can test it on other Pi's.

brownleeb
Posts: 3
Joined: Sun Oct 12, 2014 8:37 pm

Re: Detailed Description of the RHT03 / DHT22 / AM2302 senso

Mon Jun 15, 2015 4:28 pm

I hesitate to post this, because I am just such a terrible C programmer. :oops:
I'm not embarrassed to say that I am still trying to figure out the code, but I know it works.
Also, I am running the current version of Arch.
uname -a
Linux home 3.18.14-2-ARCH #1 SMP PREEMPT Thu May 28 07:19:33 MDT 2015 armv7l GNU/Linux
Anyway, happy to provide food for thought.

Code: Select all

#include <Python.h>
#include <wiringPi.h>
#include "maxdetect.h"
#define TRUE 1
#define FALSE 0
static int initialized=FALSE;

static PyObject* py_readDHT(PyObject* self, PyObject* args)
{
  int newTemp, newRh ;
  int pin, ret;

  if (!PyArg_ParseTuple(args, "i", &pin)) {
    return NULL;
  }

  if (!initialized)  {
     wiringPiSetup();
     piHiPri(55);
     delay(100);
     initialized=TRUE; }
  for (;;)  {
     ret=readRHT03 (pin, &newTemp, &newRh);
     if (ret && (newRh <= 1000))
        {break;}
     sleep(2);
  }


  return Py_BuildValue("iii", ret, newTemp, newRh);
}

static PyMethodDef readDHT_methods[] = {
  {"readDHT", py_readDHT, METH_VARARGS},
  {NULL, NULL}
};

void initreadDHT()
{
  (void) Py_InitModule("readDHT", readDHT_methods);
}
some background:
The function returns temperature and humidity as integers, they need to be divided by 10. Temperature is measured in Celsius.
On occasion, I get a good return code, but invalid results. I test the RH value to put a sanity check on the numbers.
I added the delay on re-reading the sensor to avoid possible sensor lockup. I commented out the loop in readRHT03 (maxdetect.c) to manage re-reads myself as my code seemed to be returning 'lastResult' too frequently.
As with other methods, probably need to discard first reading to get to most recent values. This doesn't appear to have been done in Gordon's code.

The python code is simple:

Code: Select all

from readDHT import *
ret, temp, hum = readDHT(pin)
where 'pin' is the WiringPi pin number (or generally, GPIO number).
Make sure readDHT.so is in the python search path.

Finally, the compile commands. Compile maxdetect (if you comment out the loop) using:
gcc -fPIC -c -lwiringPi maxdetect.c
and rht03.c with:
gcc -fPIC -shared -o readDHT.so -I/usr/include/python2.7/ -lpython2.7 -lwiringPi rht03.c maxdetect.o
Adjust for your version of python, etc...

Return to “Automation, sensing and robotics”