Hardware Reference
In-Depth Information
Let me show you what the two lines of text mean. Each line can be broken up into segments.
The first segment of nine hex values is what is directly read from the device. You really don't
need to pay attention to this value on either of the lines.
The next segment on the first line is
CRC=43 . This is the checksum value of the data that has
been read from the DS1820B. The last section on the first line is YES . This means the checksum
matches and your data are valid. If you do encounter a NO value here you can no longer trust
any of the information from the sensor and it would be wise to replace the sensor.
On the second line you have the hex values, as in the first line.
t= , which means temperature equals. Last up you have “29875”
in my example. Since this is a high-precision device this measurement actually means
29.875 ° C. (It's a little warm sitting under my 30-inch LCD.)
Something simple like this will get you the temperature:
Then the second part of this is
# cat /sys/bus/w1/devices/10-0008027e34ca/w1_slave | grep t= | cut -c 30-31
This should just give you back the first two digits. Later on in this chapter I will show you a simple script to
monitor the sensor or log the values to a file.
By default Linux won't autoload the w1_gpio and w1_therm modules. If you want your 1-wire device to
automatically appear on reboot you're going to need to set up a module autoload file. This will be the same process
you used in Chapter 2. Create a file called 1w-therm.modules in the /etc/sysconfig/modules directory. Enter the
following into the file:
#!/bin/bash
lsmod | grep -q w1_gpio || /sbin/modprobe w1_gpio >/dev/null 2>&1
lsmod | grep -q w1_therm || /sbin/modprobe w1_therm >/dev/null 2>&1
Save the file and reboot. Now your 1-wire device will be detected on boot on the Raspberry Pi.
Using the Big Blue DHT11
Now you have seen what the DS1820B can do and how easy it is to use. I now want to show you how the DHT11 can be
used. It's not as easy to use under Linux as the DS1820B but it can be done. Take a look at the electronic schematics in
Figure 3-18 . You'll notice it's a very simple connection for this sensor.
vcc
DHT11
1
2
Pi GPIO
3
4
Figure 3-18. Electronic schematics for the DHT11
You can see that you still need a pull-up resistor. It's not a 1-wire device, but it works in a similar way in that the
DHT11 expects the data line to be high at all times; it can then pull it low when required.
 
Search WWH ::




Custom Search