Updated required libraries
This commit is contained in:
parent
dc2eb61584
commit
3e206715fd
50 changed files with 3960 additions and 208 deletions
493
firmware/libraries/Adafruit_BMP280_Library/Adafruit_BMP280.cpp
Normal file
493
firmware/libraries/Adafruit_BMP280_Library/Adafruit_BMP280.cpp
Normal file
|
@ -0,0 +1,493 @@
|
|||
/*!
|
||||
* @file Adafruit_BMP280.cpp
|
||||
*
|
||||
* This is a library for the BMP280 orientation sensor
|
||||
*
|
||||
* Designed specifically to work with the Adafruit BMP280 Sensor.
|
||||
*
|
||||
* Pick one up today in the adafruit shop!
|
||||
* ------> https://www.adafruit.com/product/2651
|
||||
*
|
||||
* These sensors use I2C to communicate, 2 pins are required to interface.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit andopen-source hardware by purchasing products
|
||||
* from Adafruit!
|
||||
*
|
||||
* K.Townsend (Adafruit Industries)
|
||||
*
|
||||
* BSD license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#include <Adafruit_BMP280.h>
|
||||
|
||||
/*!
|
||||
* @brief BMP280 constructor using i2c
|
||||
* @param *theWire
|
||||
* optional wire
|
||||
*/
|
||||
Adafruit_BMP280::Adafruit_BMP280(TwoWire *theWire) {
|
||||
_wire = theWire;
|
||||
temp_sensor = new Adafruit_BMP280_Temp(this);
|
||||
pressure_sensor = new Adafruit_BMP280_Pressure(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief BMP280 constructor using hardware SPI
|
||||
* @param cspin
|
||||
* cs pin number
|
||||
* @param theSPI
|
||||
* optional SPI object
|
||||
*/
|
||||
Adafruit_BMP280::Adafruit_BMP280(int8_t cspin, SPIClass *theSPI) {
|
||||
spi_dev = new Adafruit_SPIDevice(cspin, 1000000, SPI_BITORDER_MSBFIRST,
|
||||
SPI_MODE0, theSPI);
|
||||
temp_sensor = new Adafruit_BMP280_Temp(this);
|
||||
pressure_sensor = new Adafruit_BMP280_Pressure(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief BMP280 constructor using bitbang SPI
|
||||
* @param cspin
|
||||
* The pin to use for CS/SSEL.
|
||||
* @param mosipin
|
||||
* The pin to use for MOSI.
|
||||
* @param misopin
|
||||
* The pin to use for MISO.
|
||||
* @param sckpin
|
||||
* The pin to use for SCK.
|
||||
*/
|
||||
Adafruit_BMP280::Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin,
|
||||
int8_t sckpin) {
|
||||
spi_dev = new Adafruit_SPIDevice(cspin, sckpin, misopin, mosipin);
|
||||
temp_sensor = new Adafruit_BMP280_Temp(this);
|
||||
pressure_sensor = new Adafruit_BMP280_Pressure(this);
|
||||
}
|
||||
|
||||
Adafruit_BMP280::~Adafruit_BMP280(void) {
|
||||
if (spi_dev)
|
||||
delete spi_dev;
|
||||
if (i2c_dev)
|
||||
delete i2c_dev;
|
||||
if (temp_sensor)
|
||||
delete temp_sensor;
|
||||
if (pressure_sensor)
|
||||
delete pressure_sensor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Initialises the sensor.
|
||||
* @param addr
|
||||
* The I2C address to use (default = 0x77)
|
||||
* @param chipid
|
||||
* The expected chip ID (used to validate connection).
|
||||
* @return True if the init was successful, otherwise false.
|
||||
*/
|
||||
bool Adafruit_BMP280::begin(uint8_t addr, uint8_t chipid) {
|
||||
if (spi_dev == NULL) {
|
||||
// I2C mode
|
||||
if (i2c_dev)
|
||||
delete i2c_dev;
|
||||
i2c_dev = new Adafruit_I2CDevice(addr, _wire);
|
||||
if (!i2c_dev->begin())
|
||||
return false;
|
||||
} else {
|
||||
// SPI mode
|
||||
if (!spi_dev->begin())
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if sensor, i.e. the chip ID is correct
|
||||
_sensorID = read8(BMP280_REGISTER_CHIPID);
|
||||
if (_sensorID != chipid)
|
||||
return false;
|
||||
|
||||
readCoefficients();
|
||||
// write8(BMP280_REGISTER_CONTROL, 0x3F); /* needed? */
|
||||
setSampling();
|
||||
delay(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sets the sampling config for the device.
|
||||
* @param mode
|
||||
* The operating mode of the sensor.
|
||||
* @param tempSampling
|
||||
* The sampling scheme for temp readings.
|
||||
* @param pressSampling
|
||||
* The sampling scheme for pressure readings.
|
||||
* @param filter
|
||||
* The filtering mode to apply (if any).
|
||||
* @param duration
|
||||
* The sampling duration.
|
||||
*/
|
||||
void Adafruit_BMP280::setSampling(sensor_mode mode,
|
||||
sensor_sampling tempSampling,
|
||||
sensor_sampling pressSampling,
|
||||
sensor_filter filter,
|
||||
standby_duration duration) {
|
||||
if (!_sensorID)
|
||||
return; // begin() not called yet
|
||||
_measReg.mode = mode;
|
||||
_measReg.osrs_t = tempSampling;
|
||||
_measReg.osrs_p = pressSampling;
|
||||
|
||||
_configReg.filter = filter;
|
||||
_configReg.t_sb = duration;
|
||||
|
||||
write8(BMP280_REGISTER_CONFIG, _configReg.get());
|
||||
write8(BMP280_REGISTER_CONTROL, _measReg.get());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Writes an 8 bit value over I2C/SPI
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_BMP280::write8(byte reg, byte value) {
|
||||
byte buffer[2];
|
||||
buffer[1] = value;
|
||||
if (i2c_dev) {
|
||||
buffer[0] = reg;
|
||||
i2c_dev->write(buffer, 2);
|
||||
} else {
|
||||
buffer[0] = reg & ~0x80;
|
||||
spi_dev->write(buffer, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads an 8 bit value over I2C/SPI
|
||||
* @param reg
|
||||
* selected register
|
||||
* @return value from selected register
|
||||
*/
|
||||
uint8_t Adafruit_BMP280::read8(byte reg) {
|
||||
uint8_t buffer[1];
|
||||
if (i2c_dev) {
|
||||
buffer[0] = uint8_t(reg);
|
||||
i2c_dev->write_then_read(buffer, 1, buffer, 1);
|
||||
} else {
|
||||
buffer[0] = uint8_t(reg | 0x80);
|
||||
spi_dev->write_then_read(buffer, 1, buffer, 1);
|
||||
}
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads a 16 bit value over I2C/SPI
|
||||
*/
|
||||
uint16_t Adafruit_BMP280::read16(byte reg) {
|
||||
uint8_t buffer[2];
|
||||
|
||||
if (i2c_dev) {
|
||||
buffer[0] = uint8_t(reg);
|
||||
i2c_dev->write_then_read(buffer, 1, buffer, 2);
|
||||
} else {
|
||||
buffer[0] = uint8_t(reg | 0x80);
|
||||
spi_dev->write_then_read(buffer, 1, buffer, 2);
|
||||
}
|
||||
return uint16_t(buffer[0]) << 8 | uint16_t(buffer[1]);
|
||||
}
|
||||
|
||||
uint16_t Adafruit_BMP280::read16_LE(byte reg) {
|
||||
uint16_t temp = read16(reg);
|
||||
return (temp >> 8) | (temp << 8);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads a signed 16 bit value over I2C/SPI
|
||||
*/
|
||||
int16_t Adafruit_BMP280::readS16(byte reg) { return (int16_t)read16(reg); }
|
||||
|
||||
int16_t Adafruit_BMP280::readS16_LE(byte reg) {
|
||||
return (int16_t)read16_LE(reg);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads a 24 bit value over I2C/SPI
|
||||
*/
|
||||
uint32_t Adafruit_BMP280::read24(byte reg) {
|
||||
uint8_t buffer[3];
|
||||
|
||||
if (i2c_dev) {
|
||||
buffer[0] = uint8_t(reg);
|
||||
i2c_dev->write_then_read(buffer, 1, buffer, 3);
|
||||
} else {
|
||||
buffer[0] = uint8_t(reg | 0x80);
|
||||
spi_dev->write_then_read(buffer, 1, buffer, 3);
|
||||
}
|
||||
return uint32_t(buffer[0]) << 16 | uint32_t(buffer[1]) << 8 |
|
||||
uint32_t(buffer[2]);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads the factory-set coefficients
|
||||
*/
|
||||
void Adafruit_BMP280::readCoefficients() {
|
||||
_bmp280_calib.dig_T1 = read16_LE(BMP280_REGISTER_DIG_T1);
|
||||
_bmp280_calib.dig_T2 = readS16_LE(BMP280_REGISTER_DIG_T2);
|
||||
_bmp280_calib.dig_T3 = readS16_LE(BMP280_REGISTER_DIG_T3);
|
||||
|
||||
_bmp280_calib.dig_P1 = read16_LE(BMP280_REGISTER_DIG_P1);
|
||||
_bmp280_calib.dig_P2 = readS16_LE(BMP280_REGISTER_DIG_P2);
|
||||
_bmp280_calib.dig_P3 = readS16_LE(BMP280_REGISTER_DIG_P3);
|
||||
_bmp280_calib.dig_P4 = readS16_LE(BMP280_REGISTER_DIG_P4);
|
||||
_bmp280_calib.dig_P5 = readS16_LE(BMP280_REGISTER_DIG_P5);
|
||||
_bmp280_calib.dig_P6 = readS16_LE(BMP280_REGISTER_DIG_P6);
|
||||
_bmp280_calib.dig_P7 = readS16_LE(BMP280_REGISTER_DIG_P7);
|
||||
_bmp280_calib.dig_P8 = readS16_LE(BMP280_REGISTER_DIG_P8);
|
||||
_bmp280_calib.dig_P9 = readS16_LE(BMP280_REGISTER_DIG_P9);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Reads the temperature from the device.
|
||||
* @return The temperature in degrees celsius.
|
||||
*/
|
||||
float Adafruit_BMP280::readTemperature() {
|
||||
int32_t var1, var2;
|
||||
if (!_sensorID)
|
||||
return NAN; // begin() not called yet
|
||||
|
||||
int32_t adc_T = read24(BMP280_REGISTER_TEMPDATA);
|
||||
adc_T >>= 4;
|
||||
|
||||
var1 = ((((adc_T >> 3) - ((int32_t)_bmp280_calib.dig_T1 << 1))) *
|
||||
((int32_t)_bmp280_calib.dig_T2)) >>
|
||||
11;
|
||||
|
||||
var2 = (((((adc_T >> 4) - ((int32_t)_bmp280_calib.dig_T1)) *
|
||||
((adc_T >> 4) - ((int32_t)_bmp280_calib.dig_T1))) >>
|
||||
12) *
|
||||
((int32_t)_bmp280_calib.dig_T3)) >>
|
||||
14;
|
||||
|
||||
t_fine = var1 + var2;
|
||||
|
||||
float T = (t_fine * 5 + 128) >> 8;
|
||||
return T / 100;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Reads the barometric pressure from the device.
|
||||
* @return Barometric pressure in Pa.
|
||||
*/
|
||||
float Adafruit_BMP280::readPressure() {
|
||||
int64_t var1, var2, p;
|
||||
if (!_sensorID)
|
||||
return NAN; // begin() not called yet
|
||||
|
||||
// Must be done first to get the t_fine variable set up
|
||||
readTemperature();
|
||||
|
||||
int32_t adc_P = read24(BMP280_REGISTER_PRESSUREDATA);
|
||||
adc_P >>= 4;
|
||||
|
||||
var1 = ((int64_t)t_fine) - 128000;
|
||||
var2 = var1 * var1 * (int64_t)_bmp280_calib.dig_P6;
|
||||
var2 = var2 + ((var1 * (int64_t)_bmp280_calib.dig_P5) << 17);
|
||||
var2 = var2 + (((int64_t)_bmp280_calib.dig_P4) << 35);
|
||||
var1 = ((var1 * var1 * (int64_t)_bmp280_calib.dig_P3) >> 8) +
|
||||
((var1 * (int64_t)_bmp280_calib.dig_P2) << 12);
|
||||
var1 =
|
||||
(((((int64_t)1) << 47) + var1)) * ((int64_t)_bmp280_calib.dig_P1) >> 33;
|
||||
|
||||
if (var1 == 0) {
|
||||
return 0; // avoid exception caused by division by zero
|
||||
}
|
||||
p = 1048576 - adc_P;
|
||||
p = (((p << 31) - var2) * 3125) / var1;
|
||||
var1 = (((int64_t)_bmp280_calib.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
|
||||
var2 = (((int64_t)_bmp280_calib.dig_P8) * p) >> 19;
|
||||
|
||||
p = ((p + var1 + var2) >> 8) + (((int64_t)_bmp280_calib.dig_P7) << 4);
|
||||
return (float)p / 256;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Calculates the approximate altitude using barometric pressure and the
|
||||
* supplied sea level hPa as a reference.
|
||||
* @param seaLevelhPa
|
||||
* The current hPa at sea level.
|
||||
* @return The approximate altitude above sea level in meters.
|
||||
*/
|
||||
float Adafruit_BMP280::readAltitude(float seaLevelhPa) {
|
||||
float altitude;
|
||||
|
||||
float pressure = readPressure(); // in Si units for Pascal
|
||||
pressure /= 100;
|
||||
|
||||
altitude = 44330 * (1.0 - pow(pressure / seaLevelhPa, 0.1903));
|
||||
|
||||
return altitude;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Calculates the pressure at sea level (QNH) from the specified altitude,
|
||||
* and atmospheric pressure (QFE).
|
||||
* @param altitude Altitude in m
|
||||
* @param atmospheric Atmospheric pressure in hPa
|
||||
* @return The approximate pressure in hPa
|
||||
*/
|
||||
float Adafruit_BMP280::seaLevelForAltitude(float altitude, float atmospheric) {
|
||||
// Equation taken from BMP180 datasheet (page 17):
|
||||
// http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
|
||||
|
||||
// Note that using the equation from wikipedia can give bad results
|
||||
// at high altitude. See this thread for more information:
|
||||
// http://forums.adafruit.com/viewtopic.php?f=22&t=58064
|
||||
return atmospheric / pow(1.0 - (altitude / 44330.0), 5.255);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief calculates the boiling point of water by a given pressure
|
||||
@param pressure pressure in hPa
|
||||
@return temperature in °C
|
||||
*/
|
||||
|
||||
float Adafruit_BMP280::waterBoilingPoint(float pressure) {
|
||||
// Magnusformular for calculation of the boiling point of water at a given
|
||||
// pressure
|
||||
return (234.175 * log(pressure / 6.1078)) /
|
||||
(17.08085 - log(pressure / 6.1078));
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Take a new measurement (only possible in forced mode)
|
||||
@return true if successful, otherwise false
|
||||
*/
|
||||
bool Adafruit_BMP280::takeForcedMeasurement() {
|
||||
// If we are in forced mode, the BME sensor goes back to sleep after each
|
||||
// measurement and we need to set it to forced mode once at this point, so
|
||||
// it will take the next measurement and then return to sleep again.
|
||||
// In normal mode simply does new measurements periodically.
|
||||
if (_measReg.mode == MODE_FORCED) {
|
||||
// set to forced mode, i.e. "take next measurement"
|
||||
write8(BMP280_REGISTER_CONTROL, _measReg.get());
|
||||
// wait until measurement has been completed, otherwise we would read
|
||||
// the values from the last measurement
|
||||
while (read8(BMP280_REGISTER_STATUS) & 0x08)
|
||||
delay(1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Resets the chip via soft reset
|
||||
*/
|
||||
void Adafruit_BMP280::reset(void) {
|
||||
write8(BMP280_REGISTER_SOFTRESET, MODE_SOFT_RESET_CODE);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns Sensor ID for diagnostics
|
||||
* @returns 0x61 for BME680, 0x60 for BME280, 0x56, 0x57, 0x58 for BMP280
|
||||
*/
|
||||
uint8_t Adafruit_BMP280::sensorID(void) { return _sensorID; };
|
||||
|
||||
/*!
|
||||
@brief Gets the most recent sensor event from the hardware status register.
|
||||
@return Sensor status as a byte.
|
||||
*/
|
||||
uint8_t Adafruit_BMP280::getStatus(void) {
|
||||
return read8(BMP280_REGISTER_STATUS);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Gets an Adafruit Unified Sensor object for the temp sensor component
|
||||
@return Adafruit_Sensor pointer to temperature sensor
|
||||
*/
|
||||
Adafruit_Sensor *Adafruit_BMP280::getTemperatureSensor(void) {
|
||||
return temp_sensor;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Gets an Adafruit Unified Sensor object for the pressure sensor
|
||||
component
|
||||
@return Adafruit_Sensor pointer to pressure sensor
|
||||
*/
|
||||
Adafruit_Sensor *Adafruit_BMP280::getPressureSensor(void) {
|
||||
return pressure_sensor;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the sensor_t data for the BMP280's temperature sensor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_BMP280_Temp::getSensor(sensor_t *sensor) {
|
||||
/* Clear the sensor_t object */
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
|
||||
/* Insert the sensor name in the fixed length char array */
|
||||
strncpy(sensor->name, "BMP280", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name) - 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
|
||||
sensor->min_delay = 0;
|
||||
sensor->min_value = -40.0; /* Temperature range -40 ~ +85 C */
|
||||
sensor->max_value = +85.0;
|
||||
sensor->resolution = 0.01; /* 0.01 C */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the temperature as a standard sensor event
|
||||
@param event Sensor event object that will be populated
|
||||
@returns True
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_BMP280_Temp::getEvent(sensors_event_t *event) {
|
||||
/* Clear the event */
|
||||
memset(event, 0, sizeof(sensors_event_t));
|
||||
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->sensor_id = _sensorID;
|
||||
event->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
|
||||
event->timestamp = millis();
|
||||
event->temperature = _theBMP280->readTemperature();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the sensor_t data for the BMP280's pressure sensor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_BMP280_Pressure::getSensor(sensor_t *sensor) {
|
||||
/* Clear the sensor_t object */
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
|
||||
/* Insert the sensor name in the fixed length char array */
|
||||
strncpy(sensor->name, "BMP280", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name) - 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_PRESSURE;
|
||||
sensor->min_delay = 0;
|
||||
sensor->min_value = 300.0; /* 300 ~ 1100 hPa */
|
||||
sensor->max_value = 1100.0;
|
||||
sensor->resolution = 0.012; /* 0.12 hPa relative */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the pressure as a standard sensor event
|
||||
@param event Sensor event object that will be populated
|
||||
@returns True
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_BMP280_Pressure::getEvent(sensors_event_t *event) {
|
||||
/* Clear the event */
|
||||
memset(event, 0, sizeof(sensors_event_t));
|
||||
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->sensor_id = _sensorID;
|
||||
event->type = SENSOR_TYPE_PRESSURE;
|
||||
event->timestamp = millis();
|
||||
event->pressure = _theBMP280->readPressure() / 100; // convert Pa to hPa
|
||||
return true;
|
||||
}
|
267
firmware/libraries/Adafruit_BMP280_Library/Adafruit_BMP280.h
Normal file
267
firmware/libraries/Adafruit_BMP280_Library/Adafruit_BMP280.h
Normal file
|
@ -0,0 +1,267 @@
|
|||
/*!
|
||||
* @file Adafruit_BMP280.h
|
||||
*
|
||||
* This is a library for the Adafruit BMP280 Breakout.
|
||||
*
|
||||
* Designed specifically to work with the Adafruit BMP280 Breakout.
|
||||
*
|
||||
* Pick one up today in the adafruit shop!
|
||||
* ------> https://www.adafruit.com/product/2651
|
||||
*
|
||||
* These sensors use I2C to communicate, 2 pins are required to interface.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit andopen-source hardware by purchasing products
|
||||
* from Adafruit!
|
||||
*
|
||||
* K.Townsend (Adafruit Industries)
|
||||
*
|
||||
* BSD license, all text above must be included in any redistribution
|
||||
*/
|
||||
#ifndef __BMP280_H__
|
||||
#define __BMP280_H__
|
||||
|
||||
// clang-format off
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_SPIDevice.h>
|
||||
// clang-format on
|
||||
|
||||
/*!
|
||||
* I2C ADDRESS/BITS/SETTINGS
|
||||
*/
|
||||
#define BMP280_ADDRESS (0x77) /**< The default I2C address for the sensor. */
|
||||
#define BMP280_ADDRESS_ALT \
|
||||
(0x76) /**< Alternative I2C address for the sensor. */
|
||||
#define BMP280_CHIPID (0x58) /**< Default chip ID. */
|
||||
|
||||
/*!
|
||||
* Registers available on the sensor.
|
||||
*/
|
||||
enum {
|
||||
BMP280_REGISTER_DIG_T1 = 0x88,
|
||||
BMP280_REGISTER_DIG_T2 = 0x8A,
|
||||
BMP280_REGISTER_DIG_T3 = 0x8C,
|
||||
BMP280_REGISTER_DIG_P1 = 0x8E,
|
||||
BMP280_REGISTER_DIG_P2 = 0x90,
|
||||
BMP280_REGISTER_DIG_P3 = 0x92,
|
||||
BMP280_REGISTER_DIG_P4 = 0x94,
|
||||
BMP280_REGISTER_DIG_P5 = 0x96,
|
||||
BMP280_REGISTER_DIG_P6 = 0x98,
|
||||
BMP280_REGISTER_DIG_P7 = 0x9A,
|
||||
BMP280_REGISTER_DIG_P8 = 0x9C,
|
||||
BMP280_REGISTER_DIG_P9 = 0x9E,
|
||||
BMP280_REGISTER_CHIPID = 0xD0,
|
||||
BMP280_REGISTER_VERSION = 0xD1,
|
||||
BMP280_REGISTER_SOFTRESET = 0xE0,
|
||||
BMP280_REGISTER_CAL26 = 0xE1, /**< R calibration = 0xE1-0xF0 */
|
||||
BMP280_REGISTER_STATUS = 0xF3,
|
||||
BMP280_REGISTER_CONTROL = 0xF4,
|
||||
BMP280_REGISTER_CONFIG = 0xF5,
|
||||
BMP280_REGISTER_PRESSUREDATA = 0xF7,
|
||||
BMP280_REGISTER_TEMPDATA = 0xFA,
|
||||
};
|
||||
|
||||
/*!
|
||||
* Struct to hold calibration data.
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t dig_T1; /**< dig_T1 cal register. */
|
||||
int16_t dig_T2; /**< dig_T2 cal register. */
|
||||
int16_t dig_T3; /**< dig_T3 cal register. */
|
||||
|
||||
uint16_t dig_P1; /**< dig_P1 cal register. */
|
||||
int16_t dig_P2; /**< dig_P2 cal register. */
|
||||
int16_t dig_P3; /**< dig_P3 cal register. */
|
||||
int16_t dig_P4; /**< dig_P4 cal register. */
|
||||
int16_t dig_P5; /**< dig_P5 cal register. */
|
||||
int16_t dig_P6; /**< dig_P6 cal register. */
|
||||
int16_t dig_P7; /**< dig_P7 cal register. */
|
||||
int16_t dig_P8; /**< dig_P8 cal register. */
|
||||
int16_t dig_P9; /**< dig_P9 cal register. */
|
||||
} bmp280_calib_data;
|
||||
|
||||
class Adafruit_BMP280;
|
||||
|
||||
/** Adafruit Unified Sensor interface for temperature component of BMP280 */
|
||||
class Adafruit_BMP280_Temp : public Adafruit_Sensor {
|
||||
public:
|
||||
/** @brief Create an Adafruit_Sensor compatible object for the temp sensor
|
||||
@param parent A pointer to the BMP280 class */
|
||||
Adafruit_BMP280_Temp(Adafruit_BMP280 *parent) { _theBMP280 = parent; }
|
||||
bool getEvent(sensors_event_t *);
|
||||
void getSensor(sensor_t *);
|
||||
|
||||
private:
|
||||
int _sensorID = 280;
|
||||
Adafruit_BMP280 *_theBMP280 = NULL;
|
||||
};
|
||||
|
||||
/** Adafruit Unified Sensor interface for pressure component of BMP280 */
|
||||
class Adafruit_BMP280_Pressure : public Adafruit_Sensor {
|
||||
public:
|
||||
/** @brief Create an Adafruit_Sensor compatible object for the pressure sensor
|
||||
@param parent A pointer to the BMP280 class */
|
||||
Adafruit_BMP280_Pressure(Adafruit_BMP280 *parent) { _theBMP280 = parent; }
|
||||
bool getEvent(sensors_event_t *);
|
||||
void getSensor(sensor_t *);
|
||||
|
||||
private:
|
||||
int _sensorID = 0;
|
||||
Adafruit_BMP280 *_theBMP280 = NULL;
|
||||
};
|
||||
|
||||
/**
|
||||
* Driver for the Adafruit BMP280 barometric pressure sensor.
|
||||
*/
|
||||
class Adafruit_BMP280 {
|
||||
public:
|
||||
/** Oversampling rate for the sensor. */
|
||||
enum sensor_sampling {
|
||||
/** No over-sampling. */
|
||||
SAMPLING_NONE = 0x00,
|
||||
/** 1x over-sampling. */
|
||||
SAMPLING_X1 = 0x01,
|
||||
/** 2x over-sampling. */
|
||||
SAMPLING_X2 = 0x02,
|
||||
/** 4x over-sampling. */
|
||||
SAMPLING_X4 = 0x03,
|
||||
/** 8x over-sampling. */
|
||||
SAMPLING_X8 = 0x04,
|
||||
/** 16x over-sampling. */
|
||||
SAMPLING_X16 = 0x05
|
||||
};
|
||||
|
||||
/** Operating mode for the sensor. */
|
||||
enum sensor_mode {
|
||||
/** Sleep mode. */
|
||||
MODE_SLEEP = 0x00,
|
||||
/** Forced mode. */
|
||||
MODE_FORCED = 0x01,
|
||||
/** Normal mode. */
|
||||
MODE_NORMAL = 0x03,
|
||||
/** Software reset. */
|
||||
MODE_SOFT_RESET_CODE = 0xB6
|
||||
};
|
||||
|
||||
/** Filtering level for sensor data. */
|
||||
enum sensor_filter {
|
||||
/** No filtering. */
|
||||
FILTER_OFF = 0x00,
|
||||
/** 2x filtering. */
|
||||
FILTER_X2 = 0x01,
|
||||
/** 4x filtering. */
|
||||
FILTER_X4 = 0x02,
|
||||
/** 8x filtering. */
|
||||
FILTER_X8 = 0x03,
|
||||
/** 16x filtering. */
|
||||
FILTER_X16 = 0x04
|
||||
};
|
||||
|
||||
/** Standby duration in ms */
|
||||
enum standby_duration {
|
||||
/** 1 ms standby. */
|
||||
STANDBY_MS_1 = 0x00,
|
||||
/** 62.5 ms standby. */
|
||||
STANDBY_MS_63 = 0x01,
|
||||
/** 125 ms standby. */
|
||||
STANDBY_MS_125 = 0x02,
|
||||
/** 250 ms standby. */
|
||||
STANDBY_MS_250 = 0x03,
|
||||
/** 500 ms standby. */
|
||||
STANDBY_MS_500 = 0x04,
|
||||
/** 1000 ms standby. */
|
||||
STANDBY_MS_1000 = 0x05,
|
||||
/** 2000 ms standby. */
|
||||
STANDBY_MS_2000 = 0x06,
|
||||
/** 4000 ms standby. */
|
||||
STANDBY_MS_4000 = 0x07
|
||||
};
|
||||
|
||||
Adafruit_BMP280(TwoWire *theWire = &Wire);
|
||||
Adafruit_BMP280(int8_t cspin, SPIClass *theSPI = &SPI);
|
||||
Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
|
||||
~Adafruit_BMP280(void);
|
||||
|
||||
bool begin(uint8_t addr = BMP280_ADDRESS, uint8_t chipid = BMP280_CHIPID);
|
||||
void reset(void);
|
||||
uint8_t getStatus(void);
|
||||
uint8_t sensorID(void);
|
||||
|
||||
float readTemperature();
|
||||
float readPressure(void);
|
||||
float readAltitude(float seaLevelhPa = 1013.25);
|
||||
float seaLevelForAltitude(float altitude, float atmospheric);
|
||||
float waterBoilingPoint(float pressure);
|
||||
bool takeForcedMeasurement();
|
||||
|
||||
Adafruit_Sensor *getTemperatureSensor(void);
|
||||
Adafruit_Sensor *getPressureSensor(void);
|
||||
|
||||
void setSampling(sensor_mode mode = MODE_NORMAL,
|
||||
sensor_sampling tempSampling = SAMPLING_X16,
|
||||
sensor_sampling pressSampling = SAMPLING_X16,
|
||||
sensor_filter filter = FILTER_OFF,
|
||||
standby_duration duration = STANDBY_MS_1);
|
||||
|
||||
private:
|
||||
TwoWire *_wire; /**< Wire object */
|
||||
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface
|
||||
Adafruit_SPIDevice *spi_dev = NULL; ///< Pointer to SPI bus interface
|
||||
|
||||
Adafruit_BMP280_Temp *temp_sensor = NULL;
|
||||
Adafruit_BMP280_Pressure *pressure_sensor = NULL;
|
||||
|
||||
/** Encapsulates the config register */
|
||||
struct config {
|
||||
/** Initialize to power-on-reset state */
|
||||
config() : t_sb(STANDBY_MS_1), filter(FILTER_OFF), none(0), spi3w_en(0) {}
|
||||
/** Inactive duration (standby time) in normal mode */
|
||||
unsigned int t_sb : 3;
|
||||
/** Filter settings */
|
||||
unsigned int filter : 3;
|
||||
/** Unused - don't set */
|
||||
unsigned int none : 1;
|
||||
/** Enables 3-wire SPI */
|
||||
unsigned int spi3w_en : 1;
|
||||
/** Used to retrieve the assembled config register's byte value. */
|
||||
unsigned int get() { return (t_sb << 5) | (filter << 2) | spi3w_en; }
|
||||
};
|
||||
|
||||
/** Encapsulates trhe ctrl_meas register */
|
||||
struct ctrl_meas {
|
||||
/** Initialize to power-on-reset state */
|
||||
ctrl_meas()
|
||||
: osrs_t(SAMPLING_NONE), osrs_p(SAMPLING_NONE), mode(MODE_SLEEP) {}
|
||||
/** Temperature oversampling. */
|
||||
unsigned int osrs_t : 3;
|
||||
/** Pressure oversampling. */
|
||||
unsigned int osrs_p : 3;
|
||||
/** Device mode */
|
||||
unsigned int mode : 2;
|
||||
/** Used to retrieve the assembled ctrl_meas register's byte value. */
|
||||
unsigned int get() { return (osrs_t << 5) | (osrs_p << 2) | mode; }
|
||||
};
|
||||
|
||||
void readCoefficients(void);
|
||||
uint8_t spixfer(uint8_t x);
|
||||
void write8(byte reg, byte value);
|
||||
uint8_t read8(byte reg);
|
||||
uint16_t read16(byte reg);
|
||||
uint32_t read24(byte reg);
|
||||
int16_t readS16(byte reg);
|
||||
uint16_t read16_LE(byte reg);
|
||||
int16_t readS16_LE(byte reg);
|
||||
|
||||
uint8_t _i2caddr;
|
||||
|
||||
int32_t _sensorID = 0;
|
||||
int32_t t_fine;
|
||||
// int8_t _cs, _mosi, _miso, _sck;
|
||||
bmp280_calib_data _bmp280_calib;
|
||||
config _configReg;
|
||||
ctrl_meas _measReg;
|
||||
};
|
||||
|
||||
#endif
|
47
firmware/libraries/Adafruit_BMP280_Library/README.md
Normal file
47
firmware/libraries/Adafruit_BMP280_Library/README.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Adafruit BMP280 Driver (Barometric Pressure Sensor) [](https://travis-ci.com/adafruit/Adafruit_BMP280_Library)
|
||||
|
||||
This driver is for the [Adafruit BMP280 Breakout](http://www.adafruit.com/products/2651)
|
||||
|
||||
<a href="https://www.adafruit.com/product/2651"><img src="assets/board.jpg" width="500"/></a>
|
||||
|
||||
## About the BMP280 ##
|
||||
|
||||
This precision sensor from Bosch is the best low-cost sensing solution for measuring barometric pressure and temperature. Because pressure changes with altitude you can also use it as an altimeter!
|
||||
|
||||
## About this Driver ##
|
||||
|
||||
Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||
|
||||
Written by Kevin (KTOWN) Townsend for Adafruit Industries.
|
||||
|
||||
<!-- START COMPATIBILITY TABLE -->
|
||||
|
||||
## Compatibility
|
||||
|
||||
MCU | Tested Works | Doesn't Work | Not Tested | Notes
|
||||
------------------ | :----------: | :----------: | :---------: | -----
|
||||
Atmega328 @ 16MHz | X | | |
|
||||
Atmega328 @ 12MHz | X | | |
|
||||
Atmega32u4 @ 16MHz | X | | | Use SDA/SCL on pins D2 & D3
|
||||
Atmega32u4 @ 8MHz | X | | | Use SDA/SCL on pins D2 & D3
|
||||
ESP8266 | X | | | SDA/SCL default to pins 4 & 5 but any two pins can be assigned as SDA/SCL using Wire.begin(SDA,SCL)
|
||||
Atmega2560 @ 16MHz | X | | | Use SDA/SCL on pins 20 & 21
|
||||
ATSAM3X8E | X | | | Use SDA/SCL on pins 20 & 21
|
||||
ATSAM21D | X | | |
|
||||
ATtiny85 @ 16MHz | | X | |
|
||||
ATtiny85 @ 8MHz | | X | |
|
||||
Intel Curie @ 32MHz | | | X |
|
||||
STM32F2 | | | X |
|
||||
|
||||
* ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
|
||||
* ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
|
||||
* ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
|
||||
* ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
|
||||
* ESP8266 : Adafruit Huzzah
|
||||
* ATmega2560 @ 16MHz : Arduino Mega
|
||||
* ATSAM3X8E : Arduino Due
|
||||
* ATSAM21D : Arduino Zero, M0 Pro
|
||||
* ATtiny85 @ 16MHz : Adafruit Trinket 5V
|
||||
* ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V
|
||||
|
||||
<!-- END COMPATIBILITY TABLE -->
|
BIN
firmware/libraries/Adafruit_BMP280_Library/assets/board.jpg
Normal file
BIN
firmware/libraries/Adafruit_BMP280_Library/assets/board.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 KiB |
|
@ -0,0 +1,72 @@
|
|||
/***************************************************************************
|
||||
This is a library for the BMP280 humidity, temperature & pressure sensor
|
||||
|
||||
Designed specifically to work with the Adafruit BMP280 Breakout
|
||||
----> http://www.adafruit.com/products/2651
|
||||
|
||||
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
|
||||
to interface.
|
||||
|
||||
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 <Adafruit_BMP280.h>
|
||||
|
||||
#define BMP_SCK (13)
|
||||
#define BMP_MISO (12)
|
||||
#define BMP_MOSI (11)
|
||||
#define BMP_CS (10)
|
||||
|
||||
Adafruit_BMP280 bmp; // I2C
|
||||
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
|
||||
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("BMP280 Forced Mode Test."));
|
||||
|
||||
//if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
|
||||
if (!bmp.begin()) {
|
||||
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
|
||||
"try a different address!"));
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
/* Default settings from datasheet. */
|
||||
bmp.setSampling(Adafruit_BMP280::MODE_FORCED, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// must call this to wake sensor up and get new measurement data
|
||||
// it blocks until measurement is complete
|
||||
if (bmp.takeForcedMeasurement()) {
|
||||
// can now print out the new measurements
|
||||
Serial.print(F("Temperature = "));
|
||||
Serial.print(bmp.readTemperature());
|
||||
Serial.println(" *C");
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(bmp.readPressure());
|
||||
Serial.println(" Pa");
|
||||
|
||||
Serial.print(F("Approx altitude = "));
|
||||
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
|
||||
Serial.println(" m");
|
||||
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
} else {
|
||||
Serial.println("Forced measurement failed!");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/***************************************************************************
|
||||
This is a library for the BMP280 humidity, temperature & pressure sensor
|
||||
This example shows how to take Sensor Events instead of direct readings
|
||||
|
||||
Designed specifically to work with the Adafruit BMP280 Breakout
|
||||
----> http://www.adafruit.com/products/2651
|
||||
|
||||
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
|
||||
to interface.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-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_BMP280.h>
|
||||
|
||||
Adafruit_BMP280 bmp; // use I2C interface
|
||||
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
|
||||
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while ( !Serial ) delay(100); // wait for native usb
|
||||
Serial.println(F("BMP280 Sensor event test"));
|
||||
|
||||
unsigned status;
|
||||
//status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
|
||||
status = bmp.begin();
|
||||
if (!status) {
|
||||
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
|
||||
"try a different address!"));
|
||||
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
||||
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
|
||||
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
|
||||
Serial.print(" ID of 0x60 represents a BME 280.\n");
|
||||
Serial.print(" ID of 0x61 represents a BME 680.\n");
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
/* Default settings from datasheet. */
|
||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||
|
||||
bmp_temp->printSensorDetails();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensors_event_t temp_event, pressure_event;
|
||||
bmp_temp->getEvent(&temp_event);
|
||||
bmp_pressure->getEvent(&pressure_event);
|
||||
|
||||
Serial.print(F("Temperature = "));
|
||||
Serial.print(temp_event.temperature);
|
||||
Serial.println(" *C");
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(pressure_event.pressure);
|
||||
Serial.println(" hPa");
|
||||
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/***************************************************************************
|
||||
This is a library for the BMP280 humidity, temperature & pressure sensor
|
||||
|
||||
Designed specifically to work with the Adafruit BMP280 Breakout
|
||||
----> http://www.adafruit.com/products/2651
|
||||
|
||||
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
|
||||
to interface.
|
||||
|
||||
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_BMP280.h>
|
||||
|
||||
#define BMP_SCK (13)
|
||||
#define BMP_MISO (12)
|
||||
#define BMP_MOSI (11)
|
||||
#define BMP_CS (10)
|
||||
|
||||
Adafruit_BMP280 bmp; // I2C
|
||||
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
|
||||
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while ( !Serial ) delay(100); // wait for native usb
|
||||
Serial.println(F("BMP280 test"));
|
||||
unsigned status;
|
||||
//status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
|
||||
status = bmp.begin();
|
||||
if (!status) {
|
||||
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
|
||||
"try a different address!"));
|
||||
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
||||
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
|
||||
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
|
||||
Serial.print(" ID of 0x60 represents a BME 280.\n");
|
||||
Serial.print(" ID of 0x61 represents a BME 680.\n");
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
/* Default settings from datasheet. */
|
||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("Temperature = "));
|
||||
Serial.print(bmp.readTemperature());
|
||||
Serial.println(" *C");
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(bmp.readPressure());
|
||||
Serial.println(" Pa");
|
||||
|
||||
Serial.print(F("Approx altitude = "));
|
||||
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
|
||||
Serial.println(" m");
|
||||
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
}
|
57
firmware/libraries/Adafruit_BMP280_Library/keywords.txt
Normal file
57
firmware/libraries/Adafruit_BMP280_Library/keywords.txt
Normal file
|
@ -0,0 +1,57 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map for BMP280 library
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
Adafruit_BMP280 KEYWORD1
|
||||
Adafruit_BMP280_Temp KEYWORD1
|
||||
Adafruit_BMP280_Pressure KEYWORD1
|
||||
bmp280_calib_data KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
begin KEYWORD2
|
||||
reset KEYWORD2
|
||||
getStatus KEYWORD2
|
||||
sensorID KEYWORD2
|
||||
getEvent KEYWORD2
|
||||
getSensor KEYWORD2
|
||||
readTemperature KEYWORD2
|
||||
readPressure KEYWORD2
|
||||
readAltitude KEYWORD2
|
||||
seaLevelForAltitude KEYWORD2
|
||||
waterBoilingPoint KEYWORD2
|
||||
takeForcedMeasurement KEYWORD2
|
||||
getTemperatureSensor KEYWORD2
|
||||
getPressureSensor KEYWORD2
|
||||
setSampling KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
SAMPLING_NONE LITERAL1
|
||||
SAMPLING_X1 LITERAL1
|
||||
SAMPLING_X2 LITERAL1
|
||||
SAMPLING_X4 LITERAL1
|
||||
SAMPLING_X8 LITERAL1
|
||||
SAMPLING_X16 LITERAL1
|
||||
MODE_SLEEP LITERAL1
|
||||
MODE_FORCED LITERAL1
|
||||
MODE_NORMAL LITERAL1
|
||||
MODE_SOFT_RESET_CODE LITERAL1
|
||||
FILTER_OFF LITERAL1
|
||||
FILTER_X2 LITERAL1
|
||||
FILTER_X4 LITERAL1
|
||||
FILTER_X8 LITERAL1
|
||||
FILTER_X16 LITERAL1
|
||||
STANDBY_MS_1 LITERAL1
|
||||
STANDBY_MS_63 LITERAL1
|
||||
STANDBY_MS_125 LITERAL1
|
||||
STANDBY_MS_250 LITERAL1
|
||||
STANDBY_MS_500 LITERAL1
|
||||
STANDBY_MS_1000 LITERAL1
|
||||
STANDBY_MS_2000 LITERAL1
|
||||
STANDBY_MS_4000 LITERAL1
|
|
@ -0,0 +1,10 @@
|
|||
name=Adafruit BMP280 Library
|
||||
version=2.6.6
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for BMP280 sensors.
|
||||
paragraph=Arduino library for BMP280 pressure and altitude sensors.
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_BMP280_Library
|
||||
architectures=*
|
||||
depends=Adafruit Unified Sensor, Adafruit BusIO
|
365
firmware/libraries/Adafruit_BusIO/Adafruit_BusIO_Register.cpp
Normal file
365
firmware/libraries/Adafruit_BusIO/Adafruit_BusIO_Register.cpp
Normal file
|
@ -0,0 +1,365 @@
|
|||
#include <Adafruit_BusIO_Register.h>
|
||||
|
||||
#if !defined(SPI_INTERFACES_COUNT) || \
|
||||
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
||||
|
||||
/*!
|
||||
* @brief Create a register we access over an I2C Device (which defines the
|
||||
* bus and address)
|
||||
* @param i2cdevice The I2CDevice to use for underlying I2C access
|
||||
* @param reg_addr The address pointer value for the I2C/SMBus register, can
|
||||
* be 8 or 16 bits
|
||||
* @param width The width of the register data itself, defaults to 1 byte
|
||||
* @param byteorder The byte order of the register (used when width is > 1),
|
||||
* defaults to LSBFIRST
|
||||
* @param address_width The width of the register address itself, defaults
|
||||
* to 1 byte
|
||||
*/
|
||||
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
|
||||
uint16_t reg_addr,
|
||||
uint8_t width,
|
||||
uint8_t byteorder,
|
||||
uint8_t address_width) {
|
||||
_i2cdevice = i2cdevice;
|
||||
_spidevice = nullptr;
|
||||
_addrwidth = address_width;
|
||||
_address = reg_addr;
|
||||
_byteorder = byteorder;
|
||||
_width = width;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create a register we access over an SPI Device (which defines the
|
||||
* bus and CS pin)
|
||||
* @param spidevice The SPIDevice to use for underlying SPI access
|
||||
* @param reg_addr The address pointer value for the SPI register, can
|
||||
* be 8 or 16 bits
|
||||
* @param type The method we use to read/write data to SPI (which is not
|
||||
* as well defined as I2C)
|
||||
* @param width The width of the register data itself, defaults to 1 byte
|
||||
* @param byteorder The byte order of the register (used when width is > 1),
|
||||
* defaults to LSBFIRST
|
||||
* @param address_width The width of the register address itself, defaults
|
||||
* to 1 byte
|
||||
*/
|
||||
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
|
||||
uint16_t reg_addr,
|
||||
Adafruit_BusIO_SPIRegType type,
|
||||
uint8_t width,
|
||||
uint8_t byteorder,
|
||||
uint8_t address_width) {
|
||||
_spidevice = spidevice;
|
||||
_spiregtype = type;
|
||||
_i2cdevice = nullptr;
|
||||
_addrwidth = address_width;
|
||||
_address = reg_addr;
|
||||
_byteorder = byteorder;
|
||||
_width = width;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create a register we access over an I2C or SPI Device. This is a
|
||||
* handy function because we can pass in nullptr for the unused interface,
|
||||
* allowing libraries to mass-define all the registers
|
||||
* @param i2cdevice The I2CDevice to use for underlying I2C access, if
|
||||
* nullptr we use SPI
|
||||
* @param spidevice The SPIDevice to use for underlying SPI access, if
|
||||
* nullptr we use I2C
|
||||
* @param reg_addr The address pointer value for the I2C/SMBus/SPI register,
|
||||
* can be 8 or 16 bits
|
||||
* @param type The method we use to read/write data to SPI (which is not
|
||||
* as well defined as I2C)
|
||||
* @param width The width of the register data itself, defaults to 1 byte
|
||||
* @param byteorder The byte order of the register (used when width is > 1),
|
||||
* defaults to LSBFIRST
|
||||
* @param address_width The width of the register address itself, defaults
|
||||
* to 1 byte
|
||||
*/
|
||||
Adafruit_BusIO_Register::Adafruit_BusIO_Register(
|
||||
Adafruit_I2CDevice *i2cdevice, Adafruit_SPIDevice *spidevice,
|
||||
Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, uint8_t width,
|
||||
uint8_t byteorder, uint8_t address_width) {
|
||||
_spidevice = spidevice;
|
||||
_i2cdevice = i2cdevice;
|
||||
_spiregtype = type;
|
||||
_addrwidth = address_width;
|
||||
_address = reg_addr;
|
||||
_byteorder = byteorder;
|
||||
_width = width;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Write a buffer of data to the register location
|
||||
* @param buffer Pointer to data to write
|
||||
* @param len Number of bytes to write
|
||||
* @return True on successful write (only really useful for I2C as SPI is
|
||||
* uncheckable)
|
||||
*/
|
||||
bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
|
||||
|
||||
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
|
||||
(uint8_t)(_address >> 8)};
|
||||
|
||||
if (_i2cdevice) {
|
||||
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
|
||||
}
|
||||
if (_spidevice) {
|
||||
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
|
||||
// very special case!
|
||||
|
||||
// pass the special opcode address which we set as the high byte of the
|
||||
// regaddr
|
||||
addrbuffer[0] =
|
||||
(uint8_t)(_address >> 8) & ~0x01; // set bottom bit low to write
|
||||
// the 'actual' reg addr is the second byte then
|
||||
addrbuffer[1] = (uint8_t)(_address & 0xFF);
|
||||
// the address appears to be a byte longer
|
||||
return _spidevice->write(buffer, len, addrbuffer, _addrwidth + 1);
|
||||
}
|
||||
|
||||
if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
|
||||
addrbuffer[0] &= ~0x80;
|
||||
}
|
||||
if (_spiregtype == ADDRBIT8_HIGH_TOWRITE) {
|
||||
addrbuffer[0] |= 0x80;
|
||||
}
|
||||
if (_spiregtype == AD8_HIGH_TOREAD_AD7_HIGH_TOINC) {
|
||||
addrbuffer[0] &= ~0x80;
|
||||
addrbuffer[0] |= 0x40;
|
||||
}
|
||||
return _spidevice->write(buffer, len, addrbuffer, _addrwidth);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Write up to 4 bytes of data to the register location
|
||||
* @param value Data to write
|
||||
* @param numbytes How many bytes from 'value' to write
|
||||
* @return True on successful write (only really useful for I2C as SPI is
|
||||
* uncheckable)
|
||||
*/
|
||||
bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
|
||||
if (numbytes == 0) {
|
||||
numbytes = _width;
|
||||
}
|
||||
if (numbytes > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// store a copy
|
||||
_cached = value;
|
||||
|
||||
for (int i = 0; i < numbytes; i++) {
|
||||
if (_byteorder == LSBFIRST) {
|
||||
_buffer[i] = value & 0xFF;
|
||||
} else {
|
||||
_buffer[numbytes - i - 1] = value & 0xFF;
|
||||
}
|
||||
value >>= 8;
|
||||
}
|
||||
return write(_buffer, numbytes);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Read data from the register location. This does not do any error
|
||||
* checking!
|
||||
* @return Returns 0xFFFFFFFF on failure, value otherwise
|
||||
*/
|
||||
uint32_t Adafruit_BusIO_Register::read(void) {
|
||||
if (!read(_buffer, _width)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
for (int i = 0; i < _width; i++) {
|
||||
value <<= 8;
|
||||
if (_byteorder == LSBFIRST) {
|
||||
value |= _buffer[_width - i - 1];
|
||||
} else {
|
||||
value |= _buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Read cached data from last time we wrote to this register
|
||||
* @return Returns 0xFFFFFFFF on failure, value otherwise
|
||||
*/
|
||||
uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; }
|
||||
|
||||
/*!
|
||||
* @brief Read a buffer of data from the register location
|
||||
* @param buffer Pointer to data to read into
|
||||
* @param len Number of bytes to read
|
||||
* @return True on successful write (only really useful for I2C as SPI is
|
||||
* uncheckable)
|
||||
*/
|
||||
bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
|
||||
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
|
||||
(uint8_t)(_address >> 8)};
|
||||
|
||||
if (_i2cdevice) {
|
||||
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
|
||||
}
|
||||
if (_spidevice) {
|
||||
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
|
||||
// very special case!
|
||||
|
||||
// pass the special opcode address which we set as the high byte of the
|
||||
// regaddr
|
||||
addrbuffer[0] =
|
||||
(uint8_t)(_address >> 8) | 0x01; // set bottom bit high to read
|
||||
// the 'actual' reg addr is the second byte then
|
||||
addrbuffer[1] = (uint8_t)(_address & 0xFF);
|
||||
// the address appears to be a byte longer
|
||||
return _spidevice->write_then_read(addrbuffer, _addrwidth + 1, buffer,
|
||||
len);
|
||||
}
|
||||
if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
|
||||
addrbuffer[0] |= 0x80;
|
||||
}
|
||||
if (_spiregtype == ADDRBIT8_HIGH_TOWRITE) {
|
||||
addrbuffer[0] &= ~0x80;
|
||||
}
|
||||
if (_spiregtype == AD8_HIGH_TOREAD_AD7_HIGH_TOINC) {
|
||||
addrbuffer[0] |= 0x80 | 0x40;
|
||||
}
|
||||
return _spidevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Read 2 bytes of data from the register location
|
||||
* @param value Pointer to uint16_t variable to read into
|
||||
* @return True on successful write (only really useful for I2C as SPI is
|
||||
* uncheckable)
|
||||
*/
|
||||
bool Adafruit_BusIO_Register::read(uint16_t *value) {
|
||||
if (!read(_buffer, 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_byteorder == LSBFIRST) {
|
||||
*value = _buffer[1];
|
||||
*value <<= 8;
|
||||
*value |= _buffer[0];
|
||||
} else {
|
||||
*value = _buffer[0];
|
||||
*value <<= 8;
|
||||
*value |= _buffer[1];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Read 1 byte of data from the register location
|
||||
* @param value Pointer to uint8_t variable to read into
|
||||
* @return True on successful write (only really useful for I2C as SPI is
|
||||
* uncheckable)
|
||||
*/
|
||||
bool Adafruit_BusIO_Register::read(uint8_t *value) {
|
||||
if (!read(_buffer, 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = _buffer[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Pretty printer for this register
|
||||
* @param s The Stream to print to, defaults to &Serial
|
||||
*/
|
||||
void Adafruit_BusIO_Register::print(Stream *s) {
|
||||
uint32_t val = read();
|
||||
s->print("0x");
|
||||
s->print(val, HEX);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Pretty printer for this register
|
||||
* @param s The Stream to print to, defaults to &Serial
|
||||
*/
|
||||
void Adafruit_BusIO_Register::println(Stream *s) {
|
||||
print(s);
|
||||
s->println();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create a slice of the register that we can address without
|
||||
* touching other bits
|
||||
* @param reg The Adafruit_BusIO_Register which defines the bus/register
|
||||
* @param bits The number of bits wide we are slicing
|
||||
* @param shift The number of bits that our bit-slice is shifted from LSB
|
||||
*/
|
||||
Adafruit_BusIO_RegisterBits::Adafruit_BusIO_RegisterBits(
|
||||
Adafruit_BusIO_Register *reg, uint8_t bits, uint8_t shift) {
|
||||
_register = reg;
|
||||
_bits = bits;
|
||||
_shift = shift;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Read 4 bytes of data from the register
|
||||
* @return data The 4 bytes to read
|
||||
*/
|
||||
uint32_t Adafruit_BusIO_RegisterBits::read(void) {
|
||||
uint32_t val = _register->read();
|
||||
val >>= _shift;
|
||||
return val & ((1 << (_bits)) - 1);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Write 4 bytes of data to the register
|
||||
* @param data The 4 bytes to write
|
||||
* @return True on successful write (only really useful for I2C as SPI is
|
||||
* uncheckable)
|
||||
*/
|
||||
bool Adafruit_BusIO_RegisterBits::write(uint32_t data) {
|
||||
uint32_t val = _register->read();
|
||||
|
||||
// mask off the data before writing
|
||||
uint32_t mask = (1 << (_bits)) - 1;
|
||||
data &= mask;
|
||||
|
||||
mask <<= _shift;
|
||||
val &= ~mask; // remove the current data at that spot
|
||||
val |= data << _shift; // and add in the new data
|
||||
|
||||
return _register->write(val, _register->width());
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief The width of the register data, helpful for doing calculations
|
||||
* @returns The data width used when initializing the register
|
||||
*/
|
||||
uint8_t Adafruit_BusIO_Register::width(void) { return _width; }
|
||||
|
||||
/*!
|
||||
* @brief Set the default width of data
|
||||
* @param width the default width of data read from register
|
||||
*/
|
||||
void Adafruit_BusIO_Register::setWidth(uint8_t width) { _width = width; }
|
||||
|
||||
/*!
|
||||
* @brief Set register address
|
||||
* @param address the address from register
|
||||
*/
|
||||
void Adafruit_BusIO_Register::setAddress(uint16_t address) {
|
||||
_address = address;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set the width of register address
|
||||
* @param address_width the width for register address
|
||||
*/
|
||||
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
|
||||
_addrwidth = address_width;
|
||||
}
|
||||
|
||||
#endif // SPI exists
|
105
firmware/libraries/Adafruit_BusIO/Adafruit_BusIO_Register.h
Normal file
105
firmware/libraries/Adafruit_BusIO/Adafruit_BusIO_Register.h
Normal file
|
@ -0,0 +1,105 @@
|
|||
#ifndef Adafruit_BusIO_Register_h
|
||||
#define Adafruit_BusIO_Register_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#if !defined(SPI_INTERFACES_COUNT) || \
|
||||
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
||||