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 Steven Cooreman

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

Committer:
stevew817
Date:
2017-05-04
Revision:
0:fe1dd6f4950c
Child:
1:7174444a05e2

File content as of revision 0:fe1dd6f4950c:

/*
 * PackageLicenseDeclared: Apache-2.0
 * Copyright (c) 2017 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <string>
#include "mbed.h"
#include "BMP280/BMP280.h"
#include "CCS811/CCS811.h"
#include "AMS_CCS811.h"
#include "Si7021.h"
#include "Si7210.h"

DigitalOut env_en(PF9, 1);
DigitalOut ccs_en(PF14, 1);
DigitalOut ccs_wake(PF15, 1);
DigitalOut hall_en(PB10, 1);

I2C ccs_i2c(PB6, PB7);
I2C hall_i2c(PB8, PB9);
I2C env_i2c(PC4, PC5);

int main() {
    uint32_t eco2, tvoc;
    float pressure, temperature2;
    int32_t temperature;
    uint32_t humidity;

    ccs_en = 0;
    wait_ms(1000);
    ccs_en = 1;
    wait_ms(1000);

    /* Initialize air quality sensor */
    AMS_CCS811* gasSensor = new AMS_CCS811(&ccs_i2c, PF15);
    if(!gasSensor->init()) {
        printf("Failed CCS init\r\n");
    }
    wait_ms(10);

    /* Initialize barometer and RHT */
    BMP280* pressureSensor = new BMP280(env_i2c);
    Si7021* rhtSensor = new Si7021(&env_i2c);

    printf("\r\n\r\nHello Jumbo...\r\n");
    
    /* Check if hall sensor is alive */
    silabs::Si7210* hallSensor = new silabs::Si7210(&hall_i2c);
    uint8_t id;
    hallSensor->wakeup();
    hallSensor->readRegister(SI72XX_HREVID, &id);
    printf("Hall ID: %d\r\n", id);
    
    do {
        /* Measure barometric pressure */
        rhtSensor->measure();
        rhtSensor->measure();
        temperature = rhtSensor->get_temperature();
        humidity = rhtSensor->get_humidity();
        
        temperature2 = pressureSensor->getTemperature();
        pressure = pressureSensor->getPressure();

        /* Measure air quality */
        gasSensor->has_new_data();
        eco2 = gasSensor->co2_read();
        tvoc = gasSensor->tvoc_read();
        
        /* measure HALL */
        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));
        
        Thread::wait(15000);
    } while(1);
}