Hardware Reference
In-Depth Information
• Twist the ends of the two wires together, then seal them with electrical tape (or
hot glue).
• Crimp the wires together using a crimping tool.
No matter which method you use, you'll probably need to strip off some of the insu-
lated connector covering the wires. You really should use a wire stripper for this, and
not try to use a pair of scissors (or the cutting part of a pair of pliers), because you run
the risk of cutting off part of the wire itself.
Once you have these three wires connected and properly inserted into your bread-
board (with a Pi Cobbler connecting it to your Raspberry Pi GPIO ports), you can install
the software to test it out.
On your Raspberry Pi, clone a copy of the Adafruit Git Raspberry Pi repository:
$ git clone git://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
$ cd Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver
Even though the name of this repository is Adafruit-Raspberry-Pi-Python-Code , you
will notice that the code in this directory is in C. Adafruit had to use C code to talk to
the AM2302 sensor since it requires extremely fast timing to read, and Python would
not be able to easily accomplish this task.
Adafruit includes a precompiled binary that should work on any distribution of Linux
for the Raspberry Pi, but if you do not trust their binary (or it doesn't work for some
reason), you can rebuild it. Just have gcc and make installed, and run:
$ rm -f Adafruit_DHT
$ make Adafruit_DHT
Either way, you need to run the Adafruit_DHT binary. To talk to the AM2302 sensor on
BCM Pin 4, run:
$ su -c './Adafruit_DHT 2302 4'
Using pin #4
Data (40): 0x2 0x16 0x0 0xe6 0xfe
Temp = 23.0 *C, Hum = 53.4 %
The first option passed is the sensor type (this code also supports interfacing with a
raw DHT11 (11) and DHT22 (22) in addition to the AM2302 (2302)). The second option
is the GPIO pin that it is connected to. You can see that it is reporting a temperature
of 23.0°C and a humidity of 53.4%.
You now have a reliable way of measuring the data from the AM2302. Adafruit has
also included a Python script ( Adafruit_DHT_googledocs.ex.py ), which will run the
Adafruit_DHT binary every 30 seconds, and upload the humidity and temperature
readings into a Google Docs spreadsheet.
Search WWH ::




Custom Search