0%

# BMP180

Pressure and Altitude, Temperature

## What is I2C?

I2C (eye-squared-cee) is a communication protocol that the Raspberry Pi can use to speak to other embedded devices (temperature sensors, displays, accelerometers, etc). In this example, we’ll be connecting a BMP180 Temperature/Pressure Sensor to our Raspberry Pi.

I2C is a two wire bus, the connections are called SDA (Serial Data) and SCL (Serial Clock). Each I2C bus has one or more masters (the Raspberry Pi) and one or more slave devices, like the I/O Expander. As the same data and clock lines are shared between multiple slaves, we need some way to choose which device to communicate with. With I2C, every device has an address that each communication must be prefaced with. The temperature sensor defaults to an address of 0x77. Remember this number as we’ll see it shortly when we try to detect the chip using i2cdetect.

The Rasperry Pi has two I2C buses. One is available on the GPIO (P1) header, the other is only available from the P5 header. To access the P5 header, you’ll need to solder on your own header pins. This is generally unnecessary as you typically only need a single I2C bus.

## Preparing RPi for I2C

### Activate I2C Drivers

On your Raspberry Pi, you must first enable the I2C drivers.

1. Run sudo raspi-config
2. At the menu, choose option 5. Interfacing Options
3. Select P5 I2C and then say “Yes” to enable the I2C driver and “Yes” again to load the driver by default
4. Reboot your Raspberry Pi by running sudo rebootback at the command line

Then from the prompt run:

Confirm that the i2c modules are loaded and active:

Install some i2c utilities:

i2c-tools includes some cool utilities, like i2cdetect, which will enumerate the addresses of all slave devices on a single bus. Try it out by running sudo i2cdetect -y 1 with the sensor connected. Another utility, i2cdump lets you query the state of individual settings (registers) on a specific I2C device. This is the output you should see with the sensor connected as below, and configured for the default address of 0x77:

### Reading values from the BMP180

First we’ll need to install some utilities for the Raspberry Pi to communicate over I2C inside of Python.

Next, place the following into a Python script and run it.

## FAQ

• Question: When I run the script, I get the following error:

• Answer: Ensure you have loaded the i2c_bcm2708 and i2c-dev modules using lsmod. If they are not present, follow the instructions at the top of the page to modify the files in /etc/modules

• Question: When I run the script, I get the flollowing error:

• Answer:sudo i2cdetect -y 1 should report a device on address 0x77 (the bmp180). If not check the connections between the PI and bmp180.

## References

• Streaming Data with Plotly

# I2C总线控制BMP180

BMP180压强传感器操作原理比较简单，开机先通过I2C读取出AC1,AC2,AC3,AC4,AC5,AC6,B1,B2,MB,MC,MD等寄存器的值，这些寄存器的值作为校准时使用。如何读取温度寄存器，压强寄存器的值，根据下图公式算出测得的当前温度和压强。

# 海拔和气压的转换公式

$P={P}_{0}{\left(1-\frac{H}{44300}\right)}^{5.255}$

$H=44300×\left[1-{\left(\frac{P}{{P}_{0}}\right)}^{\frac{1}{5.255}}\right]$

---- The End Thanks ----
Donate if you like the article.