STM32 Nucleo and CCS911 sensor MBed example

In this example we will connect a CCS811 gas sensor to an STM32 Nucleo and the code example will be written in the MBed compiler, lets look at the sensor

CCS811 is a low-power digital gas sensor solution, which integrates a gas sensor solution for detecting low levels of VOCs typically found indoors, with a microcontroller unit (MCU) and an Analog-to-Digital converter to monitor the local environment and provide an indication of the indoor air quality via an equivalent CO2 or TVOC output over a standard I2C digital interface.

Features

Integrated MCU
On-board processing
Standard digital interface
Optimised low power modes
IAQ threshold alarms
Programmable baseline
2.7mm x 4.0mm LGA package
Low component count
Proven technology platform

Specs

Interface I²C
Supply Voltage [V] 1.8 to 3.6
Power Consumption [mW] 1.2 to 46
Dimension [mm] 2.7 x 4.0 x 1.1 LGA
Ambient Temperature Range [°C] -40 to 85
Ambient Humidity Range [% r.h.] 10 to 95

Parts List

 

Amount Part Type
1 CJMCU-811 CCS811 Air Quality Gas Sensor
1 STM32 Development Board NUCLEO-F446RE, STM32 STM32F446RET6 MCU, supports Arduino

 

 

Schematics/Layout

Remember and connect WAKE to gnd

stm32 nucleo and ccs811 sensor
stm32 nucleo and ccs811 sensor

Code

Again we use a library this is the adafruit one – you can use the library manager and add this.

And this is the out of the box example

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "CCS811.h"


Serial pc(USBTX, USBRX);

#ifdef TARGET_UBLOX_EVK_ODIN_W2
CCS811 ccs811(PF_0, PF_1);
#else
CCS811 ccs811(I2C_SDA, I2C_SCL);
#endif


uint16_t eco2, tvoc;


void CCS811Callback(void)
{

    ccs811.readData(&eco2, &tvoc);

    pc.printf("eCO2 reading :%dppm, TVOC reading :%dppb\r\n", eco2, tvoc);

}


int main()
{
    ccs811.init();
    wait(1);

    while(1) {
//        ccs811.readstatus(); //0x90 reports everything working, 0x98 measurement ready to be used
        wait(1);
        CCS811Callback();
        wait(1);
    }
}

[/codesyntax]

 

Output

Open Teraterm and connect to the assigned port of the STM32 nucleo

You should see something like this

ccs811 output
ccs811 output

 

Links

ccs811 datasheet

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :