Files
OpenMQTTGateway/lib/SparkFun_BME280/examples/CSV_Output/CSV_Output.ino

117 lines
3.4 KiB
C++

/******************************************************************************
CSV_Output.ino
BME280 Arduino and Teensy example
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/SparkFun_BME280_Arduino_Library
This sketch configures two BME280 to produce comma separated values for use
in generating spreadsheet graphs.
in 10 being used for chip select.
Resources:
Uses Wire.h for I2C operation
Uses SPI.h for SPI operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/
#include <stdint.h>
#include "SparkFunBME280.h"
#include "Wire.h"
#include "SPI.h"
//Global sensor object
BME280 mySensor;
unsigned int sampleNumber = 0; //For counting number of CSV rows
void setup()
{
//***Driver settings********************************//
//commInterface can be I2C_MODE or SPI_MODE
//specify chipSelectPin using arduino pin names
//specify I2C address. Can be 0x77(default) or 0x76
//For I2C, enable the following and disable the SPI section
mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = 0x77;
//For SPI enable the following and dissable the I2C section
//mySensor.settings.commInterface = SPI_MODE;
//mySensor.settings.chipSelectPin = 10;
//***Operation settings*****************************//
mySensor.settings.runMode = 3; // 3, Normal mode
mySensor.settings.tStandby = 0; // 0, 0.5ms
mySensor.settings.filter = 0; // 0, filter off
//tempOverSample can be:
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.tempOverSample = 1;
//pressOverSample can be:
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.pressOverSample = 1;
//humidOverSample can be:
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.humidOverSample = 1;
Serial.begin(57600);
Serial.print("Program Started\n");
Serial.print("Starting BME280... result of .begin(): 0x");
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
//Calling .begin() causes the settings to be loaded
Serial.println(mySensor.begin(), HEX);
//Build a first-row of column headers
Serial.print("\n\n");
Serial.print("Sample,");
Serial.print("T(deg C),");
Serial.print("T(deg F),");
Serial.print("P(Pa),");
Serial.print("Alt(m),");
Serial.print("Alt(ft),");
Serial.print("%RH");
Serial.println("");
}
void loop()
{
//Print each row in the loop
//Start with temperature, as that data is needed for accurate compensation.
//Reading the temperature updates the compensators of the other functions
//in the background.
Serial.print(sampleNumber);
Serial.print(",");
Serial.print(mySensor.readTempC(), 2);
Serial.print(",");
Serial.print(mySensor.readTempF(), 3);
Serial.print(",");
Serial.print(mySensor.readFloatPressure(), 0);
Serial.print(",");
Serial.print(mySensor.readFloatAltitudeMeters(), 3);
Serial.print(",");
Serial.print(mySensor.readFloatAltitudeFeet(), 3);
Serial.print(",");
Serial.print(mySensor.readFloatHumidity(), 0);
Serial.println();
sampleNumber++;
delay(50);
}