|
| 1 | +/****************************************************************************** |
| 2 | +CSV_Output.ino |
| 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 configures two BME280 to produce comma separated values for use |
| 9 | +in generating spreadsheet graphs. |
| 10 | +in 10 being used for chip select. |
| 11 | +
|
| 12 | +Resources: |
| 13 | +Uses Wire.h for I2C operation |
| 14 | +Uses SPI.h for SPI operation |
| 15 | +
|
| 16 | +Development environment specifics: |
| 17 | +Arduino IDE 1.6.4 |
| 18 | +Teensy loader 1.23 |
| 19 | +
|
| 20 | +This code is released under the [MIT License](http://opensource.org/licenses/MIT). |
| 21 | +Please review the LICENSE.md file included with this example. If you have any questions |
| 22 | +or concerns with licensing, please contact [email protected]. |
| 23 | +Distributed as-is; no warranty is given. |
| 24 | +******************************************************************************/ |
| 25 | + |
| 26 | +#include <stdint.h> |
| 27 | +#include "SparkFunBME280.h" |
| 28 | + |
| 29 | +#include "Wire.h" |
| 30 | +#include "SPI.h" |
| 31 | + |
| 32 | +//Global sensor object |
| 33 | +BME280 mySensor; |
| 34 | + |
| 35 | +unsigned int sampleNumber = 0; //For counting number of CSV rows |
| 36 | + |
| 37 | +void setup() |
| 38 | +{ |
| 39 | + //***Driver settings********************************// |
| 40 | + //commInterface can be I2C_MODE or SPI_MODE |
| 41 | + //specify chipSelectPin using arduino pin names |
| 42 | + //specify I2C address. Can be 0x77(default) or 0x76 |
| 43 | + |
| 44 | + //For I2C, enable the following and disable the SPI section |
| 45 | + mySensor.settings.commInterface = I2C_MODE; |
| 46 | + mySensor.settings.I2CAddress = 0x77; |
| 47 | + |
| 48 | + //For SPI enable the following and dissable the I2C section |
| 49 | + //mySensor.settings.commInterface = SPI_MODE; |
| 50 | + //mySensor.settings.chipSelectPin = 10; |
| 51 | + |
| 52 | + |
| 53 | + //***Operation settings*****************************// |
| 54 | + mySensor.settings.runMode = 3; // 3, Normal mode |
| 55 | + mySensor.settings.tStandby = 0; // 0, 0.5ms |
| 56 | + mySensor.settings.filter = 0; // 0, filter off |
| 57 | + //tempOverSample can be: |
| 58 | + // 0, skipped |
| 59 | + // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively |
| 60 | + mySensor.settings.tempOverSample = 1; |
| 61 | + //pressOverSample can be: |
| 62 | + // 0, skipped |
| 63 | + // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively |
| 64 | + mySensor.settings.pressOverSample = 1; |
| 65 | + //humidOverSample can be: |
| 66 | + // 0, skipped |
| 67 | + // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively |
| 68 | + mySensor.settings.humidOverSample = 1; |
| 69 | + |
| 70 | + Serial.begin(57600); |
| 71 | + Serial.print("Program Started\n"); |
| 72 | + Serial.print("Starting BME280... result of .begin(): 0x"); |
| 73 | + delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up. |
| 74 | + //Calling .begin() causes the settings to be loaded |
| 75 | + Serial.println(mySensor.begin(), HEX); |
| 76 | + |
| 77 | + //Build a first-row of column headers |
| 78 | + Serial.print("\n\n"); |
| 79 | + Serial.print("Sample,"); |
| 80 | + Serial.print("T(deg C),"); |
| 81 | + Serial.print("T(deg F),"); |
| 82 | + Serial.print("P(kPa),"); |
| 83 | + Serial.print("Alt(m),"); |
| 84 | + Serial.print("Alt(ft),"); |
| 85 | + Serial.print("%RH"); |
| 86 | + Serial.println(""); |
| 87 | + |
| 88 | +} |
| 89 | + |
| 90 | +void loop() |
| 91 | +{ |
| 92 | + |
| 93 | + //Print each row in the loop |
| 94 | + Serial.print(sampleNumber); |
| 95 | + Serial.print(","); |
| 96 | + Serial.print(mySensor.readTempC(), 2); |
| 97 | + Serial.print(","); |
| 98 | + Serial.print(mySensor.readTempF(), 3); |
| 99 | + Serial.print(","); |
| 100 | + Serial.print(mySensor.readFloatPressure(), 0); |
| 101 | + Serial.print(","); |
| 102 | + Serial.print(mySensor.readFloatAltitudeMeters(), 3); |
| 103 | + Serial.print(","); |
| 104 | + Serial.print(mySensor.readFloatAltitudeFeet(), 3); |
| 105 | + Serial.print(","); |
| 106 | + Serial.print(mySensor.readFloatHumidity(), 0); |
| 107 | + Serial.println(); |
| 108 | + |
| 109 | + sampleNumber++; |
| 110 | + |
| 111 | + delay(50); |
| 112 | + |
| 113 | +} |
0 commit comments