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

Re: Adafruit DHT temp/humid sensor

Thu Feb 26, 2015 11:29 am

Did you check my post

http://www.raspberrypi.org/forums/viewt ... 06#p672406

the script readTemp.py already output a file called /webdata/CurrentData.txt


If you want to display just the temperature on a webpage. just modify the script to create an html page instead

if you add this code into the readTemp.py around line 146 , just after I wrote CurrentData, you will have a crude html webpage indicating the current temperature.

Code: Select all

#### create an simple html page

TempWebPage =  "/usr/share/nginx/www/temp.html"

try:
  file = open(TempWebPage,"w")
  file.write("<html><head><title>Current Temperature</title></head><body><h1>")
  file.write("Temperature : {} &#x2103;<br>".format(TempS(sensorData[0])))
  file.write("Humidity    : {} %<br>".format(TempS(sensorData[1])))
  file.write("</h1></body></html>")
  file.close
except:
   pass
Just change TempWebPage to fit your browser.

B.T.W. I'm using HighCharts, so it is possible to use a meter from High chart to indicate temperature.

Check Frames in html. This way you could show your chart and the current Temperature on the same window but on different frame.

Daniel

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

Re: Adafruit DHT temp/humid sensor

Mon Jan 02, 2017 4:36 pm

By now this is a pretty old post, but I think still valuable if you are trying to use the DHT11, DHT22 or the AM2302.
Previously, I only worked with the DHT22 and the AM2302.
Just for the sake of completeness, I installed the spidev driver on the latest kernel, and the only thing that changes is the fact that modprobe is different. To activate the spi support now, you now need to edit the /boot/config.txt file, and take the "#" away in front of the following line :

Code: Select all

dtparam=spi=on
, or use raspi-config to enable the driver. Reboot to load the driver.

While starting to work with an ESP-8266 that I purchased together with a DHT Hat, I found out that they delivered a DHT11.
I had not used that particular sensor yet so I first wanted to use it with my previous code for the DHT22 and the AM2302, but had some trouble getting this DHT11 to work properly.

It turned out that this device is a little slower in responding, and the data it returns just did not fit into the array that is used to capture the burst from the device. I ended-up changing only one line in the code to make it work again.

In the class definition, you need to change the following line from :

Code: Select all

MaxBits = 0.010 * self.speed
to :

Code: Select all

MaxBits = 0.012 * self.speed
It creates a larger array, and with this, the returned data fits, so the code works again.

I also found out that the DHT11 does not work with the Pi 3V3 supply. When I switched to the 5V supply, everything worked flawlessly. BTW, as you will read in my other posts, I always use a 1K pull-up. The 4K7 or 5K1 is simply not good enough and the signal quality is much better with 1K. There is no harm possible for the GPIO pins, but as a precaution, you can use a 1K resistor in series with the MISO pin. The MOSI already has a diode to drop the voltage a little.

If you want to know more about the DHT sensors, have a look at my detailed post about these devices. viewtopic.php?f=37&t=91326
Enjoy!

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 12 guests