bmp180: Driver for BMP180 digital pressure sensor

Defines

BMP180_DEVICE_ADDRESS

I2C address.

Enums

enum bmp180_mode_t

Hardware accuracy mode.

See Table 3 of the datasheet

Values:

enumerator BMP180_MODE_ULTRA_LOW_POWER

1 sample, 4.5 ms

enumerator BMP180_MODE_STANDARD

2 samples, 7.5 ms

enumerator BMP180_MODE_HIGH_RESOLUTION

4 samples, 13.5 ms

enumerator BMP180_MODE_ULTRA_HIGH_RESOLUTION

8 samples, 25.5 ms

Functions

esp_err_t bmp180_init_desc(bmp180_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Parameters:
  • dev – Device descriptor

  • port – I2C port number

  • sda_gpio – GPIO pin number for SDA

  • scl_gpio – GPIO pin number for SCL

Returns:

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if dev is NULL

  • ESP_ERR_NO_MEM if the descriptor mutex cannot be created

esp_err_t bmp180_free_desc(bmp180_dev_t *dev)

Free device descriptor.

Parameters:

dev – Pointer to BMP180 device descriptor

Returns:

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if dev is NULL

esp_err_t bmp180_reset(bmp180_dev_t *dev)

Reset the sensor.

Runs the power-on sequence: the control and the data registers return to their default values and an ongoing conversion is aborted. The calibration coefficients are stored in the E2PROM and survive the reset.

Parameters:

dev – Pointer to BMP180 device descriptor

Returns:

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if dev is NULL

  • another error code from the I2C layer

esp_err_t bmp180_init(bmp180_dev_t *dev)

Initialize device.

Calls bmp180_reset, verifies the chip ID and reads the calibration coefficients. The reset puts the sensor into the known state after an MCU restart while the sensor stays powered.

Parameters:

dev – Pointer to BMP180 device descriptor

Returns:

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if dev is NULL

  • ESP_ERR_NOT_FOUND if the chip ID is not the BMP180 one

  • another error code from the I2C layer

esp_err_t bmp180_measure(bmp180_dev_t *dev, float *temperature, uint32_t *pressure, bmp180_mode_t oss)

Measure temperature and pressure.

The temperature is measured before the pressure, the pressure measurement needs the temperature one. At least one of the output parameters has to be given; when the pressure is not requested it is not measured, which saves the conversion time of its mode.

Parameters:
  • dev – Pointer to BMP180 device descriptor

  • temperature – [out] Temperature in degrees Celsius, may be NULL

  • pressure – [out] Pressure in Pa, may be NULL

  • oss – Measurement mode, one of bmp180_mode_t

Returns:

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if dev is NULL, both outputs are NULL or oss is out of range

  • ESP_ERR_TIMEOUT if a conversion does not finish in time

  • ESP_ERR_INVALID_RESPONSE if the measured value is not physical, which means that the calibration data is corrupted

  • another error code from the I2C layer

struct bmp180_dev_t
#include <bmp180.h>

BMP180 device descriptor.

Public Members

i2c_dev_t i2c_dev
int16_t AC1
int16_t AC2
int16_t AC3
uint16_t AC4
uint16_t AC5
uint16_t AC6
int16_t B1
int16_t B2
int16_t MB
int16_t MC
int16_t MD