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:
Tue Dec 04 06:50:48 2018 +0000
Revision:
2:544117df8c65
Parent:
0:cef60cc92da0
Child:
3:6084ab9ff0c9
sgp30

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 0:cef60cc92da0 11 class Bme680 {
jsa1969 0:cef60cc92da0 12 public:
jsa1969 0:cef60cc92da0 13 /* function prototype declarations */
jsa1969 0:cef60cc92da0 14 /*!
jsa1969 0:cef60cc92da0 15 * @brief This API is the entry point.
jsa1969 0:cef60cc92da0 16 * It reads the chip-id and calibration data from the sensor.
jsa1969 0:cef60cc92da0 17 *
jsa1969 0:cef60cc92da0 18 * @param[in,out] dev : Structure instance of bme680_dev
jsa1969 0:cef60cc92da0 19 *
jsa1969 0:cef60cc92da0 20 * @return Result of API execution status
jsa1969 0:cef60cc92da0 21 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
jsa1969 0:cef60cc92da0 22 */
jsa1969 0:cef60cc92da0 23 Bme680(I2cCallbacks *callbacks);
jsa1969 2:544117df8c65 24 Bme680(I2cCallbacks *callbacks, uint32_t gas_resistance_max);
jsa1969 0:cef60cc92da0 25 int init();
jsa1969 0:cef60cc92da0 26 int measure(struct bme680_field_data* data, int ambTemp, uint16_t heatr_dur, uint16_t heatr_temp);
jsa1969 2:544117df8c65 27 uint32_t gasResistanceMax();
jsa1969 0:cef60cc92da0 28
jsa1969 0:cef60cc92da0 29 private:
jsa1969 2:544117df8c65 30 void initialize(I2cCallbacks *callbacks, uint32_t gas_resistance_max);
jsa1969 2:544117df8c65 31
jsa1969 0:cef60cc92da0 32 int get_calib_data();
jsa1969 0:cef60cc92da0 33 int set_gas_config();
jsa1969 0:cef60cc92da0 34 int get_gas_config();
jsa1969 0:cef60cc92da0 35 int16_t calc_temperature(uint32_t temp_adc);
jsa1969 0:cef60cc92da0 36 uint32_t calc_humidity(uint16_t hum_adc);
jsa1969 0:cef60cc92da0 37 uint32_t calc_pressure(uint32_t pres_adc);
jsa1969 0:cef60cc92da0 38 uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range);
jsa1969 0:cef60cc92da0 39 uint8_t calc_heater_res(uint16_t temp);
jsa1969 0:cef60cc92da0 40 uint8_t calc_heater_dur(uint16_t dur);
jsa1969 0:cef60cc92da0 41
jsa1969 0:cef60cc92da0 42
jsa1969 0:cef60cc92da0 43 int read_field_data(struct bme680_field_data *data);
jsa1969 0:cef60cc92da0 44 //int8_t set_mem_page(uint8_t reg_addr, struct bme680_dev *dev);
jsa1969 0:cef60cc92da0 45 //int8_t get_mem_page();
jsa1969 0:cef60cc92da0 46 int null_ptr_check();
jsa1969 0:cef60cc92da0 47 int boundary_check(uint8_t *value, uint8_t min, uint8_t max);
jsa1969 0:cef60cc92da0 48
jsa1969 0:cef60cc92da0 49 int soft_reset();
jsa1969 0:cef60cc92da0 50 int set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len);
jsa1969 0:cef60cc92da0 51 int get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
jsa1969 0:cef60cc92da0 52 int set_sensor_settings(uint16_t desired_settings);
jsa1969 0:cef60cc92da0 53 int set_sensor_mode();
jsa1969 0:cef60cc92da0 54 int get_sensor_settings(uint16_t desired_settings);
jsa1969 0:cef60cc92da0 55 int get_sensor_mode(struct bme680_dev *dev);
jsa1969 0:cef60cc92da0 56 void set_profile_dur(uint16_t duration);
jsa1969 0:cef60cc92da0 57 void get_profile_dur(uint16_t *duration);
jsa1969 0:cef60cc92da0 58 int get_sensor_data(struct bme680_field_data *data);
jsa1969 0:cef60cc92da0 59
jsa1969 0:cef60cc92da0 60 int analyze_sensor_data(struct bme680_field_data *data);
jsa1969 0:cef60cc92da0 61
jsa1969 0:cef60cc92da0 62 struct bme680_dev *_dev;
jsa1969 0:cef60cc92da0 63 I2cCallbacks* _i2cCallbacks;
jsa1969 2:544117df8c65 64 uint32_t _gas_resistance_max;
jsa1969 0:cef60cc92da0 65 };
jsa1969 0:cef60cc92da0 66
jsa1969 0:cef60cc92da0 67 #endif // BME680_H