BOSCH BSEC integration
This commit is contained in:
parent
e9cdeea2fb
commit
8f201e066f
@ -1,15 +0,0 @@
|
||||
#ifndef _BME680_H
|
||||
#define _BME680_H
|
||||
|
||||
#include "globals.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include "Adafruit_BME680.h"
|
||||
|
||||
extern bmeStatus_t
|
||||
bme_status; // Make struct for storing gps data globally available
|
||||
|
||||
void bme_init();
|
||||
bool bme_read();
|
||||
|
||||
#endif
|
23
include/bme680mems.h
Normal file
23
include/bme680mems.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef _BME680MEMS_H
|
||||
#define _BME680MEMS_H
|
||||
|
||||
#include "globals.h"
|
||||
#include <Wire.h>
|
||||
#include "bme680.h"
|
||||
#include "bsec_interface.h"
|
||||
#include "bsec_datatypes.h"
|
||||
//#include "bme680_defs.h"
|
||||
//#include "bme680.c"
|
||||
|
||||
extern bmeStatus_t
|
||||
bme_status; // Make struct for storing gps data globally available
|
||||
|
||||
void bme_init();
|
||||
bool bme_read();
|
||||
void user_delay_ms(uint32_t period);
|
||||
int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint16_t len);
|
||||
int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint16_t len);
|
||||
|
||||
#endif
|
@ -95,7 +95,7 @@ extern TaskHandle_t irqHandlerTask, wifiSwitchTask;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BME
|
||||
#include "bme680.h"
|
||||
#include "bme680mems.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAS_LORA
|
||||
|
@ -50,13 +50,9 @@ lib_deps_rgbled =
|
||||
SmartLeds@>=1.1.3
|
||||
lib_deps_gps =
|
||||
TinyGPSPlus@>=1.0.2
|
||||
lib_deps_sensors =
|
||||
Adafruit Unified Sensor@^1.0.2
|
||||
Adafruit BME680 Library@^1.0.7
|
||||
lib_deps_basic =
|
||||
ArduinoJson@^5.13.1
|
||||
Time@>=1.5
|
||||
${common.lib_deps_sensors}
|
||||
lib_deps_all =
|
||||
${common.lib_deps_basic}
|
||||
${common.lib_deps_lora}
|
||||
@ -64,6 +60,8 @@ lib_deps_all =
|
||||
${common.lib_deps_rgbled}
|
||||
${common.lib_deps_gps}
|
||||
build_flags =
|
||||
-Llib/Bosch-BSEC
|
||||
-llibalgobsec.a
|
||||
-include src/hal/${PIOENV}.h
|
||||
-include src/paxcounter.conf
|
||||
-w
|
||||
|
@ -1,44 +0,0 @@
|
||||
#ifdef HAS_BME
|
||||
|
||||
#include "bme680.h"
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = "main";
|
||||
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
// I2C Bus interface
|
||||
Adafruit_BME680 bme;
|
||||
|
||||
bmeStatus_t bme_status;
|
||||
|
||||
void bme_init(void) {
|
||||
// initialize BME680 sensor using default i2c address 0x77
|
||||
if (bme.begin(HAS_BME)) {
|
||||
// Set up oversampling and filter initialization
|
||||
bme.setTemperatureOversampling(BME680_OS_8X);
|
||||
bme.setHumidityOversampling(BME680_OS_2X);
|
||||
bme.setPressureOversampling(BME680_OS_4X);
|
||||
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
|
||||
bme.setGasHeater(320, 150); // 320*C for 150 ms
|
||||
ESP_LOGI(TAG, "BME680 chip found and initialized");
|
||||
} else
|
||||
ESP_LOGE(TAG, "BME680 chip not found on i2c bus");
|
||||
}
|
||||
|
||||
bool bme_read(void) {
|
||||
bool ret = bme.performReading();
|
||||
if (ret) {
|
||||
// read current BME data and buffer in global struct
|
||||
bme_status.temperature = bme.temperature;
|
||||
bme_status.pressure = (uint16_t)(bme.pressure / 100.0); // convert Pa -> hPa
|
||||
bme_status.humidity = bme.humidity;
|
||||
bme_status.gas_resistance = (uint16_t)(bme.gas_resistance / 1000.0); // convert Ohm -> kOhm
|
||||
ESP_LOGI(TAG, "BME680 sensor data read success");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "BME680 sensor read error");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // HAS_BME
|
127
src/bme680mems.cpp
Normal file
127
src/bme680mems.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
#ifdef HAS_BME
|
||||
|
||||
#include "bme680mems.h"
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = "main";
|
||||
|
||||
bmeStatus_t bme_status;
|
||||
|
||||
void bme_init(void) {
|
||||
|
||||
// initialize BME680 sensor
|
||||
|
||||
struct bme680_dev gas_sensor;
|
||||
|
||||
Wire.begin(HAS_BME, 400000); // I2C connect to BME680 sensor with 400 KHz
|
||||
|
||||
// configure sensor for I2C communication
|
||||
gas_sensor.dev_id = BME_ADDR;
|
||||
gas_sensor.intf = BME680_I2C_INTF;
|
||||
gas_sensor.read = user_i2c_read;
|
||||
gas_sensor.write = user_i2c_write;
|
||||
gas_sensor.delay_ms = user_delay_ms;
|
||||
gas_sensor.amb_temp = 25;
|
||||
|
||||
int8_t rslt = BME680_OK;
|
||||
rslt = bme680_init(&gas_sensor);
|
||||
|
||||
if (rslt == BME680_OK) {
|
||||
ESP_LOGI(TAG, "BME680 sensor found");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "BME680 sensor not found on i2c bus");
|
||||
return;
|
||||
}
|
||||
|
||||
// configure BME680 sensor in forced mode
|
||||
|
||||
uint8_t set_required_settings;
|
||||
|
||||
/* Set the temperature, pressure and humidity settings */
|
||||
gas_sensor.tph_sett.os_hum = BME680_OS_2X;
|
||||
gas_sensor.tph_sett.os_pres = BME680_OS_4X;
|
||||
gas_sensor.tph_sett.os_temp = BME680_OS_8X;
|
||||
gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
|
||||
|
||||
/* Set the remaining gas sensor settings and link the heating profile */
|
||||
gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
|
||||
/* Create a ramp heat waveform in 3 steps */
|
||||
gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
|
||||
gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */
|
||||
|
||||
/* Select the power mode */
|
||||
/* Must be set before writing the sensor configuration */
|
||||
gas_sensor.power_mode = BME680_FORCED_MODE;
|
||||
|
||||
/* Set the required sensor settings needed */
|
||||
set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL |
|
||||
BME680_FILTER_SEL | BME680_GAS_SENSOR_SEL;
|
||||
|
||||
/* Set the desired sensor configuration */
|
||||
rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor);
|
||||
|
||||
/* Set the power mode */
|
||||
rslt = bme680_set_sensor_mode(&gas_sensor);
|
||||
|
||||
if (rslt == BME680_OK) {
|
||||
ESP_LOGI(TAG, "BME680 sensor initialized");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "BME680 initialization failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool bme_read(void) {
|
||||
/*
|
||||
|
||||
bool ret = bme.performReading();
|
||||
if (ret) {
|
||||
// read current BME data and buffer in global struct
|
||||
bme_status.temperature = bme.temperature;
|
||||
bme_status.pressure = (uint16_t)(bme.pressure / 100.0); // convert Pa ->
|
||||
hPa bme_status.humidity = bme.humidity; bme_status.gas_resistance =
|
||||
(uint16_t)(bme.gas_resistance / 1000.0); // convert Ohm -> kOhm
|
||||
ESP_LOGI(TAG, "BME680 sensor data read success");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "BME680 sensor read error");
|
||||
}
|
||||
return ret;
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint16_t len) {
|
||||
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
|
||||
uint16_t i;
|
||||
|
||||
Wire.beginTransmission(dev_id);
|
||||
Wire.write(reg_addr);
|
||||
rslt = Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom((int)dev_id, (int)len);
|
||||
for (i = 0; (i < len) && Wire.available(); i++) {
|
||||
reg_data[i] = Wire.read();
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint16_t len) {
|
||||
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
|
||||
uint16_t i;
|
||||
|
||||
Wire.beginTransmission(dev_id);
|
||||
Wire.write(reg_addr);
|
||||
for (i = 0; i < len; i++) {
|
||||
Wire.write(reg_data[i]);
|
||||
}
|
||||
rslt = Wire.endTransmission();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
void user_delay_ms(uint32_t period) { vTaskDelay(period / portTICK_PERIOD_MS); }
|
||||
|
||||
#endif // HAS_BME
|
@ -13,9 +13,16 @@
|
||||
#define SPI_SCLK GPIO_NUM_18
|
||||
#define SPI_CS GPIO_NUM_5
|
||||
|
||||
////////////// test //////////
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
#define HAS_BME 0x77 // BME680 sensor on I2C bus (default SDA=4/SCL=15); comment out if not present
|
||||
#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
||||
// BME680 sensor on I2C bus
|
||||
#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
|
||||
// #define BME_ADDR BME680_I2C_ADDR_PRIMARY // i2c addr 0x76
|
||||
#define BME_ADDR BME680_I2C_ADDR_SECONDARY // i2c addr 0x77
|
||||
//
|
||||
// user defined sensors
|
||||
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
||||
////////////// test //////////
|
||||
|
||||
#define CFG_sx1276_radio 1 // select LoRa chip
|
||||
//#define CFG_sx1272_radio 1 // select LoRa chip
|
||||
|
@ -7,7 +7,12 @@
|
||||
|
||||
////////////// test //////////
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
#define HAS_BME 0x77 // BME680 sensor on I2C bus (default SDA=21/SCL=22); comment out if not present
|
||||
// BME680 sensor on I2C bus
|
||||
#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
|
||||
// #define BME_ADDR BME680_I2C_ADDR_PRIMARY // i2c addr 0x76
|
||||
#define BME_ADDR BME680_I2C_ADDR_SECONDARY // i2c addr 0x77
|
||||
//
|
||||
// user defined sensors
|
||||
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
||||
////////////// test //////////
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user