Beginner
10 min

Capture ultra-precise acceleration data and detect electric charge variations with LIS2DUXS12 and STM32F031K6

Precise acceleration measurement and electric charge variation detection

Accel&Qvar Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

Accel&Qvar Click

Dev Board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Designed for precise acceleration measurements and electric charge detection, ideal for developing smart devices and IoT applications.

A

A

Hardware Overview

How does it work?

Accel&Qvar Click is based on the LIS2DUXS12, an ultralow-power accelerometer from STMicroelectronics, which is notable for its integration of Qvar technology, artificial intelligence, and an anti-aliasing filter. This component stands out due to its design, which minimizes power consumption while incorporating advanced functionalities. Embedded within the LIS2DUXS12 is a digital, 3-axis accelerometer that merges MEMS and ASIC technologies to feature an array of capabilities, including an always-on anti-aliasing filter, a finite state machine (FSM), and a machine learning core (MLC) equipped with adaptive self-configuration (ASC). Additionally, it houses an analog hub alongside a Qvar sensing channel. Including the FSM and MLC with ASC equips the LIS2DUXS12 with superior edge processing capabilities. Meanwhile, the analog hub and Qvar sensing channel pave the way for unparalleled system optimization. The LIS2DUXS12 offers adjustable full scales of ±2g, ±4g, ±8g, and ±16g and can accurately measure accelerations with output data rates (ODR) ranging from 1.6Hz to 800Hz. Its built-in engine handles motion and acceleration detections, such as free-fall, wake-up events, and multiple tap recognitions, alongside activity/inactivity monitoring and orientation detection. Operating modes of the

LIS2DUXS12 include high-performance, low-power, ultralow-power, and one-shot, ensuring versatility across different applications. Notably, its low-power mode engages a robust anti-aliasing filter, maintaining low energy consumption. These features make it ideal for various applications, including wearable technology, portable healthcare devices, and motion-activated user interfaces. As mentioned, the LIS2DUXS12 embeds a Qvar sensor that detects electric charge variations in the proximity of the external electrodes connected to the device, in this case, two sets of pads. The upper pair can be used as a radar and is disabled by default. You can enable it by soldering two unpopulated R8 and R15 0 Ohm resistors. Two arrow-like pads are parts of a sensitive touch interface able to detect touch, press, or swipe. Two 3-pin headers allow you to attach external electrodes on the sensor's Q1 and Q2 Qvar channels. These electrodes can be used for all the mentioned Qvar functionalities. This Click board™ can communicate with the host MCU by selecting one between the I2C and SPI interfaces over the COMM SEL jumper, where the I2C is selected by default. All four jumpers must be set into the appropriate position for this Click board™ to work properly. The standard 2-Wire I2C interface supports Fast mode (400kHz) and Fast mode plus

(1MHz) clock frequencies. The I2C address can be selected over the ADDR SEL jumper, where 0 is set by default. If your choice is the SPI, this Click board™ supports both 3- and 4-Wire SPI serial interfaces with clock frequencies up to 10MHz. The device may be configured to generate interrupt signals from an independent inertial wake-up/free-fall event or from the device's position. The thresholds and timing of this interrupt generator are programmable by the end user in runtime. Automatic programmable sleep-to-wake-up and return-to-sleep functions are also available for enhanced power saving. The device interrupts signal can behave as free-fall (3-axis under-threshold recognition), wake-up (axis recognition), wake-to-sleep (change of state recognition active-sleep also known as activity-inactivity), 6D and 4D orientation detection (change of position recognition), Tap-tap: single, double, triple axis and sign recognition. To use this feature on IT1 and IT2 pins, populate R18 and R19 resistors, which are unpopulated by default. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Accel&Qvar Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F031K6 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)

4096

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

Interrupt 1
PA0
AN
ID SEL
PA11
RST
SPI Select / ID COMM
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 2
PA12
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel&Qvar 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 STM32F031K6 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
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU Access 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 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 via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for Accel&Qvar Click driver.

Key functions:

  • accelqvar_get_axes_data - This function reads the accelerometer sensor axes data

  • accelqvar_get_qvar_data - This function reads the Qvar electrostatic sensor data output

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 main.c
 * @brief AccelQvar Click example
 *
 * # Description
 * This library contains API for the AccelQvar Click driver. 
 * The library initializes and defines the I2C and SPI drivers to write and read data 
 * from registers and the default configuration for reading the accelerator data 
 * and Qvar electrostatic sensor measurement.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * The initialization of I2C and SPI module and log UART.
 * After driver initialization, the app sets the default configuration.
 *
 * ## Application Task
 * This example demonstrates the use of the AccelQvar Click board.
 * Measures and displays acceleration data for the X-axis, Y-axis, and Z-axis [mg] 
 * and detects and displays a touch position and the strength of a touch.
 * Results are being sent to the UART Terminal, where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "accelqvar.h"

// Qvar sensing - the threshold for touch detection, position and sensitivity
#define ACCELQVAR_THOLD_DETECT_TOUCH    1.0
#define ACCELQVAR_TOUCH_ZERO            0.0
#define ACCELQVAR_THOLD_SENS            1.3

static accelqvar_t accelqvar;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    accelqvar_cfg_t accelqvar_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.
    accelqvar_cfg_setup( &accelqvar_cfg );
    ACCELQVAR_MAP_MIKROBUS( accelqvar_cfg, MIKROBUS_1 );
    err_t init_flag = accelqvar_init( &accelqvar, &accelqvar_cfg );
    if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    Delay_ms ( 100 );

    if ( ACCELQVAR_ERROR == accelqvar_default_cfg ( &accelqvar ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    Delay_ms ( 100 );

    log_info( &logger, " Application Task " );
    log_printf( &logger, "_________________\r\n" );
}

void application_task ( void )
{
    accelqvar_axes_t acc_axis;
    if ( ACCELQVAR_OK == accelqvar_get_axes_data( &accelqvar, &acc_axis ) )
    {
        log_printf( &logger, " Accel X: %.2f mg\r\n", acc_axis.x );
        log_printf( &logger, " Accel Y: %.2f mg\r\n", acc_axis.y );
        log_printf( &logger, " Accel Z: %.2f mg\r\n", acc_axis.z );
        log_printf( &logger, "_________________\r\n" );
    }

    float qvar = 0;
    if ( ACCELQVAR_OK == accelqvar_get_qvar_data( &accelqvar, &qvar ) )
    {
        if ( abs( qvar ) > ACCELQVAR_THOLD_DETECT_TOUCH )
        {
            uint8_t touch_strength = ( uint8_t ) ( abs( qvar ) / ACCELQVAR_THOLD_SENS );
            log_printf( &logger, " Touch position: " );
            if ( qvar < ACCELQVAR_TOUCH_ZERO )
            {
                log_printf( &logger, " Left\r\n" );
            }
            else
            {
                log_printf( &logger, " Right\r\n " );
            }
            log_printf( &logger, " Strength: " );
            while ( touch_strength )
            {
                log_printf( &logger, "|" );
                touch_strength--;
            }
            log_printf( &logger, "\r\n_________________\r\n" );
        }
    }
    Delay_ms ( 1000 );
}

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;
}

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