Using the BMP180 to record air pressure and temperature

Install the kernel

To install the new kernel, copy it to /boot. To avoid confusing the new kernel with the current one, rename it (e.g., to kernelx.img):

$ sudo cp arch/arm/boot/Image /boot/kernelx.img

You now have to instruct the bootloader to use your custom-built kernel next time you start the Pi. You can do this by opening /boot/config.txt and inserting the line kernel=kernelx.img at the very top. You'll need root privileges to do so.

Before booting, test which kernel is running (Listing 6), because it would be a real pain if after all your efforts your Pi booted using the old kernel. After you've restarted, run uname -a to check that the new kernel is running. If all goes to plan, it's time to focus on the sensor.

Listing 6

Check Kernel Version

$ uname -a
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2017 armv7l GNU/Linux

If anything goes wrong, insert the Pi's microSD card into a reader connected to a PC and undo the changes you've made to /boot/config.txt. The Pi will then reboot using the old kernel.

Testing the sensor

Before starting the test, take a look at the current configuration of the I2C bus. The sensor should still be located at address 0x77h (Listing 7). Next, tell the kernel that the BMP180 is located at this address on the bus:

Listing 7

Output of i2cdetect (Sensor Address)

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
$ sudo echo bmp085 0x77 > /sys/bus/i2c/devices/i2c-1/new_device

Next, examine the bus configuration as a normal user. The address 0x77h now is listed as UU (Listing 8). This means the kernel has loaded the driver at this address. The other two devices you can see in the output for i2cdetect are also registered with the new kernel, but you can ignore these for the time being.

Listing 8

Output of i2cdetect (Bus Configuration).

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- UU

The driver creates two devices that you can read easily. Note that you must divide the value for the temperature by 10 and the value for the air pressure by 100 (Listing 9, lines 1-2). To make testing easier, use the command from the third line.

Listing 9

Output of I2C Sensor (Temperature and Air Pressure)

$ cat  /sys/bus/i2c/devices/1-0077/pressure0_input
99835
$ cat  /sys/bus/i2c/devices/1-0077/temp0_input
256
$ watch cat /sys/bus/i2c/devices/1-0077/*_input$

The driver will create two devices that you can measure easily. Note that you must divide the temperature value by 10 and the air pressure value by 100 (Listing 9, first two lines of output). Use the third command to simplify testing.

If you know your altitude roughly, you can use the table at the start of this guide to see if the air pressure output is plausible. To test the temperature sensor, you could just place your finger on it to see if in increases. Alternatively use a freeze spray to cool it to below zero in a matter of seconds [2].

Investing in a can of freeze spray is useful not just to test your temperature sensor: Broken transistors have been known to work again after a deep freeze – but only for as long as the semiconductors remain cool. However, it does allow you to identify defective components.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content