LinkNode_BMP180

Dependencies:   BLE_API BMP180 mbed nRF51822

Fork of BMP180_example by Kevin Gillepsie

Committer:
kgills
Date:
Fri Apr 17 15:37:41 2015 +0000
Revision:
0:f03b6a07c4ba
Child:
3:b66abd88f595
Adding files.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kgills 0:f03b6a07c4ba 1 #include <stdio.h>
kgills 0:f03b6a07c4ba 2 #include "mbed.h"
kgills 0:f03b6a07c4ba 3 #include "BMP180.h"
kgills 0:f03b6a07c4ba 4
kgills 0:f03b6a07c4ba 5 I2C i2c(I2C_SDA, I2C_SCL);
kgills 0:f03b6a07c4ba 6 BMP180 bmp180(&i2c);
kgills 0:f03b6a07c4ba 7
kgills 0:f03b6a07c4ba 8 int main(void) {
kgills 0:f03b6a07c4ba 9
kgills 0:f03b6a07c4ba 10 while(1) {
kgills 0:f03b6a07c4ba 11 if (bmp180.init() != 0) {
kgills 0:f03b6a07c4ba 12 printf("Error communicating with BMP180\n");
kgills 0:f03b6a07c4ba 13 } else {
kgills 0:f03b6a07c4ba 14 printf("Initialized BMP180\n");
kgills 0:f03b6a07c4ba 15 break;
kgills 0:f03b6a07c4ba 16 }
kgills 0:f03b6a07c4ba 17 wait(1);
kgills 0:f03b6a07c4ba 18 }
kgills 0:f03b6a07c4ba 19
kgills 0:f03b6a07c4ba 20 while(1) {
kgills 0:f03b6a07c4ba 21 bmp180.startTemperature();
kgills 0:f03b6a07c4ba 22 wait_ms(5); // Wait for conversion to complete
kgills 0:f03b6a07c4ba 23 float temp;
kgills 0:f03b6a07c4ba 24 if(bmp180.getTemperature(&temp) != 0) {
kgills 0:f03b6a07c4ba 25 printf("Error getting temperature\n");
kgills 0:f03b6a07c4ba 26 continue;
kgills 0:f03b6a07c4ba 27 }
kgills 0:f03b6a07c4ba 28
kgills 0:f03b6a07c4ba 29 bmp180.startPressure(BMP180::ULTRA_LOW_POWER);
kgills 0:f03b6a07c4ba 30 wait_ms(10); // Wait for conversion to complete
kgills 0:f03b6a07c4ba 31 int pressure;
kgills 0:f03b6a07c4ba 32 if(bmp180.getPressure(&pressure) != 0) {
kgills 0:f03b6a07c4ba 33 printf("Error getting pressure\n");
kgills 0:f03b6a07c4ba 34 continue;
kgills 0:f03b6a07c4ba 35 }
kgills 0:f03b6a07c4ba 36
kgills 0:f03b6a07c4ba 37 printf("Pressure = %d Pa Temperature = %f C\n", pressure, temp);
kgills 0:f03b6a07c4ba 38 wait(1);
kgills 0:f03b6a07c4ba 39 }
kgills 0:f03b6a07c4ba 40 }