/*************************************************************************** This is a library for the BME280 humidity, temperature & pressure sensor Designed specifically to work with the Adafruit BME280 Breakout ----> http://www.adafruit.com/products/2650 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. The device's I2C address is either 0x76 or 0x77. Adafruit invests time and resources providing this open source code, please support Adafruit andopen-source hardware by purchasing products from Adafruit! Written by Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ /* Modified by Bill Gilbert, Bush Point Trac Park Waterworks 590PW.com 20171216, 1800 PST. to read as true sea level barometer, with credit to http://keisan.casio.com/exec/system/1224575267 for the conversion function to make the BME280 a true land-based barometer. Note: the #include function in the header for the double (same as float in arduino) void getP() routine returns the sea level pressure but Serial.print cannot handle double see also double to string function in the print routine. where a char string is assembled as pp which prints fine. The sketch is currently being run on a YUN but in USB serial mode. But will eventually be run as a Client so Print will be Console. */ #include // for power function in pressure conversion #include // #include #include #include /* #define BME_SCK 13 #define BME_MISO 12 #define BME_MOSI 11 #define BME_CS 10 */ #define SEALEVELPRESSURE_HPA (1024.1) // not used in the sketch Adafruit_BME280 bme; // I2C // Adafruit_BME280 bme(BME_CS); // hardware SPI // Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI unsigned long delayTime; double P; // for pressure conversion void setup() { Serial.begin(9600); Serial.println(F("BME280 test")); bool status; // default settings // (you can also pass in a Wire library object like &Wire2) status = bme.begin(); if (!status) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } Serial.println("-- Default Test --"); delayTime = 5000; Serial.println(); delay(100); // let sensor boot up } void loop() { getP(); printValues(); delay(delayTime); } void printValues() { Serial.print("Temperature = "); Serial.print(((bme.readTemperature() * 1.8) + 32)); Serial.println(" ºF"); Serial.print("Altitude Set at "); Serial.print("142"); // put in your feet Serial.println(" Ft."); Serial.print("Local Pressure = "); Serial.print(bme.readPressure() * 0.0002953); Serial.println(" in."); // 'nilton61' http://forum.arduino.cc/index.php?topic=282250.0 // convert a double to string for printing char pp[7]; // setup character string for barometer reading dtostrf(P, 4, 2, pp); // convert double to string Serial.print("Sea Level Barometer = "); Serial.print(pp); Serial.println(" in."); Serial.print("Humidity = "); Serial.print(bme.readHumidity()); Serial.println(" %"); Serial.println(); } // Keisan Calculation for Sea Level Pressure from current BME280 readings // http://keisan.casio.com/exec/system/1224575267 void getP() { int a = 43; // My altitude in meters = 142 (ft)* 0.30488 float k = .0065; // altitude multiplier volatile float z = (((k * a) / (bme.readTemperature() + (k * a) + 273.15))) ; volatile float y = (bme.readPressure()); P = y * (pow ((1 - z) , -5.257)) ; P = P * 0.0002953; // convert to Inches return P; }