# esp-idf-lib/bmp180
[](https://github.com/esp-idf-lib/bmp180/actions/workflows/build.yml)
[](https://github.com/esp-idf-lib/bmp180/actions/workflows/build-docs.yml)
[](https://github.com/esp-idf-lib/bmp180/actions/workflows/validate-component.yml)
Driver for the BMP180 digital pressure sensor.
* [Documentation](https://esp-idf-lib.github.io/bmp180/)
* [Repository](https://github.com/esp-idf-lib/bmp180)
* [Issues](https://github.com/esp-idf-lib/bmp180/issues)
* [Discussions and questions](https://github.com/esp-idf-lib/core/discussions)
* [Component page at the ESP Component Registry](https://components.espressif.com/components/esp-idf-lib/bmp180)
## Installation
```sh
idf.py add-dependency esp-idf-lib/bmp180
```
## Hardware
The 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.
## Usage
```c
#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.
## Measuring
`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.
## Limitations
- 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; call
`i2cdev_done()` when nothing else uses the bus.
## Examples
- `default` — measures every 500 ms in the standard mode and prints the values.
## Support
For questions and discussions about the component, please use
[Discussions](https://github.com/esp-idf-lib/core/discussions)
at [esp-idf-lib/core](https://github.com/esp-idf-lib/core).
## Contributing
Please read [CONTRIBUTING.md](https://github.com/esp-idf-lib/core/blob/main/CONTRIBUTING.md)
at [esp-idf-lib/core](https://github.com/esp-idf-lib/core).
506fe00bba76477c1fee32c1cfefbaaa2ff03943
idf.py add-dependency "esp-idf-lib/bmp180^1.0.10"