|
| 1 | +/* |
| 2 | + Output all readings in CSV format |
| 3 | + BME280 Arduino and Teensy example |
| 4 | + Marshall Taylor @ SparkFun Electronics |
| 5 | + May 20, 2015 |
| 6 | + https://github.com/sparkfun/SparkFun_BME280_Arduino_Library |
| 7 | + |
| 8 | + This sketch outputs BME280 data in comma separated values for generating spreadsheet graphs. |
| 9 | +
|
| 10 | + Feel like supporting our work? Buy a board from SparkFun! |
| 11 | + https://www.sparkfun.com/products/14348 - Qwiic Combo Board |
| 12 | + https://www.sparkfun.com/products/13676 - BME280 Breakout Board |
| 13 | +
|
| 14 | + This code is released under the [MIT License](http://opensource.org/licenses/MIT). |
| 15 | + Please review the LICENSE.md file included with this example. If you have any questions |
| 16 | + or concerns with licensing, please contact techsupport@sparkfun.com. |
| 17 | + Distributed as-is; no warranty is given. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include "Wire.h" |
| 21 | + |
| 22 | +#include "SparkFunBME280.h" |
| 23 | +BME280 mySensor; //Global sensor object |
| 24 | + |
| 25 | +unsigned long sampleNumber = 0; |
| 26 | + |
| 27 | +void setup() |
| 28 | +{ |
| 29 | + Serial.begin(9600); |
| 30 | + |
| 31 | + Wire.begin(); |
| 32 | + |
| 33 | + if (mySensor.beginI2C() == false) //Begin communication over I2C |
| 34 | + { |
| 35 | + Serial.println("The chip did not respond. Please check wiring."); |
| 36 | + while(1); //Freeze |
| 37 | + } |
| 38 | + |
| 39 | + //Build a first-row of column headers |
| 40 | + Serial.print("SampleNumber,"); |
| 41 | + Serial.print("Time(ms),"); |
| 42 | + Serial.print("T(deg C),"); |
| 43 | + Serial.print("T(deg F),"); |
| 44 | + Serial.print("P(Pa),"); |
| 45 | + Serial.print("Alt(m),"); |
| 46 | + Serial.print("Alt(ft),"); |
| 47 | + Serial.print("%RH"); |
| 48 | + Serial.println(""); |
| 49 | +} |
| 50 | + |
| 51 | +void loop() |
| 52 | +{ |
| 53 | + //Print each row in the loop |
| 54 | + //Start with temperature, as that data is needed for accurate compensation. |
| 55 | + //Reading the temperature updates the compensators of the other functions |
| 56 | + //in the background. |
| 57 | + Serial.print(sampleNumber); |
| 58 | + Serial.print(","); |
| 59 | + Serial.print(millis()); |
| 60 | + Serial.print(","); |
| 61 | + Serial.print(mySensor.readTempC(), 2); |
| 62 | + Serial.print(","); |
| 63 | + Serial.print(mySensor.readTempF(), 3); |
| 64 | + Serial.print(","); |
| 65 | + Serial.print(mySensor.readFloatPressure(), 0); |
| 66 | + Serial.print(","); |
| 67 | + Serial.print(mySensor.readFloatAltitudeMeters(), 3); |
| 68 | + Serial.print(","); |
| 69 | + Serial.print(mySensor.readFloatAltitudeFeet(), 3); |
| 70 | + Serial.print(","); |
| 71 | + Serial.print(mySensor.readFloatHumidity(), 0); |
| 72 | + Serial.println(); |
| 73 | + |
| 74 | + sampleNumber++; |
| 75 | + |
| 76 | + delay(50); |
| 77 | +} |
0 commit comments