Hardware Reference
In-Depth Information
One of the nice features of the DS18B20 sensor is it has a unique number that allows you to
use multiple sensors and uniquely identify the temperature of each sensor. he preceding
command interfaces with the sensor and retrieves the temperature, which it then writes to a
new directory on the Raspberry Pi. his directory can be found in /sys/bus/w1/devices/ .
In order to check if this ile was created, you can do a directory listing by typing the following
command:
ls /sys/bus/w1/devices/
You should see a directory that correlates to the unique number of your sensor. Every sensor
has a unique number, so it won't be the same as my ile, but it will be similar to this:
28-0000040be5b6
If you don't see a directory with lots of numbers and letters like this one, then do the following:
Check your circuit wiring.
Make sure that you have the correct resistor. (his is very important - yellow, violet,
red, gold.)
Feel the temperature gauge with your inger. If it feels hot, you have it wired back to
front.
If you do see the new directory, navigate into it and view the contents of the w1_slave ile,
which will contain the temperature value. (Remember to replace my number with yours.)
cd /sys/bus/w1/devices/28-0000040be5b6
nano w1_slave
You will now see the contents of the w1_slave ile, which contains the temperature data in
Celsius. In my example (see Figure 13-10), the temperature is 20.812 degrees Celsius. Press
Ctrl + X, followed by N, to exit.
Now that you have completed testing your circuit and have the sensor working, you will
write some Python code to automate the preceding and print the temperature to the screen,
as shown in Listing 13-2.
Search WWH ::




Custom Search