fixed and split example
This commit is contained in:
parent
54b1c5125c
commit
553c635a81
|
|
@ -40,14 +40,7 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, i
|
||||||
@brief Initialise sensor with given parameters / settings
|
@brief Initialise sensor with given parameters / settings
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
bool Adafruit_BME280::begin(uint8_t addr,
|
bool Adafruit_BME280::begin(uint8_t addr)
|
||||||
sensor_mode mode,
|
|
||||||
sensor_sampling tempSampling,
|
|
||||||
sensor_sampling pressSampling,
|
|
||||||
sensor_sampling humSampling,
|
|
||||||
sensor_filter filter,
|
|
||||||
standby_duration duration
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
_i2caddr = addr;
|
_i2caddr = addr;
|
||||||
|
|
||||||
|
|
@ -75,6 +68,27 @@ bool Adafruit_BME280::begin(uint8_t addr,
|
||||||
|
|
||||||
readCoefficients(); // read trimming parameters, see DS 4.2.2
|
readCoefficients(); // read trimming parameters, see DS 4.2.2
|
||||||
|
|
||||||
|
setSampling(); // use defaults
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief setup sensor with given parameters / settings
|
||||||
|
|
||||||
|
This is simply a overload to the normal begin()-function, so SPI users
|
||||||
|
don't get confused about the library requiring an address.
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
void Adafruit_BME280::setSampling(sensor_mode mode,
|
||||||
|
sensor_sampling tempSampling,
|
||||||
|
sensor_sampling pressSampling,
|
||||||
|
sensor_sampling humSampling,
|
||||||
|
sensor_filter filter,
|
||||||
|
standby_duration duration) {
|
||||||
_measReg.mode = mode;
|
_measReg.mode = mode;
|
||||||
_measReg.osrs_t = tempSampling;
|
_measReg.osrs_t = tempSampling;
|
||||||
_measReg.osrs_p = pressSampling;
|
_measReg.osrs_p = pressSampling;
|
||||||
|
|
@ -90,28 +104,6 @@ bool Adafruit_BME280::begin(uint8_t addr,
|
||||||
write8(BME280_REGISTER_CONTROLHUMID, _humReg.get());
|
write8(BME280_REGISTER_CONTROLHUMID, _humReg.get());
|
||||||
write8(BME280_REGISTER_CONFIG, _configReg.get());
|
write8(BME280_REGISTER_CONFIG, _configReg.get());
|
||||||
write8(BME280_REGISTER_CONTROL, _measReg.get());
|
write8(BME280_REGISTER_CONTROL, _measReg.get());
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/*!
|
|
||||||
@brief Initialise sensor with given parameters / settings
|
|
||||||
|
|
||||||
This is simply a overload to the normal begin()-function, so SPI users
|
|
||||||
don't get confused about the library requiring an address.
|
|
||||||
*/
|
|
||||||
/**************************************************************************/
|
|
||||||
bool Adafruit_BME280::begin(sensor_mode mode,
|
|
||||||
sensor_sampling tempSampling,
|
|
||||||
sensor_sampling pressSampling,
|
|
||||||
sensor_sampling humSampling,
|
|
||||||
sensor_filter filter,
|
|
||||||
standby_duration duration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return begin(BME280_ADDRESS, mode, tempSampling, pressSampling, humSampling, filter, duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,23 +166,15 @@ class Adafruit_BME280 {
|
||||||
Adafruit_BME280(int8_t cspin);
|
Adafruit_BME280(int8_t cspin);
|
||||||
Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
|
Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
|
||||||
|
|
||||||
bool begin(uint8_t addr = BME280_ADDRESS,
|
bool begin(uint8_t addr = BME280_ADDRESS);
|
||||||
sensor_mode mode = MODE_NORMAL,
|
|
||||||
sensor_sampling tempSampling = SAMPLING_X16,
|
void setSampling(sensor_mode mode = MODE_NORMAL,
|
||||||
sensor_sampling pressSampling = SAMPLING_X16,
|
sensor_sampling tempSampling = SAMPLING_X16,
|
||||||
sensor_sampling humSampling = SAMPLING_X16,
|
sensor_sampling pressSampling = SAMPLING_X16,
|
||||||
sensor_filter filter = FILTER_OFF,
|
sensor_sampling humSampling = SAMPLING_X16,
|
||||||
standby_duration duration = STANDBY_MS_0_5
|
sensor_filter filter = FILTER_OFF,
|
||||||
);
|
standby_duration duration = STANDBY_MS_0_5
|
||||||
|
);
|
||||||
// overload function without address (-> for SPI users)
|
|
||||||
bool begin(sensor_mode mode = MODE_NORMAL,
|
|
||||||
sensor_sampling tempSampling = SAMPLING_X16,
|
|
||||||
sensor_sampling pressSampling = SAMPLING_X16,
|
|
||||||
sensor_sampling humSampling = SAMPLING_X16,
|
|
||||||
sensor_filter filter = FILTER_OFF,
|
|
||||||
standby_duration duration = STANDBY_MS_0_5
|
|
||||||
);
|
|
||||||
|
|
||||||
void takeForcedMeasurement();
|
void takeForcedMeasurement();
|
||||||
float readTemperature(void);
|
float readTemperature(void);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,157 @@
|
||||||
|
/***************************************************************************
|
||||||
|
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
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
|
|
||||||
|
#define BME_SCK 13
|
||||||
|
#define BME_MISO 12
|
||||||
|
#define BME_MOSI 11
|
||||||
|
#define BME_CS 10
|
||||||
|
|
||||||
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.println(F("BME280 test"));
|
||||||
|
|
||||||
|
if (! bme.begin()) {
|
||||||
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("-- Default Test --");
|
||||||
|
Serial.println("normal mode, 16x oversampling for all, filter off,");
|
||||||
|
Serial.println("0.5ms standby period");
|
||||||
|
delayTime = 5000;
|
||||||
|
|
||||||
|
|
||||||
|
// For more details on the following scenarious, see chapter
|
||||||
|
// 3.5 "Recommended modes of operation" in the datasheet
|
||||||
|
|
||||||
|
/*
|
||||||
|
// weather monitoring
|
||||||
|
Serial.println("-- Weather Station Scenario --");
|
||||||
|
Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
|
||||||
|
Serial.println("filter off");
|
||||||
|
bme.setSampling(Adafruit_BME280::MODE_FORCED,
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // temperature
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // pressure
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // humidity
|
||||||
|
Adafruit_BME280::FILTER_OFF );
|
||||||
|
|
||||||
|
// suggested rate is 1/60Hz (1m)
|
||||||
|
delayTime = 60000; // in milliseconds
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// humidity sensing
|
||||||
|
Serial.println("-- Humidity Sensing Scenario --");
|
||||||
|
Serial.println("forced mode, 1x temperature / 1x humidity / 0x pressure oversampling");
|
||||||
|
Serial.println("= pressure off, filter off");
|
||||||
|
bme.setSampling(Adafruit_BME280::MODE_FORCED,
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // temperature
|
||||||
|
Adafruit_BME280::SAMPLING_NONE, // pressure
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // humidity
|
||||||
|
Adafruit_BME280::FILTER_OFF );
|
||||||
|
|
||||||
|
// suggested rate is 1Hz (1s)
|
||||||
|
delayTime = 1000; // in milliseconds
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// indoor navigation
|
||||||
|
Serial.println("-- Indoor Navigation Scenario --");
|
||||||
|
Serial.println("normal mode, 16x pressure / 2x temperature / 1x humidity oversampling,");
|
||||||
|
Serial.println("0.5ms standby period, filter 16x");
|
||||||
|
bme.setSampling(Adafruit_BME280::MODE_NORMAL,
|
||||||
|
Adafruit_BME280::SAMPLING_X2, // temperature
|
||||||
|
Adafruit_BME280::SAMPLING_X16, // pressure
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // humidity
|
||||||
|
Adafruit_BME280::FILTER_X16,
|
||||||
|
Adafruit_BME280::STANDBY_MS_0_5 );
|
||||||
|
|
||||||
|
// suggested rate is 25Hz
|
||||||
|
// 1 + (2 * T_ovs) + (2 * P_ovs + 0.5) + (2 * H_ovs + 0.5)
|
||||||
|
// T_ovs = 2
|
||||||
|
// P_ovs = 16
|
||||||
|
// H_ovs = 1
|
||||||
|
// = 40ms (25Hz)
|
||||||
|
// with standby time that should really be 24.16913... Hz
|
||||||
|
delayTime = 41;
|
||||||
|
|
||||||
|
/*
|
||||||
|
// gaming
|
||||||
|
Serial.println("-- Gaming Scenario --");
|
||||||
|
Serial.println("normal mode, 4x pressure / 1x temperature / 0x humidity oversampling,");
|
||||||
|
Serial.println("= humidity off, 0.5ms standby period, filter 16x");
|
||||||
|
bme.setSampling(Adafruit_BME280::MODE_NORMAL,
|
||||||
|
Adafruit_BME280::SAMPLING_X1, // temperature
|
||||||
|
Adafruit_BME280::SAMPLING_X4, // pressure
|
||||||
|
Adafruit_BME280::SAMPLING_NONE, // humidity
|
||||||
|
Adafruit_BME280::FILTER_X16,
|
||||||
|
Adafruit_BME280::STANDBY_MS_0_5 );
|
||||||
|
|
||||||
|
// Suggested rate is 83Hz
|
||||||
|
// 1 + (2 * T_ovs) + (2 * P_ovs + 0.5)
|
||||||
|
// T_ovs = 1
|
||||||
|
// P_ovs = 4
|
||||||
|
// = 11.5ms + 0.5ms standby
|
||||||
|
delayTime = 12;
|
||||||
|
*/
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Only needed in forced mode! In normal mode, you can remove the next line.
|
||||||
|
bme.takeForcedMeasurement(); // has no effect in normal mode
|
||||||
|
|
||||||
|
printValues();
|
||||||
|
delay(delayTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printValues() {
|
||||||
|
Serial.print("Temperature = ");
|
||||||
|
Serial.print(bme.readTemperature());
|
||||||
|
Serial.println(" *C");
|
||||||
|
|
||||||
|
Serial.print("Pressure = ");
|
||||||
|
|
||||||
|
Serial.print(bme.readPressure() / 100.0F);
|
||||||
|
Serial.println(" hPa");
|
||||||
|
|
||||||
|
Serial.print("Approx. Altitude = ");
|
||||||
|
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
|
||||||
|
Serial.println(" m");
|
||||||
|
|
||||||
|
Serial.print("Humidity = ");
|
||||||
|
Serial.print(bme.readHumidity());
|
||||||
|
Serial.println(" %");
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
@ -41,107 +41,19 @@ void setup() {
|
||||||
|
|
||||||
// default settings
|
// default settings
|
||||||
status = bme.begin();
|
status = bme.begin();
|
||||||
Serial.println("-- Default Test --");
|
|
||||||
Serial.println("normal mode, 16x oversampling for all, filter off,");
|
|
||||||
Serial.println("0.5ms standby period");
|
|
||||||
delayTime = 5000;
|
|
||||||
|
|
||||||
|
|
||||||
// For more details on the following scenarious, see chapter
|
|
||||||
// 3.5 "Recommended modes of operation" in the datasheet
|
|
||||||
|
|
||||||
/*
|
|
||||||
// weather monitoring
|
|
||||||
Serial.println("-- Weather Station Scenario --");
|
|
||||||
Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
|
|
||||||
Serial.println("filter off");
|
|
||||||
status = bme.begin(Adafruit_BME280::MODE_FORCED,
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // temperature
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // pressure
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // humidity
|
|
||||||
Adafruit_BME280::FILTER_OFF
|
|
||||||
);
|
|
||||||
|
|
||||||
// suggested rate is 1/60Hz (1m)
|
|
||||||
delayTime = 60e3;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// humidity sensing
|
|
||||||
Serial.println("-- Humidity Sensing Scenario --");
|
|
||||||
Serial.println("forced mode, 1x temperature / 1x humidity / 0x pressure oversampling");
|
|
||||||
Serial.println("= pressure off, filter off");
|
|
||||||
status = bme.begin(Adafruit_BME280::MODE_FORCED,
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // temperature
|
|
||||||
Adafruit_BME280::SAMPLING_NONE, // pressure
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // humidity
|
|
||||||
Adafruit_BME280::FILTER_OFF
|
|
||||||
);
|
|
||||||
|
|
||||||
// suggested rate is 1Hz (1s)
|
|
||||||
delayTime = 1e3;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// indoor navigation
|
|
||||||
Serial.println("-- Indoor Navigation Scenario --");
|
|
||||||
Serial.println("normal mode, 16x pressure / 2x temperature / 1x humidity oversampling,");
|
|
||||||
Serial.println("0.5ms standby period, filter 16x");
|
|
||||||
status = bme.begin(Adafruit_BME280::MODE_NORMAL,
|
|
||||||
Adafruit_BME280::SAMPLING_X2, // temperature
|
|
||||||
Adafruit_BME280::SAMPLING_X16, // pressure
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // humidity
|
|
||||||
Adafruit_BME280::FILTER_X16,
|
|
||||||
Adafruit_BME280::STANDBY_MS_0_5
|
|
||||||
);
|
|
||||||
|
|
||||||
// suggested rate is 25Hz
|
|
||||||
// 1 + (2 * T_ovs) + (2 * P_ovs + 0.5) + (2 * H_ovs + 0.5)
|
|
||||||
// T_ovs = 2
|
|
||||||
// P_ovs = 16
|
|
||||||
// H_ovs = 1
|
|
||||||
// = 40ms (25Hz)
|
|
||||||
// with standby time that should really be 24.16913... Hz
|
|
||||||
delayTime = 41;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// gaming
|
|
||||||
Serial.println("-- Gaming Scenario --");
|
|
||||||
Serial.println("normal mode, 4x pressure / 1x temperature / 0x humidity oversampling,");
|
|
||||||
Serial.println("= humidity off, 0.5ms standby period, filter 16x");
|
|
||||||
status = bme.begin(Adafruit_BME280::MODE_NORMAL,
|
|
||||||
Adafruit_BME280::SAMPLING_X1, // temperature
|
|
||||||
Adafruit_BME280::SAMPLING_X4, // pressure
|
|
||||||
Adafruit_BME280::SAMPLING_NONE, // humidity
|
|
||||||
Adafruit_BME280::FILTER_X16,
|
|
||||||
Adafruit_BME280::STANDBY_MS_0_5
|
|
||||||
);
|
|
||||||
|
|
||||||
// Suggested rate is 83Hz
|
|
||||||
// 1 + (2 * T_ovs) + (2 * P_ovs + 0.5)
|
|
||||||
// T_ovs = 1
|
|
||||||
// P_ovs = 4
|
|
||||||
// = 11.5ms + 0.5ms standby
|
|
||||||
delayTime = 12;
|
|
||||||
*/
|
|
||||||
|
|
||||||
Serial.println();
|
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.println("-- Default Test --");
|
||||||
|
delayTime = 1000;
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Only needed in forced mode! In normal mode, you can remove the next line.
|
|
||||||
bme.takeForcedMeasurement(); // has no effect in normal mode
|
|
||||||
|
|
||||||
printValues();
|
printValues();
|
||||||
delay(delayTime);
|
delay(delayTime);
|
||||||
}
|
}
|
||||||
|
|
@ -166,4 +78,4 @@ void printValues() {
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue