![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Pressure sensor + Oled display SSD1306 32*128
Dependencies: mbed Adafruit_GFX BMP180
main.cpp@0:a1bf4bcd163a, 2019-10-09 (annotated)
- Committer:
- Taraskin
- Date:
- Wed Oct 09 21:30:55 2019 +0000
- Revision:
- 0:a1bf4bcd163a
BMP180 + SSD1306 32*128
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Taraskin | 0:a1bf4bcd163a | 1 | #include "mbed.h" |
Taraskin | 0:a1bf4bcd163a | 2 | #include "Adafruit_SSD1306.h" |
Taraskin | 0:a1bf4bcd163a | 3 | #include "BMP180.h" |
Taraskin | 0:a1bf4bcd163a | 4 | |
Taraskin | 0:a1bf4bcd163a | 5 | DigitalOut myled_R(LED1); |
Taraskin | 0:a1bf4bcd163a | 6 | |
Taraskin | 0:a1bf4bcd163a | 7 | I2C i2c(PB_9, PB_8); // SDA, SCL arduino pins |
Taraskin | 0:a1bf4bcd163a | 8 | |
Taraskin | 0:a1bf4bcd163a | 9 | Adafruit_SSD1306_I2c myOled(i2c,NC,0x78,32,128); |
Taraskin | 0:a1bf4bcd163a | 10 | BMP180 bmp180(&i2c); |
Taraskin | 0:a1bf4bcd163a | 11 | |
Taraskin | 0:a1bf4bcd163a | 12 | int main(void) { |
Taraskin | 0:a1bf4bcd163a | 13 | |
Taraskin | 0:a1bf4bcd163a | 14 | while(1) { |
Taraskin | 0:a1bf4bcd163a | 15 | if (bmp180.init() != 0) { |
Taraskin | 0:a1bf4bcd163a | 16 | printf("Error communicating with BMP180\n"); |
Taraskin | 0:a1bf4bcd163a | 17 | } else { |
Taraskin | 0:a1bf4bcd163a | 18 | printf("Initialized BMP180\n"); |
Taraskin | 0:a1bf4bcd163a | 19 | break; |
Taraskin | 0:a1bf4bcd163a | 20 | } |
Taraskin | 0:a1bf4bcd163a | 21 | wait(1); |
Taraskin | 0:a1bf4bcd163a | 22 | } |
Taraskin | 0:a1bf4bcd163a | 23 | |
Taraskin | 0:a1bf4bcd163a | 24 | while(1) { |
Taraskin | 0:a1bf4bcd163a | 25 | bmp180.startTemperature(); |
Taraskin | 0:a1bf4bcd163a | 26 | wait_ms(5); // Wait for conversion to complete. |
Taraskin | 0:a1bf4bcd163a | 27 | float temp; |
Taraskin | 0:a1bf4bcd163a | 28 | if(bmp180.getTemperature(&temp) != 0) { |
Taraskin | 0:a1bf4bcd163a | 29 | printf("Error getting temperature\n"); |
Taraskin | 0:a1bf4bcd163a | 30 | continue; |
Taraskin | 0:a1bf4bcd163a | 31 | } |
Taraskin | 0:a1bf4bcd163a | 32 | |
Taraskin | 0:a1bf4bcd163a | 33 | bmp180.startPressure(BMP180::ULTRA_LOW_POWER); |
Taraskin | 0:a1bf4bcd163a | 34 | wait_ms(10); // Wait for conversion to complete |
Taraskin | 0:a1bf4bcd163a | 35 | int pressure; |
Taraskin | 0:a1bf4bcd163a | 36 | if(bmp180.getPressure(&pressure) != 0) { |
Taraskin | 0:a1bf4bcd163a | 37 | printf("Error getting pressure\n"); |
Taraskin | 0:a1bf4bcd163a | 38 | continue; |
Taraskin | 0:a1bf4bcd163a | 39 | } |
Taraskin | 0:a1bf4bcd163a | 40 | |
Taraskin | 0:a1bf4bcd163a | 41 | myOled.printf("Temp= %f\r", temp); |
Taraskin | 0:a1bf4bcd163a | 42 | myOled.display(); |
Taraskin | 0:a1bf4bcd163a | 43 | wait(0.01); |
Taraskin | 0:a1bf4bcd163a | 44 | |
Taraskin | 0:a1bf4bcd163a | 45 | } |
Taraskin | 0:a1bf4bcd163a | 46 | } |