Beginner
10 min

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

Precise acceleration measurement and electric charge variation detection

Accel&Qvar Click with Clicker 2 for Kinetis

Published Apr 30, 2024

Click board™

Accel&Qvar Click

Dev.Board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

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 2 for Kinetis is a compact starter development board 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 ARM Cortex-M4F microcontroller, the MK64FN1M0VDC12 from NXP Semiconductors, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a JTAG programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and

features quickly. Each part of the Clicker 2 for Kinetis development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for Kinetis programming method, using a USB HID mikroBootloader or an external mikroProg connector for Kinetis programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Micro-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or

using a Li-Polymer battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for Kinetis is an integral part of the Mikroe ecosystem, allowing 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.

Clicker 2 for Kinetis dimensions image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

NXP

Pin count

121

RAM (Bytes)

262144

Used MCU Pins

mikroBUS™ mapper

Interrupt 1
PB2
AN
ID SEL
PB11
RST
SPI Select / ID COMM
PC4
CS
SPI Clock
PC5
SCK
SPI Data OUT
PC7
MISO
SPI Data IN
PC6
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt 2
PB13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel&Qvar Click Schematic schematic

Step by step

Project assembly

Clicker 2 for PIC32MZ front image hardware assembly

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

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker 2 Access - 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

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