Hardware Reference
In-Depth Information
gcc -o Adafruit_DHT Adafruit_DHT.o -std=c99 -I. -lbcm2835
[root@hobo pi-dht11]#
Do an ls on the current directory and you will now see an application called Adafruit_DHT , which is the
application that will read from our sensor. The Adafruit_DHT application expects to receive two command-line options.
The first option is what type of sensor it will be communicating with. In your case that will be
the DHT11, so the first option will simply be 11 .
The last option the
Adafruit_DHT application expects is the GPIO pin number. This is not the
physical pin number but the logical GPIO pin reference number. Recall that you connected the
data line of the DHT11 to pin P1-11: this is GPIO17.
Now that you have the required information to run the application, run it with the following command:
# ./Adafruit_DHT 11 17
This should produce something like what you see in Figure 3-25 .
Figure 3-25. Output of the Adafruit_DHT application
The output of this application has three lines.
The first line tells you what GPIO pin it's using.
The second line is the raw data that the application received. The last line shows the important
part: the temperature and humidity.
There is one odd thing you must remember about the DHT11. The sensor itself can only ever respond to a
temperature and humidity reading request every two seconds or more. If you try to ask it more frequently you will get
the output you see in Figure 3-26 . It's not an error; there just are no data. You'll notice there is no third line. Give it
a few seconds and ask again.
Figure 3-26. No data received from the DHT11
The Adafruit_DHT can be run anywhere on your Raspberry Pi. I personally like to move it to /usr/local/bin as
this complies with the Unix filesystem layout, but feel free to place it wherever you want. Because /usr/local/bin
is in your path you won't need to specify the full path to the binary when you run it. Here is a neat little one liner for
placing the temperature and humidity readings on a separate line:
# Adafruit_DHT 11 17 | grep Temp | tr "," "\n"
This will give you the readouts on separate lines. Nice and pretty!
 
Search WWH ::




Custom Search