Test of the BMP180 sensor (Temperature and pression) with the nRF51822 platform.

Dependencies:   BMP180 mbed

Fork of BMP180_example by Kevin Gillepsie

main.cpp

Committer:
kgills
Date:
2015-04-17
Revision:
0:f03b6a07c4ba
Child:
3:43e6a2416ddf

File content as of revision 0:f03b6a07c4ba:

#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);
    }
}