Nucleo and BMP180 example

115

In this example we will connect a BMP180 sensor to our Nucleo board. Typically this is in some sort of breakout or module such as the one below

GY-68-1

 

Description

This precision sensor from Bosch is the best low-cost sensing solution for measuring barometric pressure and temperature. Because pressure changes with altitude you can also use it as an altimeter! The sensor is soldered onto a PCB with a 3.3V regulator, I2C level shifter and pull-up resistors on the I2C pins. The BMP180 is the next-generation of sensors from Bosch, and replaces the BMP085. The good news is that it is completely identical to the BMP085 in terms of firmware/software/interfacing – you can use any example code/libraries for BMP085 as a drop-in replacement.

Specification

  • Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
  • Up to 0.03hPa / 0.25m resolution
  • -40 to +85°C operational range, +-2°C temperature accuracy

The connections were as follows, crucially this is an I2C device and it runs on 3.3v. You can see the I2C pins at D15,D14

 

nucleo pins
nucleo pins

Code

You will need to import the bmp180 library

#include <stdio.h>
#include "mbed.h"
#include "BMP180.h"
 
I2C i2c(I2C_SDA, I2C_SCL);
BMP180 bmp180(&i2c);
 
int main(void) {
 
    while(1) {
        if (bmp180.init() != 0) {
            printf("Error communicating with BMP180\n");
        } else {
            printf("Initialized BMP180\n");
            break;
        }
        wait(1);
    }
 
    while(1) {
        bmp180.startTemperature();
        wait_ms(5);     // Wait for conversion to complete
        float temp;
        if(bmp180.getTemperature(&temp) != 0) {
            printf("Error getting temperature\n");
            continue;
        }
 
        bmp180.startPressure(BMP180::ULTRA_LOW_POWER);
        wait_ms(10);    // Wait for conversion to complete
        int pressure;
        if(bmp180.getPressure(&pressure) != 0) {
            printf("Error getting pressure\n");
            continue;
        }
 
        printf("Pressure = %d Pa Temperature = %f C\n", pressure, temp);
        wait(1);
    }
}

 

Results

Open a serial monitor such as TeraTerm, if all is correct you should see something like the following

nucleo and bmp180
nucleo and bmp180

 

Links
1PCS GY-68 BMP180 Replace BMP085 Digital Barometric Pressure Sensor Module For Arduino

Share