/*GY-BMP 280 Arduino UNO VCC 3.3v GND gnd SCL 13 SDA 11 CSB 10 SDO 12 */ #include <Wire.h> #include <SPI.h> #include <Adafruit_BMP280.h> #include <U8glib.h> //#define BMP_SCK (13) //#define BMP_MISO (12) //#define BMP_MOSI (11) #define BMP_CS (10) U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); //Adafruit_BMP280 bmp; // I2C Adafruit_BMP280 bmp(BMP_CS); // hardware SPI //Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); void setup() { Serial.begin(9600); Serial.println(F("BMP280 test")); if (!bmp.begin()) { Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); while (1); } /* Default settings from datasheet. */ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ Adafruit_BMP280::FILTER_X16, /* Filtering. */ Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ } void draw(void) { u8g.setFont(u8g_font_8x13); // 温度 u8g.setPrintPos(0, 10); u8g.print("Tem: "); u8g.setPrintPos(32, 10); u8g.print(bmp.readTemperature()); // 气压 u8g.setPrintPos(0, 30); u8g.print("Pre: "); u8g.setPrintPos(32, 30); u8g.print(bmp.readPressure()); // 海拔 u8g.setPrintPos(0, 50); u8g.print("Alt: "); u8g.setPrintPos(32, 50); u8g.print(bmp.readAltitude(1013.25)); } void loop() { Serial.print(F("Temperature = ")); Serial.print(bmp.readTemperature()); Serial.println(" *C"); Serial.print(F("Pressure = ")); Serial.print(bmp.readPressure()); Serial.println(" Pa"); Serial.print(F("Approx altitude = ")); Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */ Serial.println(" m"); Serial.println(); delay(2000); u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); delay(200); }