uses BBC micro:bit to measure and display indoor air quality using Bosch BME680 and/or Sensirion SGP30

Dependencies:   microbit

uses Bosch BME680 and/or Sensirion SGP30 sensors to measure indor air quality

sensors should be connected to BBC micro:bit using i2c

commands are received and data is being sent using uBit / nordic radio protocol

display ---

last line always indicates: - first dot: bme680 detected - second dot: sgp30 detected - third dot: sgp 30 setting humidity/temperature - fourth dor: sgp30 measuring - fith dot: bme680 measuring

the detect dots should be in a stable state (not blinking) the measuring dots should be blinking (constant light means: measurement failed)

if only one bme680 is present: - first 3 lines indicate gas resistence (air quality / more dots == worse quality) - fourth line indicates humidity level

if only sgp30 is present: - first two lines indicate SGP30 VOC level - third and fourth line indicate sgp30 CO2 level

if both sensors are present: - first line indicates SGP30 VOC level - second line line indicates sgp30 CO2 level - third line indicates bme680 gas resistence (air quality) - fourth line indicates bme 680 humidity level

buttons - B display state, switches betweeen - full bright - low light - display off

AB reset sgp30 baseline in non volatile storage

data logging -- during measurements the minimum and mximum values for each measured value (temperature, air pressure, humidity,gas resistance, VOC, CO2) are being stored in non volatile storage those (and the last measurement results) are being shown when btn A has been pressed

Committer:
jsa1969
Date:
Fri Jun 03 17:05:56 2022 +0000
Revision:
60:6b21ca38ee7c
Parent:
46:2fed2865a0f3
cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jsa1969 0:cef60cc92da0 1 #include "mbed.h"
jsa1969 0:cef60cc92da0 2 #include "MicroBit.h"
jsa1969 0:cef60cc92da0 3
jsa1969 0:cef60cc92da0 4 #include "i2c_callbacks.h"
jsa1969 0:cef60cc92da0 5
jsa1969 0:cef60cc92da0 6 #ifndef BME680_H
jsa1969 0:cef60cc92da0 7 #define BME680_H
jsa1969 0:cef60cc92da0 8
jsa1969 0:cef60cc92da0 9 #include "bme680_defs.h"
jsa1969 0:cef60cc92da0 10
jsa1969 16:3a4b9a3ef2bb 11 /*
jsa1969 16:3a4b9a3ef2bb 12 the code has been taken from https://github.com/BoschSensortec/BME680_driver
jsa1969 16:3a4b9a3ef2bb 13 and only been slightly adjusted for mbed MicroBit
jsa1969 16:3a4b9a3ef2bb 14 */
jsa1969 16:3a4b9a3ef2bb 15
jsa1969 0:cef60cc92da0 16 class Bme680 {
jsa1969 0:cef60cc92da0 17 public:
jsa1969 0:cef60cc92da0 18 /* function prototype declarations */
jsa1969 0:cef60cc92da0 19 /*!
jsa1969 0:cef60cc92da0 20 * @brief This API is the entry point.
jsa1969 0:cef60cc92da0 21 * It reads the chip-id and calibration data from the sensor.
jsa1969 0:cef60cc92da0 22 *
jsa1969 0:cef60cc92da0 23 * @param[in,out] dev : Structure instance of bme680_dev
jsa1969 0:cef60cc92da0 24 *
jsa1969 0:cef60cc92da0 25 * @return Result of API execution status
jsa1969 0:cef60cc92da0 26 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
jsa1969 0:cef60cc92da0 27 */
jsa1969 0:cef60cc92da0 28 Bme680(I2cCallbacks *callbacks);
jsa1969 0:cef60cc92da0 29 int init();
jsa1969 14:71060505061e 30 int measure(struct bme680_field_data* data, const int ambTemp, const uint16_t heatr_dur, const uint16_t heatr_temp);
jsa1969 0:cef60cc92da0 31
jsa1969 0:cef60cc92da0 32 private:
jsa1969 0:cef60cc92da0 33 int get_calib_data();
jsa1969 0:cef60cc92da0 34 int set_gas_config();
jsa1969 0:cef60cc92da0 35 int get_gas_config();
jsa1969 0:cef60cc92da0 36 int16_t calc_temperature(uint32_t temp_adc);
jsa1969 0:cef60cc92da0 37 uint32_t calc_humidity(uint16_t hum_adc);
jsa1969 0:cef60cc92da0 38 uint32_t calc_pressure(uint32_t pres_adc);
jsa1969 0:cef60cc92da0 39 uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range);
jsa1969 0:cef60cc92da0 40 uint8_t calc_heater_res(uint16_t temp);
jsa1969 0:cef60cc92da0 41 uint8_t calc_heater_dur(uint16_t dur);
jsa1969 0:cef60cc92da0 42
jsa1969 0:cef60cc92da0 43
jsa1969 0:cef60cc92da0 44 int read_field_data(struct bme680_field_data *data);
jsa1969 0:cef60cc92da0 45 //int8_t set_mem_page(uint8_t reg_addr, struct bme680_dev *dev);
jsa1969 0:cef60cc92da0 46 //int8_t get_mem_page();
jsa1969 0:cef60cc92da0 47 int null_ptr_check();
jsa1969 0:cef60cc92da0 48 int boundary_check(uint8_t *value, uint8_t min, uint8_t max);
jsa1969 0:cef60cc92da0 49
jsa1969 0:cef60cc92da0 50 int soft_reset();
jsa1969 0:cef60cc92da0 51 int set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len);
jsa1969 0:cef60cc92da0 52 int get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
jsa1969 0:cef60cc92da0 53 int set_sensor_settings(uint16_t desired_settings);
jsa1969 0:cef60cc92da0 54 int set_sensor_mode();
jsa1969 0:cef60cc92da0 55 int get_sensor_settings(uint16_t desired_settings);
jsa1969 0:cef60cc92da0 56 int get_sensor_mode(struct bme680_dev *dev);
jsa1969 0:cef60cc92da0 57 void set_profile_dur(uint16_t duration);
jsa1969 0:cef60cc92da0 58 void get_profile_dur(uint16_t *duration);
jsa1969 0:cef60cc92da0 59 int get_sensor_data(struct bme680_field_data *data);
jsa1969 0:cef60cc92da0 60
jsa1969 0:cef60cc92da0 61 int analyze_sensor_data(struct bme680_field_data *data);
jsa1969 0:cef60cc92da0 62
jsa1969 0:cef60cc92da0 63 struct bme680_dev *_dev;
jsa1969 0:cef60cc92da0 64 I2cCallbacks* _i2cCallbacks;
jsa1969 0:cef60cc92da0 65 };
jsa1969 0:cef60cc92da0 66
jsa1969 0:cef60cc92da0 67 #endif // BME680_H