Intermediate
30 min

Enable precise activity tracking and intuitive gesture control using IIS2DLPC and ATmega328

Get in the groove: Your 3-axis accelero-friend!

Accel 13 Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

Accel 13 Click

Dev Board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328

Enhance the accuracy of your navigation systems and robotics projects by integrating our three-axis accelerometer, offering real-time motion data for improved control

A

A

Hardware Overview

How does it work?

Accel 13 Click is based on the IIS2DLPC, a high-performance ultra-low-power 3-axis accelerometer for industrial applications, from STMicroelectronics. This sensor has many features perfectly suited for wearables, handheld, and IoT applications, offering a good balance between the performance and the power consumption. One of its key features is its extremely low power consumption, which makes it perfectly suited for such applications. There are several power modes which the IIS2DLPC device can use. While in Low Power mode, the device consumes the least power, but the access to some features is restricted. More information can be found within the IIS2DLPC datasheet. The IIS2DLPC sensor can measure acceleration within ranges of ±2 g, ±4 g, ±8, and ±16 g. It can output the measurement data using the Output Data Rate (ODR) from 1.6Hz (Low Power mode), up to 1600Hz (Performance mode). A high-precision analog front end facilitates highly sensitive MEMS, featuring a 14-bit A/D Converter. It allows very high accuracy of the output, even during very low amplitude changes. This makes the sensor particularly sensitive and accurate

with movements that generate relatively low acceleration signals. However, using a highly sensitive MEMS makes the IIS2DLPC prone to damage caused by extremely high g-forces (10,000 g for less than 200 µs). Acceleration data is available in 14-bit format from both the data registers and the internal FIFO buffe, which can can memorize 32 slots of X, Y and Z data. The FIFO buffer can be used for more complex calculations or timed readings, reducing the traffic on the communication interface. The interrupt engine facilitates the FIFO buffer, triggering an interrupt for two FIFO events: watermark event, and FIFO buffer full event. FIFO buffer allows optimization within the firmware that runs on the host MCU. Besides the acceleration MEMS and complementary analog front-end circuit, the IIS2DLPC sensor also has an integrated temperature sensor. It is updated up to 25 times per second, and sampled to an 12-bit value (complement of 2’s format). Interrupts can be triggered for many different events. Some basic events include the data-ready interrupt event and aforementioned FIFO events, while so-called

feature engines can trigger an interrupt for any of the detected motion/movement events, including step detection/counter, activity recognition, tilt on wrist, tap/double tap, any/no motion, and error event interrupt. The extensive interrupt engine can use two programmable interrupt pins. Both of these pins can be assigned with any interrupt source and can be either LOW or HIGH on interrupt, depending on settings in appropriate registers. These two pins are routed to PWM and INT pin of the mikroBUS™, and are labeled as IT1 and IT2, respectively. Accel 13 click offers two communication interfaces. It can be used with either I2C or SPI. The onboard SMD jumpers labeled as COMM SEL allow switching between the two interfaces. Note that all the jumpers have to be positioned either I2C or to SPI position. When I2C interface is selected, an additional SMD jumper labeled as ADDR SEL becomes available, determining the least significant bit of the IIS2DLPC I2C address. The Click board™ should be interfaced only with MCUs that use logic levels of 3.3V.

Accel 13 Click top side image
Accel 13 Click bottom side image

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

32

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
SPI Chip Select
PB2
CS
SPI Clock
PB5
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Interrupt 1
PD6
PWM
Interrupt 2
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel 13 Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Barometer 13 Click front image hardware assembly
Prog-cut hardware assembly
Arduino UNO Rev3 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
Arduino UNO 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 13 Click driver.

Key functions:

  • accel13_get_status - This function reads the status data and stores it in the status object

  • accel13_get_tap_status - This function reads the tap status data and stores it in the tap_status object

  • accel13_get_6d_status - This function reads the 6D status data and stores it in the sixd_status object

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 
 * \brief Accel13 Click example
 * 
 * # Description
 * This application enables reading acceleration and tapping data on all 3 axes,
 * using I2C or SPI communication.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver init, Test communication, 
 * starts chip configuration for measurement and Temperature reads.
 * 
 * ## Application Task  
 * Reads Accelerometer data and detects tap on the axis
 * 
 * *note:* 
 * The example is the basic functionality of the IIS2DLPC sensor, 
 * it is possible to read the acceleration data and detect Tap on all 3 axes.
 * For other settings and improvements in reading accuracy, 
 * you need to further set up the registers and set the sensor to your conditions.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "accel13.h"

// ------------------------------------------------------------------ VARIABLES

static accel13_t accel13;
static log_t logger;
static accel13_axis_t axis;
static accel13_tap_t tap;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    accel13_cfg_t cfg;
    uint8_t device_id;
    float temperature;

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

    accel13_cfg_setup( &cfg );
    ACCEL13_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    accel13_init( &accel13, &cfg );

    accel13_generic_read_bytes( &accel13, ACCEL13_REG_WHO_AM_I, &device_id, 1 );

    if ( device_id != ACCEL13_DEF_WHO_AM_I )
    {
        log_printf( &logger, "*\\*/*\\*/ Communication ERROR !!! \\*/*\\*/*" );
        for ( ; ; );
    }
    log_printf( &logger, "---- Communication OK!!! ----\r\n" );
    Delay_100ms( );

    // Configuration

    accel13_default_cfg ( &accel13 );

    accel13_generic_write_single_byte( &accel13, ACCEL13_REG_CTRL_6, ACCEL13_CTRL6_BW_FILT_ODR_2 |
                                                                     ACCEL13_CTRL6_FULL_SCALE_2g |
                                                                     ACCEL13_CTRL6_FDS_LOW_PASS |
                                                                     ACCEL13_CTRL6_LOW_NOISE_ENABLE );

    // Temperature

    temperature = accel13_get_temperature( &accel13 );
    log_printf( &logger, " Temperature : %f.2 \r\n", temperature);
}

void application_task ( void )
{

    // Reads Accel data
    
    accel13_get_axis_data( &accel13, &axis );

    log_printf( &logger, "---- Accel axis data ----\r\n\n" );
    
    log_printf( &logger, "* X : %d \r\n", axis.x );
   
    log_printf( &logger, "* Y : %d \r\n", axis.y);

    log_printf( &logger, "* Z : %d \r\n", axis.z);
    log_printf( &logger, "-------------------------\r\n" );
    Delay_ms( 300 );
    
    // Detections Tap on the axis
    
    accel13_get_tap_status( &accel13, &tap );

    if ( tap.tap_x == 0x01 )
    {
        log_printf( &logger, "---- Tap on the X axis ----\r\n" );
    }

    if ( tap.tap_y == 0x01 )
    {
        log_printf( &logger, "---- Tap on the Y axis ----\r\n" );
    }

    if ( tap.tap_z == 0x01 )
    {
        log_printf( &logger, "---- Tap on the Z axis ----\r\n" );
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


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