![](/media/cache/group/silicon-labs-logo-red_Zq62zJd.png.50x50_q85.png)
Demo for showing Thunderboard Sense 2's sensor values on a 15-second interval
Dependencies: AMS_CCS811_gas_sensor BMP280 Si7021 Si7210 Si1133 ICM20648
Fork of TBSense2_Sensor_Demo by
Information
All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.
Diff: main.cpp
- Revision:
- 2:f80572d04d7a
- Parent:
- 1:7174444a05e2
- Child:
- 3:2e1381d5e300
--- a/main.cpp Tue May 09 08:58:09 2017 -0600 +++ b/main.cpp Sun Nov 12 16:43:58 2017 +0100 @@ -21,10 +21,15 @@ #include "AMS_CCS811.h" #include "Si7021.h" #include "Si7210.h" +#include "Si1133.h" +/* Turn on power supply to ENV sensor suite */ DigitalOut env_en(PF9, 1); +/* Turn on power to CCS811 sensor */ DigitalOut ccs_en(PF14, 1); +/* Set CCS_WAKE pin to output */ DigitalOut ccs_wake(PF15, 1); +/* Turn on power to hall effect sensor */ DigitalOut hall_en(PB10, 1); I2C ccs_i2c(PB6, PB7); @@ -36,6 +41,13 @@ float pressure, temperature2; int32_t temperature; uint32_t humidity; + float light, uv; + + bool lightsensor_en = true; + bool gassensor_en = true; + bool hallsensor_en = true; + bool rhtsensor_en = true; + bool pressuresensor_en = true; ccs_en = 0; wait_ms(1000); @@ -45,18 +57,22 @@ /* Initialize air quality sensor */ AMS_CCS811* gasSensor = new AMS_CCS811(&ccs_i2c, PF15); if(!gasSensor->init()) { - printf("Failed CCS init\r\n"); + printf("Failed CCS811 init\r\n"); + gassensor_en = false; + } else { + if(!gasSensor->mode(AMS_CCS811::TEN_SECOND)) { + printf("Failed to set CCS811 mode\r\n"); + gassensor_en = false; + } } - if(!gasSensor->mode(AMS_CCS811::TEN_SECOND)) { - printf("Failed to set mode\r\n"); - } + wait_ms(10); /* Initialize barometer and RHT */ BMP280* pressureSensor = new BMP280(env_i2c); Si7021* rhtSensor = new Si7021(PC4, PC5); - printf("\r\n\r\nHello Jumbo...\r\n"); + printf("\r\n\r\nHello Thunderboard Sense 2...\r\n"); /* Check if hall sensor is alive */ silabs::Si7210* hallSensor = new silabs::Si7210(&hall_i2c); @@ -64,39 +80,69 @@ hallSensor->wakeup(); hallSensor->readRegister(SI72XX_HREVID, &id); printf("Hall ID: %d\r\n", id); + + /* Initialize light sensor */ + Si1133* lightSensor = new Si1133(PC4, PC5); + + if(!lightSensor->open()) { + printf("Something is wrong with Si1133, disabling...\n"); + lightsensor_en = false; + } do { + printf("----------------------------------------------\r\n"); + /* Measure temperature and humidity */ + if(rhtsensor_en) { + rhtSensor->measure(); + rhtSensor->measure(); + temperature = rhtSensor->get_temperature(); + humidity = rhtSensor->get_humidity(); + + printf("Si7021:\r\n"); + printf("T: %ld.%03ld degC\r\n", temperature/1000, abs(temperature%1000)); + printf("h: %ld.%03ld %%\r\n", humidity/1000, humidity%1000); + } + /* Measure barometric pressure */ - rhtSensor->measure(); - rhtSensor->measure(); - temperature = rhtSensor->get_temperature(); - humidity = rhtSensor->get_humidity(); - - temperature2 = pressureSensor->getTemperature(); - pressure = pressureSensor->getPressure(); + if(pressuresensor_en) { + temperature2 = pressureSensor->getTemperature(); + pressure = pressureSensor->getPressure(); + + printf("BMP280:\r\n"); + printf("P: %.2f bar\r\n", pressure); + printf("T: %.2f degC\r\n", temperature2); + } /* Measure air quality */ - gasSensor->has_new_data(); - eco2 = gasSensor->co2_read(); - tvoc = gasSensor->tvoc_read(); + if(gassensor_en) { + gasSensor->has_new_data(); + eco2 = gasSensor->co2_read(); + tvoc = gasSensor->tvoc_read(); + + printf("CCS811:\r\n"); + printf("CO2: %ld ppm\r\n", eco2); + printf("VoC: %ld ppb\r\n", tvoc); + } + /* measure HALL */ - hallSensor->measureOnce(); + if(hallsensor_en) { + hallSensor->measureOnce(); - printf("-------------------------\r\n"); - printf("BMP280:\r\n"); - printf("P: %.2f bar\r\n", pressure); - printf("T: %.2f degC\r\n", temperature2); - printf("Si7021:\r\n"); - printf("T: %ld.%03ld degC\r\n", temperature/1000, abs(temperature%1000)); - printf("h: %ld.%03ld %%\r\n", humidity/1000, humidity%1000); - printf("CCS811:\r\n"); - printf("CO2: %ld ppm\r\n", eco2); - printf("VoC: %ld ppb\r\n", tvoc); - printf("Si7210:\r\n"); - printf("T: %d.%02d degC\r\n", hallSensor->getTemperature()/1000, abs(hallSensor->getTemperature()%1000)); - printf("F: %i.%03d mT\r\n", (int)(hallSensor->getFieldStrength()/1000), abs(hallSensor->getFieldStrength() % 1000)); + printf("Si7210:\r\n"); + printf("T: %d.%02d degC\r\n", hallSensor->getTemperature()/1000, abs(hallSensor->getTemperature()%1000)); + printf("F: %i.%03d mT\r\n", (int)(hallSensor->getFieldStrength()/1000), abs(hallSensor->getFieldStrength() % 1000)); + } - Thread::wait(15000); + /* measure light */ + if(lightsensor_en) { + lightSensor->get_light_and_uv(&light, &uv); + + printf("BMP280:\r\n"); + printf("L: %.2f lux\r\n", light); + printf("U: %.2f\r\n", uv); + } + + wait_ms(15000); } while(1); }