uses BBC micro:bit to measure and display indoor air quality using Bosch BME680 and/or Sensirion SGP30
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
Diff: i2c/i2c_callbacks.cpp
- Revision:
- 46:2fed2865a0f3
- Parent:
- 44:67a19da5f269
diff -r d6a9fd9c8200 -r 2fed2865a0f3 i2c/i2c_callbacks.cpp --- a/i2c/i2c_callbacks.cpp Wed Feb 13 22:39:36 2019 +0000 +++ b/i2c/i2c_callbacks.cpp Fri Feb 15 10:55:02 2019 +0000 @@ -1,34 +1,25 @@ #include "i2c_callbacks.h" -I2cCallbacks::I2cCallbacks(MicroBit* uBit, MicroBitI2C* i2c){ +I2cCallbacks::I2cCallbacks(MicroBit* uBit){ _uBit = uBit; - uBit->seedRandom(); - _currentlock = 0; - - if (i2c == NULL) { - _i2c = &(_uBit->i2c); - } - else { - _i2c = i2c; - } } -int I2cCallbacks::read(const uint8_t address, const uint8_t reg, uint8_t *buffer, const uint16_t length, int lock){ - if (buffer == NULL || length <= 0 || lock!=_currentlock) +int I2cCallbacks::read(const uint8_t address, const uint8_t reg, uint8_t *buffer, const uint16_t length){ + if (buffer == NULL || length <= 0) return MICROBIT_INVALID_PARAMETER; - int result = _i2c->write(address, (const char *)®, 1, true); + int result = _uBit->i2c.write(address, (const char *)®, 1, true); if (result == 0) - result = _i2c->read(address, (char *)buffer, length); + result = _uBit->i2c.read(address, (char *)buffer, length); return result != 0 ? MICROBIT_I2C_ERROR : MICROBIT_OK; } -int I2cCallbacks::read(const uint8_t address, uint8_t *buffer, const uint16_t length, int lock){ - if (buffer == NULL || length <= 0 || lock!=_currentlock) +int I2cCallbacks::read(const uint8_t address, uint8_t *buffer, const uint16_t length){ + if (buffer == NULL || length <= 0) return MICROBIT_INVALID_PARAMETER; - int result = _i2c->read(address, (char *)buffer, length); + int result = _uBit->i2c.read(address, (char *)buffer, length); if (result !=0) return MICROBIT_I2C_ERROR; @@ -36,24 +27,18 @@ return MICROBIT_OK; } -int I2cCallbacks::write(const uint8_t dev_id, const uint8_t reg_addr, const uint8_t *data, const uint16_t length, int lock){ - if (lock!=_currentlock) - return MICROBIT_INVALID_PARAMETER; - +int I2cCallbacks::write(const uint8_t dev_id, const uint8_t reg_addr, const uint8_t *data, const uint16_t length){ char tmpBuf[length+1]; tmpBuf[0] = reg_addr; for (int i=0,j=1; i <length ; ++i,++j){ tmpBuf[j] = data[i]; } - return _i2c->write(dev_id, tmpBuf, length+1); + return _uBit->i2c.write(dev_id, tmpBuf, length+1); } -int I2cCallbacks::write(const uint8_t dev_id, const uint8_t *data, const uint16_t length, int lock){ - if (lock!=_currentlock) - return MICROBIT_INVALID_PARAMETER; - - return _i2c->write(dev_id, (char*)data, length); +int I2cCallbacks::write(const uint8_t dev_id, const uint8_t *data, const uint16_t length){ + return _uBit->i2c.write(dev_id, (char*)data, length); } void I2cCallbacks::delay_ms_relaxed(const uint32_t period) { @@ -62,17 +47,4 @@ void I2cCallbacks::delay_ms_strict(const uint32_t period) { delay_ms_relaxed(period); - /* - unsigned long endTime = _uBit->systemTime() + period; - while (_uBit->systemTime() < endTime) { - }*/ -} - -int I2cCallbacks::acquireLock() { - while (_currentlock!=0) _uBit->sleep(1); - _currentlock = _uBit->random(9999999); - } - -void I2cCallbacks::releaseLock() { - _currentlock = 0; - } \ No newline at end of file +} \ No newline at end of file