This sample code is for measuring surrounding air pressure's tutorial using Grove Air Pressure Sensor(BMP280)
#include "Seeed_BMP280.h" | |
#include <Wire.h> | |
#include <Arduino.h> | |
#include <U8x8lib.h> | |
U8X8_SSD1306_128X64_ALT0_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); | |
BMP280 bmp280; | |
void setup() { | |
Serial.begin(9600); | |
u8x8.setBusClock(100000); // If you breakout other modules, please enable this line | |
u8x8.begin(); | |
u8x8.setPowerSave(0); | |
u8x8.setFlipMode(1); | |
if (!bmp280.init()) { | |
Serial.println("Device not connected or broken!"); | |
} | |
} | |
void loop() { | |
float pressure; | |
u8x8.setFont(u8x8_font_chroma48medium8_r); | |
u8x8.setCursor(0, 0); | |
u8x8.print("P:"); | |
u8x8.print(pressure = bmp280.getPressure()); | |
u8x8.print("Pa"); | |
u8x8.setCursor(0, 30); | |
u8x8.print("A:"); | |
u8x8.print(bmp280.calcAltitude(pressure)); | |
u8x8.print("m"); | |
u8x8.refreshDisplay(); | |
delay(200); | |
//float pressure; | |
//get and print temperatures | |
Serial.print("Temp: "); | |
Serial.print(bmp280.getTemperature()); | |
Serial.println("C"); // The unit for Celsius because original arduino don't support speical symbols | |
//get and print atmospheric pressure data | |
Serial.print("Pressure: "); | |
Serial.print(pressure = bmp280.getPressure()); | |
Serial.println("Pa"); | |
//get and print altitude data | |
Serial.print("Altitude: "); | |
Serial.print(bmp280.calcAltitude(pressure)); | |
Serial.println("m"); | |
Serial.println("\n");//add a line between output of different times. | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment