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

bme680/bme680.h

Committer:
jsa1969
Date:
2018-12-03
Revision:
0:cef60cc92da0
Child:
2:544117df8c65

File content as of revision 0:cef60cc92da0:

#include "mbed.h"
#include "MicroBit.h"

#include "i2c_callbacks.h"

#ifndef BME680_H
#define BME680_H

#include "bme680_defs.h"

class Bme680 {
    public:
        /* function prototype declarations */
        /*!
         *  @brief This API is the entry point.
         *  It reads the chip-id and calibration data from the sensor.
         *
         *  @param[in,out] dev : Structure instance of bme680_dev
         *
         *  @return Result of API execution status
         *  @retval zero -> Success / +ve value -> Warning / -ve value -> Error
         */
         Bme680(I2cCallbacks *callbacks);
         int init();
         int measure(struct bme680_field_data* data, int ambTemp, uint16_t heatr_dur, uint16_t heatr_temp);
         
    private:
        int get_calib_data();
        int set_gas_config();
        int get_gas_config();
        int16_t calc_temperature(uint32_t temp_adc);
        uint32_t calc_humidity(uint16_t hum_adc);
        uint32_t calc_pressure(uint32_t pres_adc);
        uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range);
        uint8_t calc_heater_res(uint16_t temp);
        uint8_t calc_heater_dur(uint16_t dur);
        
        
        int read_field_data(struct bme680_field_data *data);
        //int8_t set_mem_page(uint8_t reg_addr, struct bme680_dev *dev);
        //int8_t get_mem_page();
        int null_ptr_check();
        int boundary_check(uint8_t *value, uint8_t min, uint8_t max);
        
        int soft_reset();
        int set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len);
        int get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
        int set_sensor_settings(uint16_t desired_settings);
        int set_sensor_mode();
        int get_sensor_settings(uint16_t desired_settings);
        int get_sensor_mode(struct bme680_dev *dev);
        void set_profile_dur(uint16_t duration);
        void get_profile_dur(uint16_t *duration);
        int get_sensor_data(struct bme680_field_data *data);
        
        int analyze_sensor_data(struct bme680_field_data *data);
        
        struct bme680_dev *_dev;
        I2cCallbacks* _i2cCallbacks;
};

#endif // BME680_H