Intermediate
30 min

Deliver accurate and swift identification of ethanol presence using 3SP-Ethanol-1000 and PIC32MZ2048EFH100

Your reliable partner in gas detection

Alcohol 2 Click with Flip&Click PIC32MZ

Published Aug 29, 2023

Click board™

Alcohol 2 Click

Dev. board

Flip&Click PIC32MZ

Compiler

NECTO Studio

MCU

PIC32MZ2048EFH100

Upgrade your safety measures with highly accurate and reliable ethanol gas detection solution

A

A

Hardware Overview

How does it work?

Alcohol 2 Click is based on the 3SP-Ethanol-1000 from SPEC Sensors, which can sense ethanol concentration up to 1000ppm. The sensor has a very short response time; however, the longer it is exposed to a particular gas, the more accurate data it can provide. This is especially true when calibration is performed. The sensor is sensitive to small dust particles, condensed water, and other impurities, which might prevent gas from reaching the sensor. It is advised to protect the sensor when used in critical applications. In ideal conditions, the lifetime of this sensor is indefinite, but in real-life applications, the expected operating life is more than five years (10 years at 23 ± 3 ˚C; 40 ± 10 %RH). Although very reliable and accurate, this sensor is great for building relative gas sensing applications. For example, it can detect increased levels of ethanol gas. However, when developing applications for the absolute gas concentration, the sensor must be calibrated, and the measurement data needs to be compensated. Factors such as humidity and temperature can affect measurements; the sensor reaction curve to a specific measured gas (ethanol in this case) is not completely linear, and other gases might affect the measurement (cross-sensitivity to other gases). For this reason, a range of calibration routines must be done in the working environment conditions to calculate the absolute

gas concentration. Alcohol 2 click uses the LMP91000, a configurable AFE potentiostat IC for low-power chemical sensing applications, from Texas Instruments. It provides the complete sensor solution, generating the output voltage proportional to the sensor current. A trans-impedance amplifier (TIA) with a programmable gain is used to convert the current through the sensor, covering the range from 5μA to 750 μA, depending on the used sensor. The voltage between the referent electrode (RE) and the working electrode (WE) is held constant, with the bias set by the variable bias circuitry. This type of sensor performs best when a fixed bias voltage is applied. The sensor manufacturer recommends a +100mV fixed bias for the sensor on this Click board™. The bias voltage and the TIA gain can be set via the I2C registers. In addition, an embedded thermal sensor in the AFE IC can be used for the result compensation if needed. It is available via the VOUT pin as the analog voltage value with respect to GND. The Click board™ has two additional ICs onboard. The first is the MCP3221, a 12-bit successive approximation register A/D converter from Microchip. The second IC is the OPA344, a single-supply, rail-to-rail operational amplifier from Texas Instruments. It is possible to use the onboard switch, labeled as AN SEL, to select the IC to which the VOUT pin from the

LMP91000 AFE is routed. If the switch is in the ADC position, the VOUT pin will be routed to the input of the MCP3221 ADC. This allows the voltage value at the VOUT pin to be read via the I2C interface as digital information. When the switch is in the AN position, it will route the VOUT pin of the LMP91000 AFE IC to the input of the OPA344. The output of the OPA344 op-amp has a stable unity gain, acting as a buffer so that the voltage at the VOUT pin of the AFE can be sampled by the host MCU via the AN pin of the mikroBUS™. The RST pin on the mikroBUS™ is routed to the MEMB pin of the LMP91000, and it is used to enable the I2C interface section, thus making it possible to use more than one chip on the same I2C bus. When driven to a LOW logic level, the I2C communication is enabled, and the host device (host MCU) can issue a START condition. The RST pin should stay at LOW during the communication. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

Alcohol 2 Click top side image
Alcohol 2 Click bottom side image

Features overview

Development board

Flip&Click PIC32MZ is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller, the PIC32MZ2048EFH100 from Microchip, four mikroBUS™ sockets for Click board™ connectivity, two USB connectors, LED indicators, buttons, debugger/programmer connectors, and two headers compatible with Arduino-UNO pinout. Thanks to innovative manufacturing technology,

it allows you to build gadgets with unique functionalities and features quickly. Each part of the Flip&Click PIC32MZ development kit contains the components necessary for the most efficient operation of the same board. In addition, there is the possibility of choosing the Flip&Click PIC32MZ programming method, using the chipKIT bootloader (Arduino-style development environment) or our USB HID bootloader using mikroC, mikroBasic, and mikroPascal for PIC32. This kit includes a clean and regulated power supply block through the USB Type-C (USB-C) connector. All communication

methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, user-configurable buttons, and LED indicators. Flip&Click PIC32MZ development kit allows you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Flip&Click PIC32MZ double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

Analog Output
RB11
AN
I2C Enable
RE2
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
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RA2
SCL
I2C Data
RA3
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Alcohol 2 Click Schematic schematic

Step by step

Project assembly

Flip&Click PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Flip&Click PIC32MZ as your development board.

Flip&Click PIC32MZ front image hardware assembly
Buck 22 Click front image hardware assembly
Prog-cut hardware assembly
Flip&Click PIC32MZ - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for Alcohol 2 Click driver.

Key functions:

  • alcohol2_write_byte - This function writes one byte to the register

  • alcohol2_read_byte - This function reads one byte from the register

  • alcohol2_read_alcohol - This function reads Alcohol data.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief Alcohol2 Click example
 * 
 * # Description
 * The demo application gets Alcohol data and logs data to USBUART.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes device configuration.
 *  
 * ## Application Task  
 * Gets Alcohol (C2H5OH) data and logs data to USBUART every 500ms.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "alcohol2.h"

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

static alcohol2_t alcohol2;
static log_t logger;

static float alcohol_value;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    alcohol2_cfg_t cfg;

    /** 
     * 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.

    alcohol2_cfg_setup( &cfg );
    ALCOHOL2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    alcohol2_init( &alcohol2, &cfg );

    alcohol2_write_byte( &alcohol2, ALCOHOL2_MODECN_REG, ALCOHOL2_DEEP_SLEEP_MODE );
    alcohol2_write_byte( &alcohol2, ALCOHOL2_LOCK_REG,   ALCOHOL2_WRITE_MODE );
    alcohol2_write_byte( &alcohol2, ALCOHOL2_TIACN_REG, ALCOHOL2_EXT_TIA_RES | ALCOHOL2_100_OHM_LOAD_RES );
    alcohol2_write_byte( &alcohol2, ALCOHOL2_REFCN_REG, ALCOHOL2_VREF_INT | ALCOHOL2_50_PERCENTS_INT_ZERO | ALCOHOL2_BIAS_POL_NEGATIVE | ALCOHOL2_0_PERCENTS_BIAS );

    log_printf( &logger, "Alcohol 2 is initialized\r\n" );
    Delay_ms( 300 );
}

void application_task ( void )
{
    alcohol_value = alcohol2_read_alcohol( &alcohol2 );
    log_printf( &logger, "Alcohol value : %f \r\n", alcohol_value );
    Delay_ms( 500 );
}

void main ( void )
{
    application_init( );

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

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

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.