Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Climber's Friend
- *
- * learnelectronics
- * 29 NOV 2017
- *
- * www.youtube.com/c/learnelectronics
- */
- #include <Wire.h> //I2C library for both sensors
- #include <Adafruit_Sensor.h> //Adafruit sensor library for BME280
- #include <Adafruit_BME280.h> //BME280 library
- #include <Adafruit_SSD1306.h> //OLED library
- #define OLED_RESET 4 //not connected
- #define SEALEVELPRESSURE_HPA (1013.25) //put your local Sea level pressure here
- Adafruit_BME280 bme; //create instance of BME280 called bme
- Adafruit_SSD1306 display(OLED_RESET); //create instance of oled called display
- unsigned long delayTime; //declare var for delay
- float altstart = 0.0; //declare var for starting altitude
- void setup() {
- Serial.begin(9600); //serial comms for debug
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // start the oled screen @ hex addy 0x3c
- display.display();
- display.clearDisplay();
- Serial.println(F("BME280 test"));
- bool status;
- // default settings
- status = bme.begin(); //start the bme280 sensor
- if (!status) {
- Serial.println("NO BME");
- while (1);
- }
- Serial.println("-- Default Test --");
- delayTime = 2000; //define delay time
- Serial.println();
- delay(5000); //wait 5 seconds for BME to start
- altstart = ((bme.readAltitude(SEALEVELPRESSURE_HPA))*3.28084); //grab initial altitude and store in var
- }
- void loop() {
- printValues(); //call printVaulues function
- delay(delayTime); //wait
- }
- void printValues() {
- display.clearDisplay(); //clear the display and buffer
- display.setTextSize(1); //set text to smallest size
- display.setTextColor(WHITE); //set color to white
- display.setCursor(0,0); //cursor to upper left
- display.print("Temp. = "); //output line title to buffer
- display.print((bme.readTemperature()*1.8)+32); //output line value to buffer converted to F
- display.println(" F"); //output line units to buffer with linefeed
- display.print("Pressure = ");
- display.print((bme.readPressure() / 100.0F)*.0295); //output line value to buffer converted to inhes of mercury
- display.println(" in");
- display.print("Alt. = ");
- display.print((bme.readAltitude(SEALEVELPRESSURE_HPA))*3.28084); //output line value to buffer converted to feet
- display.println(" Ft");
- float nowalt = ((bme.readAltitude(SEALEVELPRESSURE_HPA))*3.28084);//create a float call nowalt to holt curent alt data
- display.print("Humidity = ");
- display.print(bme.readHumidity());
- display.println(" %");
- display.println("");
- display.print("Alt.Chg. =");
- display.print((altstart-nowalt)*-1); //output change in altitude (start alt - curr alt) * -1
- display.print(" Ft");
- display.display(); //show whats in the buffer on the display
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement