Intermediate
30 min

Enjoy pure air thanks to the MiCS-VZ-89TE and PIC18F4610

Air quality unveiled: Your window to healthier, happier living

Air quality 7 Click with EasyPIC v8

Published Nov 01, 2023

Click board™

Air quality 7 Click

Dev Board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18F4610

Our comprehensive air quality monitoring solution empowers individuals, businesses, and communities with accurate data to make informed decisions for healthier surroundings.

A

A

Hardware Overview

How does it work?

Air Quality 7 Click is based on the MiCS-VZ-89TE, an integrated sensor module from Amphenol for indoor air quality monitoring. The MiCS-VZ-89TE combines the most modern MOS sensor technology with intelligent detection algorithms to control VOCs and CO2 fluctuations in buildings. Among other appealing features like 3.3V supply, I2C communication, and calibration-free high sensitivity, this module has a small size factor. The sensor must not be exposed to high concentrations of organic solvents, ammonia, silicone vapor, or cigarette smoke to avoid poisoning the sensitive layer. It should be protected against water and dust projections, and its Vendor strongly recommends using ESD protection equipment to handle the sensor. This Click board™ is easy to program and read data because it does not require an overly demanding configuration. The first step is the initialization of

all the necessary peripherals and pins. The additional delay time of a couple of seconds during system initialization is needed because this Click board™ needs some time to establish the measurements. The second initialization is the I2C driver and communication test by reading the revision information of the module. If the CRC check is OK, it allows the program to go on; if it's not, a user needs to restart the program. The user can read the air quality status if every step is valid. This can also be seen in an example code that contains easy-to-use functions that may be used as a reference for further development. Air quality 7 Click communicates with MCU using the standard I2C 2-Wire interface that supports Standard-Mode operation with bit rates up to 100 kbit/s. The MiCS-VZ-89TE slave address contains seven fixed bits. The slave address byte is the first byte received following the START condition from

the host device. The first part of the address byte consists of a 4-bit device code, which is set to 1110 for the IAQS, followed by three address bits (A2, A1, A0), which are programmed at 0. The dual signal output routed on the OUT pin of the mikroBUS™ socket, which brings the results of the measurements, can be read through a multiplexed PWM output or an I2C bus. This Click board™ is designed to be operated only with a 3.3V logic voltage level. A proper logic voltage level conversion should be performed before the Click board™ is used with MCUs with different logic voltage levels. More information about the MiCS-VZ-89TE can be found in the attached datasheet. However, the Click board™ comes equipped with a library that contains easy-to-use functions and a usage example that may be used as a reference for further development.

Air quality 7 Click top side image
Air quality 7 Click bottom side image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

PIC18F4610

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

3968

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
PWM Output
RB0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Air quality 7 Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyPIC v8 DIP MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Air Quality 7 Click driver.

Key functions:

  • airquality7_get_status - Get Status function

  • airquality7_get_revision - Get Revision function

  • airquality7_get_r0_calib - Get R0 Calibration function.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief AirQuality7 Click example
 * 
 * # Description
 * This demo application measures air quality.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes I2C driver and reads revision date of the module. 
 * If CRC check is OK allows the program to go on, otherwise, it displays a message that
 * the program needs to be restarted.
 * 
 * ## Application Task  
 * Reads air quality status every 1500ms and shows the results on the USB UART.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "airquality7.h"

// ------------------------------------------------------------------ VARIABLES

static airquality7_t airquality7;
static log_t logger;

uint16_t airquality7_tvoc_ppb;
uint16_t airquality7_co2_ppm;
uint32_t airquality7_res_val_ohm;
airquality7_err_t airquality7_err_code;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    airquality7_cfg_t cfg;
    
    uint8_t airquality7_rev_year       = AIRQUALITY7_DUMMY;
    uint8_t airquality7_rev_month      = AIRQUALITY7_DUMMY;
    uint8_t airquality7_rev_day        = AIRQUALITY7_DUMMY;
    uint8_t airquality7_rev_ascii_code = AIRQUALITY7_DUMMY;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    airquality7_cfg_setup( &cfg );
    AIRQUALITY7_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    airquality7_init( &airquality7, &cfg );

    
    airquality7_tvoc_ppb    = AIRQUALITY7_DUMMY;
    airquality7_co2_ppm     = AIRQUALITY7_DUMMY;
    airquality7_res_val_ohm = AIRQUALITY7_DUMMY;

    airquality7_err_code = airquality7_get_revision( &airquality7, 
                                                     &airquality7_rev_year,
                                                     &airquality7_rev_month,
                                                     &airquality7_rev_day,
                                                     &airquality7_rev_ascii_code );
    
    if ( airquality7_err_code == AIRQUALITY7_ERR_OK )
    {
        log_printf( &logger, " Revision date: %.2u.%.2u.%.2u\r\n", ( uint16_t ) airquality7_rev_day, 
                                                                   ( uint16_t ) airquality7_rev_month,
                                                                   ( uint16_t ) airquality7_rev_year );
        log_printf( &logger, " ASCII code for a charter: %u \r\n", ( uint16_t ) airquality7_rev_ascii_code );
    }
    else
    {
        log_printf( &logger, "CRC ERROR READING REVISION. \r\n" );
        Delay_ms( 1000 );
        
        for ( ; ; )
        {
            log_printf( &logger, "PLEASE, RESTART YOUR SYSTEM...\r\n" );
            Delay_ms( 1000 );
            log_printf( &logger, " \r\n \r\n " );
            Delay_ms( 1000 );
        }
    }
    
    log_printf( &logger, "----------------------------------------- \r\n" );
    Delay_ms( 500 );
}

void application_task ( void )
{
    airquality7_err_code = airquality7_get_status( &airquality7, 
                                                   &airquality7_tvoc_ppb, 
                                                   &airquality7_co2_ppm,
                                                   &airquality7_res_val_ohm, 
                                                   AIRQUALITY7_NULL );
        
    if ( airquality7_err_code == AIRQUALITY7_ERR_OK )
    {
        uint8_t cnt;

        log_printf( &logger, " tVOC [ppb] = %u \r\n", airquality7_tvoc_ppb );

        log_printf( &logger, " CO2 [ppm] = %u \r\n", airquality7_co2_ppm );

        log_printf( &logger, " Resistor value [ohm] = %lu \r\n", airquality7_res_val_ohm );
        log_printf( &logger, "----------------------------------------- \r\n" );
    }
    
    Delay_ms( 1500 );
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources