300
In this example we will take the previous bmp180 example – Nucleo and BMP180 example. This time again we will connect an LCD Keypad shield and display the temperature and pressure on the display.
Code
You will need the freetronics lcd keypad shield library
[codesyntax lang=”cpp”]
#include "mbed.h" #include "freetronicsLCDShield.h" #include "BMP180.h" I2C i2c(I2C_SDA, I2C_SCL); freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D7, D1, A0); BMP180 bmp180(&i2c); int n=0; int main() { lcd.cls(); lcd.printf("Initiliazing"); lcd.setCursorPosition(1, 0); while(1) { if (bmp180.init() != 0) { lcd.printf("Comms error"); } else { lcd.printf("Initialized BMP180"); break; } wait(1); } while(1) { bmp180.startTemperature(); wait_ms(5); // Wait for conversion to complete float temp; lcd.cls(); if(bmp180.getTemperature(&temp) != 0) { lcd.setCursorPosition(0, 0); lcd.printf("Error temp"); continue; } bmp180.startPressure(BMP180::ULTRA_LOW_POWER); wait_ms(10); // Wait for conversion to complete int pressure; if(bmp180.getPressure(&pressure) != 0) { lcd.printf("Error pres"); continue; } lcd.setCursorPosition(0, 0); lcd.printf("Temp : "); lcd.setCursorPosition(0, 7); lcd.printf("%2.1f",temp); lcd.setCursorPosition(1, 0); lcd.printf("Pres : "); lcd.setCursorPosition(1, 7); lcd.printf("%d",pressure); wait_ms(1000); } }
[/codesyntax]
Links
1PCS GY-68 BMP180 Replace BMP085 Digital Barometric Pressure Sensor Module For Arduino
1602 LCD Board Keypad Shield Blue Backligh