Test of the BMP180 sensor (Temperature and pression) with the nRF51822 platform.
Fork of BMP180_example by
main.cpp@3:43e6a2416ddf, 2015-10-16 (annotated)
- Committer:
- yanndouze
- Date:
- Fri Oct 16 14:53:16 2015 +0000
- Revision:
- 3:43e6a2416ddf
- Parent:
- 0:f03b6a07c4ba
Test of the BMP180 Sensor (pression and temperature) with the nRF51822 platform.
Who changed what in which revision?
User | Revision | Line number | New 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 | |
yanndouze | 3:43e6a2416ddf | 5 | I2C i2c(D14, D15); |
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) { |
yanndouze | 3:43e6a2416ddf | 12 | printf("Error communicating with BMP180\r\n"); |
kgills | 0:f03b6a07c4ba | 13 | } else { |
yanndouze | 3:43e6a2416ddf | 14 | printf("Initialized BMP180\r\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) { |
yanndouze | 3:43e6a2416ddf | 25 | printf("Error getting temperature\r\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) { |
yanndouze | 3:43e6a2416ddf | 33 | printf("Error getting pressure\r\n"); |
kgills | 0:f03b6a07c4ba | 34 | continue; |
kgills | 0:f03b6a07c4ba | 35 | } |
kgills | 0:f03b6a07c4ba | 36 | |
yanndouze | 3:43e6a2416ddf | 37 | printf("Pressure = %d Pa Temperature = %f C\r\n", pressure, temp); |
kgills | 0:f03b6a07c4ba | 38 | wait(1); |
kgills | 0:f03b6a07c4ba | 39 | } |
kgills | 0:f03b6a07c4ba | 40 | } |