Driver for the BMP180 digital pressure sensor.
- Documentation
- Repository
- Issues
- Discussions and questions
- Component page at the ESP Component Registry
idf.py add-dependency esp-idf-lib/bmp180The sensor answers on 0x77; the address is fixed, so there can be only one
BMP180 per bus. Supply is 1.8–3.6 V, and the breakout boards usually add a
regulator, so check the markings before feeding one from 5 V. The driver sets
the port to 1 MHz, the fastest rate ESP-IDF supports; the chip itself would go
up to 3.4 MHz.
Two pins are enough:
| Sensor | ESP32 |
|---|---|
VIN / VCC |
3.3 V |
GND |
GND |
SCL |
any GPIO with a pull-up |
SDA |
any GPIO with a pull-up |
The chip id lives in the version register and is checked on every
bmp180_init(): a different value returns ESP_ERR_NOT_FOUND, so a wrong
address or a dead bus is reported instead of producing plausible numbers.
#include <bmp180.h>
bmp180_dev_t dev = { 0 };
ESP_ERROR_CHECK(bmp180_init_desc(&dev, 0, CONFIG_EXAMPLE_I2C_MASTER_SDA,
CONFIG_EXAMPLE_I2C_MASTER_SCL));
ESP_ERROR_CHECK(bmp180_init(&dev));
float temperature;
uint32_t pressure;
ESP_ERROR_CHECK(bmp180_measure(&dev, &temperature, &pressure,
BMP180_MODE_STANDARD));
printf("%.2f C, %" PRIu32 " Pa\n", temperature, pressure);i2cdev_init() has to run before the first transfer, which happens inside
bmp180_init(); bmp180_init_desc() only fills the descriptor and creates its
mutex.
bmp180_measure() takes the temperature first and the pressure second: the
pressure compensation needs the temperature of the same cycle, so both values
always belong together. Either output may be NULL, and a NULL pressure
skips its conversion entirely and returns sooner.
The oss argument trades resolution for time, as in table 3 of the datasheet:
| Mode | Samples | Pressure conversion |
|---|---|---|
BMP180_MODE_ULTRA_LOW_POWER |
1 | 4.5 ms |
BMP180_MODE_STANDARD |
2 | 7.5 ms |
BMP180_MODE_HIGH_RESOLUTION |
4 | 13.5 ms |
BMP180_MODE_ULTRA_HIGH_RESOLUTION |
8 | 25.5 ms |
The temperature conversion takes 4.5 ms in every mode. The driver does not
sleep for these times: it writes the command and polls the Sco bit until the
conversion reports completion, with a 10 ms margin over the datasheet time.
A conversion that does not finish returns ESP_ERR_TIMEOUT.
Temperature is returned in degrees Celsius, pressure in pascals. The
compensation follows the datasheet formulas, so the accuracy figures of the
datasheet apply: ±0.5 °C and ±1 hPa in the standard mode at room temperature.
Values that come out non-physical mean corrupted calibration data and are
reported as ESP_ERR_INVALID_RESPONSE instead of being returned: the driver
checks the temperature against the operating range of the chip (−40…+85 °C) and
rejects a pressure that is not positive.
bmp180_reset() sends the reset command and waits at least 2 ms (the delay is
quantised to the FreeRTOS tick); bmp180_init() calls
it before reading the identification and the eleven calibration coefficients,
so a sensor that stayed powered through an MCU restart starts from a known
state.
- The address is fixed at
0x77. - Pressure is returned in pascals only; altitude needs the sea-level pressure of the moment and is left to the application.
- A measurement is several I2C transactions, each with its own mutex, so another device on the same bus can interleave between them. The conversion itself is not interrupted.
bmp180_free_desc()deletes the mutex, it does not release the port; calli2cdev_done()when nothing else uses the bus.
default— measures every 500 ms in the standard mode and prints the values.
For questions and discussions about the component, please use Discussions at esp-idf-lib/core.
Please read CONTRIBUTING.md at esp-idf-lib/core.