Beginner
10 min

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

Precise acceleration measurement and electric charge variation detection

Accel&Qvar Click with Curiosity Nano with PIC18F57Q43

Published Apr 30, 2024

Click board™

Accel&Qvar Click

Dev.Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

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

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Interrupt 1
PA0
AN
ID SEL
PA7
RST
SPI Select / ID COMM
PD4
CS
SPI Clock
PC6
SCK
SPI Data OUT
PC5
MISO
SPI Data IN
PC4
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt 2
PA6
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB1
SCL
I2C Data
PB2
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel&Qvar Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX 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
PIC18F57Q43 Curiosity 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