Using the BMP180 to record air pressure and temperature
I2C
To enable the I2C bus on the Raspberry Pi you need to load the appropriate drivers. Unfortunately you can't do this from raspi-config
, but you can install them manually. Using root privileges, edit the /etc/modules
file and add the two lines from Listing 1. Next, add the two lines in Listing 2 to the /boot/config.txt
file using sudo
.
Listing 1
Add to /etc/modules
i2c-bcm2708 i2c-dev
Listing 2
Add to /boot/config.txt
dtparam=i2c1=on dtparam=i2c_arm=on
Update the software on your Rasp Pi, then install the I2C tools (first three lines of Listing 3) and add user pi to the i2c user group (Listing 3, last line). This will avoid having to elevate your user privileges from now on every time you access the bus. Finally, reboot the Raspberry Pi and make sure the BMP180 is registered on the bus. During testing, I found this worked right away (Listing 4).
Listing 3
Download Tools and Add pi User to i2c User Group
$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install i2c-tools $ sudo adduser pi i2c
Listing 4
Check that BMP180 Is Connected to Bus
$ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- 77
Measurements
Previously in this series of articles on the I2C bus, you learned different ways to access the I2C hardware. This time, I'm taking a new approach by using a kernel module designed for the BMP085, the predecessor to the BMP180. It works perfectly but isn't pre-installed in the standard kernel. In view of this, you need to build a separate kernel that includes it.
Any readers who have ever tried to build the kernel before will know how long it takes. If you're building on the Raspberry Pi, you might need to let it run overnight (or see the "Handy Tip" box).
Handy Tip
You can cross-compile the new kernel much faster by using a desktop computer running Linux, then installing it on the Raspberry Pi.
This article uses a previous version of Raspbian, so some of the details might vary if you try it with the latest version. First install and unpack the kernel sources (Listing 5), which can take some time depending on your connection speed. The files are around 1.2GB.
Listing 5
Download Raspbian Kernel
01 $ cd /usr/src/ 02 $ sudo mkdir kernel 03 $ sudo chown pi:pi kernel/ 04 $ cd kernel 05 $ git clone https://github.com/raspberrypi/linux.git 06 $ cd linux 07 $ cp /proc/config.gz ./myConfig.gz 08 $ gunzip ./myConfig.gz 09 $ sudo apt-get install bc libncurses-dev 10 $ make menuconfig
Building a kernel from scratch is quite an arduous task, so copy the configuration from your current system and build on that instead (Listing 5, lines 7-8). Before you begin the build, install some additional tools (Listing 5, line 9) so the process will run smoothly. You can then start configuring your new Linux kernel (Listing 5; Figure 2).
First, load the current configuration with Load (Figure 3), then select the driver for the sensor with Device Drivers | Misc devices | BMP085 digital pressure sensor on I2C (Figure 4). The asterisk (*) shows that the driver is integrated into the kernel; use [M] to create a module. Now save the new configuration in .config
with Save, so the make
command will find it (Figure 5). Finally, exit the program by selecting Exit.
You can now start building the kernel. You can speed up this process by using all four cores on the Raspberry Pi. To do this, run make
with the option -j4
, which corresponds to the number of cores. The process takes around four hours.
After Make has built the complete kernel, use the modules_install
parameter to create the boot image and install the appropriate modules.
« Previous 1 2 3 4 Next »
Buy this article as PDF
Pages: 6
(incl. VAT)