User Tools

Site Tools


linux:installing_dh22_temp_sensor

Installing DH22 Temp / Humidity Software

Make sure you are updated:

sudo apt upgrade

Install the required packages:

sudo apt install build-essential python3-dev python3-openssl git

cd into Downloads and clone the repo:

cd Downloads
git clone https://github.com/adafruit/Adafruit_Python_DHT.git && cd Adafruit_Python_DHT

Now create a Python library with:

sudo python3 setup.py install

Change the directory to the examples directory:

cd ~/Downloads/Adafruit_Python_DHT/examples/

run the example with code:

sudo ./AdafruitDHT.py 22 4

if it does not work, python might not be in the past. Try this:

sudo python3 AdafruitDHT.py 22 4

The first parameter indicates which sensor was used (22 for the DHT22) and the second indicates which GPIO it is connected to. In this example, we've connected the DHT22 to GPIO 4:

Should look like this:

Temp=25.0*  Humidity=45.7%

Uncomment line 44 of AdafruitDHT.py to convert the temperature to Fahrenheit.

vi ~/Downloads/Adafruit_Python_DHT/examples/AdafruitDHT.py

For Fahrenheit Change this:

#temperature = temperature * 9/5.0 + 32

to this

temperature = temperature * 9/5.0 + 32

run the example with code again:

sudo ./AdafruitDHT.py 22 4

if it does not work, python might not be in the past. Try this:

sudo python3 AdafruitDHT.py 22 4

It should now look like this:

Temp=79.2*  Humidity=43.6%

Then copy AdafruitDHT.py to /usr/local/bin

sudo cp AdafruitDHT.py /usr/local/bin/

You should now be able to run AdafruitDHT.py 22 4 from any directory

AdafruitDHT.py 22 4

if it does not work, python might not be in the past. Try this:

sudo python3 AdafruitDHT.py 22 4

Now ready to start scripting

linux/installing_dh22_temp_sensor.txt · Last modified: 2024/10/01 13:58 by 127.0.0.1