Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Hiker's Friend
- *
- * learnelectronics
- * 16 Sept 2017
- *
- * www.youtube.com/c/learnelectronics
- *
- * Note: I2C pins on the D1 Mini are: SDA D@, SCK D1
- */
- #include <Wire.h> //I2C library
- #include <Adafruit_SSD1306.h> //OLED driver
- #include <Adafruit_Sensor.h> //Sensor library
- #include <Adafruit_BMP280.h> //BMP280 driver
- Adafruit_SSD1306 display(LED_BUILTIN); //create instance of SSD1306 called display
- Adafruit_BMP280 bme; //create instance of BMP280 called bme
- void setup() {
- Serial.begin(9600); //serial begin for debugging
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //start OLED @ hex addy 0X3C
- display.display(); //show Adafruit logo
- delay(2000); //wait 2 sec
- display.clearDisplay(); //clear display & buffer
- if (!bme.begin()) { //if bme does not start show error
- Serial.println("Could not find a valid BMP280 sensor, check wiring!");
- while (1);
- }
- }
- void loop() {
- float temp = ((bme.readTemperature()*1.8)+32); //get temp and convert from C to F
- float pres = (bme.readPressure()*0.0002953); //get pressure and convert from Pa to inHg
- float alti = (bme.readAltitude(1013.25)*3.28084); //get altitude and convert from M to feet
- display.clearDisplay(); //clear display & buffer
- display.setTextSize(1); //set text size to 1
- display.setTextColor(WHITE); //set color to white
- display.setCursor(0,0); //start in upper left
- display.print("Temp: "); //print heading to buffer
- display.print(temp,2); //print value to buffer w/ 2 dec places
- display.println("F"); //print units to buffer and drop down 1 line
- display.print("Pressure: ");
- display.print(pres,2);
- display.println("in");
- display.print("Altitude: ");
- display.print(alti,2);
- display.println("Ft");
- display.display(); //show the buffer
- delay(2000); //wait 2 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement