Beginner
10 min

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

Precise acceleration measurement and electric charge variation detection

Accel&Qvar Click with Clicker 4 for STM32F4

Published May 02, 2024

Click board™

Accel&Qvar Click

Dev.Board

Clicker 4 for STM32F4

Compiler

NECTO Studio

MCU

STM32F407VGT6

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

Clicker 4 for STM32F4 is a compact development board designed as a complete solution that you can use to quickly build your own gadgets with unique functionalities. Featuring an STM32F407VGT6 MCU, four mikroBUS™ sockets for Click boards™ connectivity, power management, and more, it represents a perfect solution for the rapid development of many different types of applications. At its core is an STM32F407VGT6 MCU, a powerful microcontroller by STMicroelectronics based on the high-performance

Arm® Cortex®-M4 32-bit processor core operating at up to 168 MHz frequency. It provides sufficient processing power for the most demanding tasks, allowing Clicker 4 to adapt to any specific application requirements. Besides two 1x20 pin headers, four improved mikroBUS™ sockets represent the most distinctive connectivity feature, allowing access to a huge base of Click boards™, growing on a daily basis. Each section of Clicker 4 is clearly marked, offering an intuitive and clean interface. This makes working with the

development board much simpler and, thus, faster. The usability of Clicker 4 doesn’t end with its ability to accelerate the prototyping and application development stages: it is designed as a complete solution that can be implemented directly into any project, with no additional hardware modifications required. Four mounting holes [4.2mm/0.165”] at all four corners allow simple installation by using mounting screws.

Clicker 4 for STM32F4 double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

10

Silicon Vendor

STMicroelectronics

Pin count

100

RAM (Bytes)

100

Used MCU Pins

mikroBUS™ mapper

Interrupt 1
PC4
AN
ID SEL
PC15
RST
SPI Select / ID COMM
PA4
CS
SPI Clock
PA5
SCK
SPI Data OUT
PA6
MISO
SPI Data IN
PA7
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt 2
PD0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB10
SCL
I2C Data
PB11
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel&Qvar Click Schematic schematic

Step by step

Project assembly

Clicker 4 for STM32F4 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 4 for STM32F4 as your development board.

Clicker 4 for STM32F4 front image hardware assembly
LTE IoT 5 Click front image hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Clicker 4 STM32F4 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
Clicker 4 for STM32F4 HA 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

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