Beginner
10 min

Stay one step ahead of smoke and fire hazards with ADPD188BI and STM32F042K6

Reliable, rapid, responsive

Smoke 2 Click with Nucleo 32 with STM32F042K6 MCU

Published Oct 01, 2024

Click board™

Smoke 2 Click

Dev. board

Nucleo 32 with STM32F042K6 MCU

Compiler

NECTO Studio

MCU

STM32F042K6

Breathe easy and stay secure with our cutting-edge smoke detection technology, engineered to shield you from potential hazards.

A

A

Hardware Overview

How does it work?

Smoke 2 Click is based on the ADPD188BI, a complete photometric system for smoke detection using optical dual-wavelength technology from Analog Devices. The module combines the dual photodetector with two separate LEDs and a mixed-signal photometric front-end ASIC. It prevents light from going directly from the LED to the photodiode without entering the smoke detection chamber. The dual-wavelength combination in a scattering measurement, a 470nm blue LED and an 850nm IR LED, allows particle size discrimination between different types of smoke, dust, or steam. The core circuitry stimulates the LEDs and measures the corresponding optical return signals. This integrated solution enables low power and reduces false smoke alarms in harsh environments due to dust, steam, and other nuisance sources. The smoke chamber 28800X is designed to be used with the ADPD188BI and minimize background response while controlling the environment around the ADPD188BI module by limiting dust accumulation and keeping out insects. The ADPD188BI registers a positive signal due to light scattering from the smoke chamber. Although the smoke chamber minimizes this positive signal, there is a nonzero response in the absence of smoke. When using a smoke chamber, this background response must be accounted for if you want to accurately measure the level of particles present in the smoke chamber. The ADPD188BI operates in three modes: Standby, Program, or Normal Sampling Mode. Standby Mode is a power-saving mode in which data collection does not occur, while the Program

Mode configures and program registers. During regular operation, the ADPD188BI pulses light and collects data, and in this mode, power consumption depends on the pulse count and data rate. Besides, the ADPD188BI also requires a supply voltage of 1.8V to work regularly. Therefore, a small regulating LDO, the ADP160 from Analog Devices, provides a 1.8V out of 3.3V mikroBUS™ rail, or optionally, from a battery power source. The output from the LDO regulator provides a needed voltage for one side of the ADG3308, a bidirectional level translator containing eight bidirectional channels from Analog Devices, while the voltage for the other side of the level translator is delivered from the VCC SEL jumper. Also, this Click board™ may be battery-powered, indicated via an LED indicator labeled as BATT, and used as a stand-alone device. It has LTC3531, a synchronous buck-boost DC/DC converter also from Analog Devices. It allows battery voltage to be converted to 3.3V and used in a selection of voltage needed to be converted by ADP160 to supply ADPD188BI. Smoke 2 Click provides the possibility of using both I2C and SPI serial interfaces, although only one is allowed at any given time in the actual application. All internal registers of the ADPD188BI are accessed through the selected communications interface. I2C supports Fast mode with data transfer of 400 kbps, while the SPI interface supports frequency up to 10MHz. This selection can be performed by positioning SMD jumpers labeled COMM SEL to an appropriate position. Note that all the jumpers must be lined to the same side, or the Click board™ may become unresponsive. Additionally, test points,

located in the upper part on the top side of the board, for pins EXT_IN1, EXT_IN2, and GPIO1 allow users to plug in external sensors like thermistors into the EXT pins and to use the GPIO1 pin for some digital functionality. The EXT_IN1 and EXT_IN2 pins are also current inputs that can be connected to external sensors. A voltage source can be connected to the EXT_IN1 and EXT_IN2 pins through a series resistance, effectively converting the voltage into a current. Other test points for LED1, LED2, and LED3 pins can be found under the smoke chamber on the top side of the board if users want to plug in their LEDs and not use the internal LEDs. The user also has the option to select the voltage for the blue LED of the ADPD188BI, which can be selected via the BLUE SEL jumper to analyze the characteristics with the recommended and maximum values. This diode can be powered by a maximum of 6V achieved by LTC3459 from Analog Devices. Optionally, the Smoke 2 Click board™, in addition to the mikroBUS™ power supply, can also be powered from an external battery. The battery power supply section is designed to power ADPD188BI and fulfill the demand for a complete solution, including the microcontroller and short-range radio power needs. 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.

Smoke 2 Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F042K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

6144

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
SPI Chip Select
PA4
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PA12
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Smoke 2 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F042K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 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
STM32 M4 Clicker HA MCU/Select 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 Smoke 2 Click driver.

Key functions:

  • smoke2_get_int_pin - This function eget state of int pin of Smoke 2 click board.

  • smoke2_write_data - This function is generic for writing data to register of Smoke 2 click board.

  • smoke2_read_data - This function is generic for reading data from registar of Smoke 2 click board.

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 main.c
 * @brief Smoke2 Click example
 *
 * # Description
 * This example is made to see how Smoke 2 Clicks work. The purpose of this example is that,
 * depending on the way we choose, it collects data from the external environment about smoke,
 * processes it, and prints it via the UART terminal.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of communication modules, additional pins, Mapping pins and configures 
 * device for measurement.
 *
 * ## Application Task
 * Example shows module working depending on example mode. We can choose between:
 * EXAMPLE_MODE_PROXIMITY and EXAMPLE_MODE_SMOKE.
 *
 * Additional Functions :
 * - void smoke_example ( smoke2_t *ctx ) - Example checks if sensor data goes over threshold set.
 * - void proximity_example ( void ) - Reads sensor data and logs it.
 *
 * @author Jelena Milosavljevic
 *
 */

#include "board.h"
#include "log.h"
#include "smoke2.h"

static smoke2_t smoke2;
static log_t logger;

#define EXAMPLE_MODE_SMOKE      0
#define EXAMPLE_MODE_PROXIMITY  1

#define EXAMPLE_MODE            EXAMPLE_MODE_SMOKE

/**
 * @brief Smoke 2 Smoke example.
 * @details This function checks if sensor data is gone over thershold set.
 */
void smoke_example ( smoke2_t *ctx );

/**
 * @brief Smoke 2 Proximity example.
 * @details This function reads sensor data and logs it.
 */
void proximity_example ( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;            /**< Logger config object. */
    smoke2_cfg_t smoke2_cfg;      /**< Click config object. */
    
    /** 
     * 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.
    smoke2_cfg_setup( &smoke2_cfg );
    SMOKE2_MAP_MIKROBUS( smoke2_cfg, MIKROBUS_1 );
    err_t init_flag  = smoke2_init( &smoke2, &smoke2_cfg );
    if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }

    smoke2_soft_reset( &smoke2 );
    smoke2_set_mode( &smoke2, SMOKE2_MODE_IDLE );

    uint16_t devid = smoke2_read_data( &smoke2, SMOKE2_REG_DEVID );
    log_printf( &logger, ">> ID:  0x%.2X\r\n", ( uint16_t ) ( devid & 0xFF ) );  
    log_printf( &logger, ">> REV: 0x%.2X\r\n", ( uint16_t ) ( ( devid >> 8 ) & 0xFF ) );
    Delay_ms ( 1000 );
    
    log_printf( &logger, ">> Configuration <<\r\n" );
    smoke2_default_cfg( &smoke2 ); 
    Delay_ms ( 1000 ); 
    
#if ( EXAMPLE_MODE == EXAMPLE_MODE_SMOKE )
    log_printf( &logger, ">> SMOKE MODE <<\r\n" );
    log_printf( &logger, ">> Calibration <<\r\n" );
    uint16_t calib_data = smoke2_smoke_calibration( &smoke2, 500 );
    log_printf( &logger, ">> Calibration data: %u\r\n", calib_data );
#elif ( EXAMPLE_MODE == EXAMPLE_MODE_PROXIMITY )
    log_printf( &logger, ">> PROXIMITY MODE <<\r\n" );
#endif
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
#if ( EXAMPLE_MODE == EXAMPLE_MODE_SMOKE )
    smoke_example( &smoke2 );
#elif ( EXAMPLE_MODE == EXAMPLE_MODE_PROXIMITY )
    proximity_example( );
#endif
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

void smoke_example ( smoke2_t *ctx ) 
{
    static uint8_t last_state = 0;
    uint8_t smoke_detected = smoke2_check_smoke( &smoke2 );
    if ( last_state != smoke_detected ) 
    {
        if ( SMOKE2_SMOKE_DETECTED == smoke_detected ) 
        {
            log_printf( &logger, ">> SMOKE_DETECTED <<\r\n" );
        }
        else if ( SMOKE2_SMOKE_NOT_DETECTED == smoke_detected ) 
        {
            log_printf( &logger, ">> SMOKE_CLEAR <<\r\n" );
        }
        else 
        {
            log_printf( &logger, ">> ERROR <<\r\n" );
            for( ; ; );
        }
        last_state = smoke_detected;
    }
}

void proximity_example ( void ) 
{
    uint16_t sens_data = 0;
    uint8_t fifo_int = 0;
    uint8_t slot_a_int = 0;
    uint8_t slot_b_int = 0;
    if ( 0 == smoke2_get_int_pin( &smoke2 ) ) 
    {
        smoke2_get_int( &smoke2, &fifo_int, &slot_a_int, &slot_b_int );
        if ( 0 != slot_a_int ) 
        {
            sens_data = smoke2_read_sens_data( &smoke2, SMOKE2_SLOT_A, SMOKE2_CHN_1 );
            log_printf( &logger, ">> DATA A: %d\r\n", sens_data );
            slot_a_int = 0;
            Delay_ms ( 100 );
        }
        if ( 0 != slot_b_int ) 
        {
            sens_data = smoke2_read_sens_data( &smoke2, SMOKE2_SLOT_B, SMOKE2_CHN_1 );
            log_printf( &logger, ">> DATA B: %d\r\n", sens_data );
            slot_b_int = 0;
            Delay_ms ( 100 );
        }
        if ( 0 != fifo_int ) 
        {
            log_printf( &logger, " \r\n", fifo_int );
            for ( uint8_t fifo_cnt = 0; fifo_cnt < fifo_int; fifo_cnt++ ) 
            {
                sens_data = smoke2_read_data( &smoke2, SMOKE2_REG_FIFO_ACCESS );
                log_printf( &logger, ">> FIFO: %d\r\n", sens_data );
            }
            Delay_ms ( 100 );
        }
    }
}

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