![](/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.
main.cpp@0:fe1dd6f4950c, 2017-05-04 (annotated)
- Committer:
- stevew817
- Date:
- Thu May 04 12:16:45 2017 +0000
- Revision:
- 0:fe1dd6f4950c
- Child:
- 1:7174444a05e2
Initial wip;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stevew817 | 0:fe1dd6f4950c | 1 | /* |
stevew817 | 0:fe1dd6f4950c | 2 | * PackageLicenseDeclared: Apache-2.0 |
stevew817 | 0:fe1dd6f4950c | 3 | * Copyright (c) 2017 ARM Limited |
stevew817 | 0:fe1dd6f4950c | 4 | * |
stevew817 | 0:fe1dd6f4950c | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
stevew817 | 0:fe1dd6f4950c | 6 | * you may not use this file except in compliance with the License. |
stevew817 | 0:fe1dd6f4950c | 7 | * You may obtain a copy of the License at |
stevew817 | 0:fe1dd6f4950c | 8 | * |
stevew817 | 0:fe1dd6f4950c | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
stevew817 | 0:fe1dd6f4950c | 10 | * |
stevew817 | 0:fe1dd6f4950c | 11 | * Unless required by applicable law or agreed to in writing, software |
stevew817 | 0:fe1dd6f4950c | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
stevew817 | 0:fe1dd6f4950c | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
stevew817 | 0:fe1dd6f4950c | 14 | * See the License for the specific language governing permissions and |
stevew817 | 0:fe1dd6f4950c | 15 | * limitations under the License. |
stevew817 | 0:fe1dd6f4950c | 16 | */ |
stevew817 | 0:fe1dd6f4950c | 17 | |
stevew817 | 0:fe1dd6f4950c | 18 | #include <string> |
stevew817 | 0:fe1dd6f4950c | 19 | #include "mbed.h" |
stevew817 | 0:fe1dd6f4950c | 20 | #include "BMP280/BMP280.h" |
stevew817 | 0:fe1dd6f4950c | 21 | #include "CCS811/CCS811.h" |
stevew817 | 0:fe1dd6f4950c | 22 | #include "AMS_CCS811.h" |
stevew817 | 0:fe1dd6f4950c | 23 | #include "Si7021.h" |
stevew817 | 0:fe1dd6f4950c | 24 | #include "Si7210.h" |
stevew817 | 0:fe1dd6f4950c | 25 | |
stevew817 | 0:fe1dd6f4950c | 26 | DigitalOut env_en(PF9, 1); |
stevew817 | 0:fe1dd6f4950c | 27 | DigitalOut ccs_en(PF14, 1); |
stevew817 | 0:fe1dd6f4950c | 28 | DigitalOut ccs_wake(PF15, 1); |
stevew817 | 0:fe1dd6f4950c | 29 | DigitalOut hall_en(PB10, 1); |
stevew817 | 0:fe1dd6f4950c | 30 | |
stevew817 | 0:fe1dd6f4950c | 31 | I2C ccs_i2c(PB6, PB7); |
stevew817 | 0:fe1dd6f4950c | 32 | I2C hall_i2c(PB8, PB9); |
stevew817 | 0:fe1dd6f4950c | 33 | I2C env_i2c(PC4, PC5); |
stevew817 | 0:fe1dd6f4950c | 34 | |
stevew817 | 0:fe1dd6f4950c | 35 | int main() { |
stevew817 | 0:fe1dd6f4950c | 36 | uint32_t eco2, tvoc; |
stevew817 | 0:fe1dd6f4950c | 37 | float pressure, temperature2; |
stevew817 | 0:fe1dd6f4950c | 38 | int32_t temperature; |
stevew817 | 0:fe1dd6f4950c | 39 | uint32_t humidity; |
stevew817 | 0:fe1dd6f4950c | 40 | |
stevew817 | 0:fe1dd6f4950c | 41 | ccs_en = 0; |
stevew817 | 0:fe1dd6f4950c | 42 | wait_ms(1000); |
stevew817 | 0:fe1dd6f4950c | 43 | ccs_en = 1; |
stevew817 | 0:fe1dd6f4950c | 44 | wait_ms(1000); |
stevew817 | 0:fe1dd6f4950c | 45 | |
stevew817 | 0:fe1dd6f4950c | 46 | /* Initialize air quality sensor */ |
stevew817 | 0:fe1dd6f4950c | 47 | AMS_CCS811* gasSensor = new AMS_CCS811(&ccs_i2c, PF15); |
stevew817 | 0:fe1dd6f4950c | 48 | if(!gasSensor->init()) { |
stevew817 | 0:fe1dd6f4950c | 49 | printf("Failed CCS init\r\n"); |
stevew817 | 0:fe1dd6f4950c | 50 | } |
stevew817 | 0:fe1dd6f4950c | 51 | wait_ms(10); |
stevew817 | 0:fe1dd6f4950c | 52 | |
stevew817 | 0:fe1dd6f4950c | 53 | /* Initialize barometer and RHT */ |
stevew817 | 0:fe1dd6f4950c | 54 | BMP280* pressureSensor = new BMP280(env_i2c); |
stevew817 | 0:fe1dd6f4950c | 55 | Si7021* rhtSensor = new Si7021(&env_i2c); |
stevew817 | 0:fe1dd6f4950c | 56 | |
stevew817 | 0:fe1dd6f4950c | 57 | printf("\r\n\r\nHello Jumbo...\r\n"); |
stevew817 | 0:fe1dd6f4950c | 58 | |
stevew817 | 0:fe1dd6f4950c | 59 | /* Check if hall sensor is alive */ |
stevew817 | 0:fe1dd6f4950c | 60 | silabs::Si7210* hallSensor = new silabs::Si7210(&hall_i2c); |
stevew817 | 0:fe1dd6f4950c | 61 | uint8_t id; |
stevew817 | 0:fe1dd6f4950c | 62 | hallSensor->wakeup(); |
stevew817 | 0:fe1dd6f4950c | 63 | hallSensor->readRegister(SI72XX_HREVID, &id); |
stevew817 | 0:fe1dd6f4950c | 64 | printf("Hall ID: %d\r\n", id); |
stevew817 | 0:fe1dd6f4950c | 65 | |
stevew817 | 0:fe1dd6f4950c | 66 | do { |
stevew817 | 0:fe1dd6f4950c | 67 | /* Measure barometric pressure */ |
stevew817 | 0:fe1dd6f4950c | 68 | rhtSensor->measure(); |
stevew817 | 0:fe1dd6f4950c | 69 | rhtSensor->measure(); |
stevew817 | 0:fe1dd6f4950c | 70 | temperature = rhtSensor->get_temperature(); |
stevew817 | 0:fe1dd6f4950c | 71 | humidity = rhtSensor->get_humidity(); |
stevew817 | 0:fe1dd6f4950c | 72 | |
stevew817 | 0:fe1dd6f4950c | 73 | temperature2 = pressureSensor->getTemperature(); |
stevew817 | 0:fe1dd6f4950c | 74 | pressure = pressureSensor->getPressure(); |
stevew817 | 0:fe1dd6f4950c | 75 | |
stevew817 | 0:fe1dd6f4950c | 76 | /* Measure air quality */ |
stevew817 | 0:fe1dd6f4950c | 77 | gasSensor->has_new_data(); |
stevew817 | 0:fe1dd6f4950c | 78 | eco2 = gasSensor->co2_read(); |
stevew817 | 0:fe1dd6f4950c | 79 | tvoc = gasSensor->tvoc_read(); |
stevew817 | 0:fe1dd6f4950c | 80 | |
stevew817 | 0:fe1dd6f4950c | 81 | /* measure HALL */ |
stevew817 | 0:fe1dd6f4950c | 82 | hallSensor->measureOnce(); |
stevew817 | 0:fe1dd6f4950c | 83 | |
stevew817 | 0:fe1dd6f4950c | 84 | printf("-------------------------\r\n"); |
stevew817 | 0:fe1dd6f4950c | 85 | printf("BMP280:\r\n"); |
stevew817 | 0:fe1dd6f4950c | 86 | printf("P: %.2f bar\r\n", pressure); |
stevew817 | 0:fe1dd6f4950c | 87 | printf("T: %.2f degC\r\n", temperature2); |
stevew817 | 0:fe1dd6f4950c | 88 | printf("Si7021:\r\n"); |
stevew817 | 0:fe1dd6f4950c | 89 | printf("T: %ld.%03ld degC\r\n", temperature/1000, abs(temperature%1000)); |
stevew817 | 0:fe1dd6f4950c | 90 | printf("h: %ld.%03ld %%\r\n", humidity/1000, humidity%1000); |
stevew817 | 0:fe1dd6f4950c | 91 | printf("CCS811:\r\n"); |
stevew817 | 0:fe1dd6f4950c | 92 | printf("CO2: %ld ppm\r\n", eco2); |
stevew817 | 0:fe1dd6f4950c | 93 | printf("VoC: %ld ppb\r\n", tvoc); |
stevew817 | 0:fe1dd6f4950c | 94 | printf("Si7210:\r\n"); |
stevew817 | 0:fe1dd6f4950c | 95 | printf("T: %d.%02d degC\r\n", hallSensor->getTemperature()/1000, abs(hallSensor->getTemperature()%1000)); |
stevew817 | 0:fe1dd6f4950c | 96 | printf("F: %i.%03d mT\r\n", (int)(hallSensor->getFieldStrength()/1000), abs(hallSensor->getFieldStrength() % 1000)); |
stevew817 | 0:fe1dd6f4950c | 97 | |
stevew817 | 0:fe1dd6f4950c | 98 | Thread::wait(15000); |
stevew817 | 0:fe1dd6f4950c | 99 | } while(1); |
stevew817 | 0:fe1dd6f4950c | 100 | } |