Intermediate
30 min

Detect impacts and sudden changes in motion with MPU6050 and MK22FN512VLH12

Accelerometer: Small device, big impact

Accel 8 Click with Kinetis Clicker

Published Oct 05, 2023

Click board™

Accel 8 Click

Dev Board

Kinetis Clicker

Compiler

NECTO Studio

MCU

MK22FN512VLH12

Measure acceleration forces and achieve precise monitoring of an object's movement and its changes in velocity over time

A

A

Hardware Overview

How does it work?

Accel 8 Click is based on the MPU6050, a motion tracking sensor IC, from TDK Invensense. It is an advanced, integrated microelectromechanical gyroscope and accelerometer sensor (MEMS), combined with the powerful data processing engine. There is a respective accelerometer or gyroscope MEMS on each axis. The output of each MEMS is processed and digitized by a separate sigma-delta 16-bit A/D converter (ADC). The outputs can be processed by a programmable low-pass filter, while their sample rate can be selected by the user. Three-axis gyroscope MEMS can be programmed to measure the rotation about each axis, in four different ranges of rotational speed (degrees per angle, DPS): ±250, ±500, ±1000, and ±2000. Three-axis accelerometer MEMS can be programmed to measure the acceleration along each axis, in four different acceleration ranges: ±2g, ±4g, ±8g, and ±16g. The user can select an optimal range for both properties, depending on the application requirements. The embedded Digital Motion Processor™ can process complex 6-axis motion detection and gesture recognition algorithms without taking up processing cycles of the host microcontroller (MCU), making it perfectly suited

for different kinds of low-power applications. The DMP engine offers a high output data rate (ODR), improving measurement accuracy. Due to DMP hardware-accelerated motion detection algorithms, MPU60x0 are very popular motion tracking ICs and there are many different designs using both MPU6050 and MPU6000 (e.g. MPU IMU click). Unlike the MPU6000, the MPU6050 uses the I2C communication interface. MPU6050 incorporates a powerful programmable interrupt engine. The interrupt engine can generate a signal on the interrupt pin for several interrupt sources, including FIFO Buffer overflow, Data Ready, I2C Master Error, and I2C Slave Error. The interrupt is routed to the INT pin of the mikroBUS™. A FIFO buffer helps to further reduce the processing load, offering temporary storage for the output data. The MPU6050 features a FIFO buffer with the capacity of 1024 bytes. The user can select which data will be stored in the FIFO buffer: gyro data, accel data, temperature readings, and auxiliary sensor readings. Once the FIFO buffer is full, it will start discarding the oldest data, allowing new data to be written. The FIFO buffer overflow condition can be used to trigger an interrupt, alerting the host MCU about its status. Another powerful

feature of the MPU6050 is its ability to be interfaced with an additional sensor, such as the 3-axis compass. By utilizing the MotionFusion™ firmware on the chip, along with the run-time calibration, it offers the complete 9-axis motion sensing solution. This sensor can be connected to the auxiliary I2C pins, routed to the mikroBUS™. Aux I2C clock pin is routed to the RST pin of the mikroBUS™ and it is labeled as CL, while the Aux I2C data pin is routed to the AN pin of the mikroBUS™, labeled as DA. Besides the compass sensor, other general-purpose sensors that use I2C interface can be connected, too. An interrupt can be generated if there is an error in the communication between the MPU6050 and the auxiliary sensor. The I2C address of the MPU6050 can be selected by the ADD SEL jumper. This SMD jumper is used to select the least significant bit (LSB) of the 7-bit I2C address. The value of the LSB is decided by the position of this jumper. Accel 8 click uses the I2C communication interface. It has pull-up resistors connected to the mikroBUS™ 3.3V rail. Proper conversion of logic voltage levels should be applied before the Click board™ is used with MCUs operated with 5V.

Accel 8 Click top side image
Accel 8 Click bottom side image

Features overview

Development board

Kinetis Clicker 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-M4 microcontroller, the MK22FN512VLH12 from NXP Semiconductor, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access

anywhere and under any circumstances. Each part of the Kinetis Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Kinetis Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for Kinetis programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB-MiniAB connection provides up to 500mA of current, which is more than enough to operate all

onboard and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. Kinetis Clicker 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.

Kinetis Clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

512

Silicon Vendor

NXP

Pin count

64

RAM (Bytes)

131072

Used MCU Pins

mikroBUS™ mapper

Auxiliary I2C Data
PTB2
AN
Auxiliary I2C Clock
PTB3
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PTD0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PTB0
SCL
I2C Data
PTB1
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel 8 Click Schematic schematic

Step by step

Project assembly

Kinetis Clicker front image hardware assembly

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

Kinetis Clicker front image hardware assembly
Thermo 28 Click front image hardware assembly
Prog-cut hardware assembly
Kinetis Mini B Connector clicker - 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
Kinetis 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

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 8 Click driver.

Key functions:

  • accel8_get_accel_axis - This function reads Accel axis data

  • accel8_get_gyro_axis - This function reads Gyro axis data

  • accel8_get_interrupt - This function returns Interupt state

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 Accel8 Click example
 * 
 * # Description
 * This application measures accelermeter and gyroscopic data and temperature.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initialization driver init, reset chip and start configuration chip for measurement.
 * 
 * ## Application Task  
 * Reads Accel X/Y/Z axis, Gyro X/Y/Z axis and device Temperature. 
 * All data logs on the USBUART every 2 sec.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "accel8.h"

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

static accel8_t accel8;
static log_t logger;
static range_retval_t range;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    accel8_cfg_t cfg;

    uint8_t temp_write;

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

    accel8_cfg_setup( &cfg );
    ACCEL8_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    temp_write = accel8_init( &accel8, &cfg );
	
	if ( temp_write ==  ACCEL8_INIT_ERROR )
	{
		log_info( &logger, "ERROR\r\n" );
		for ( ; ; );
	}

    log_printf( &logger, " *-* Device Reset *-* \r\n");
    temp_write = ACCEL8_PM1_DEVICE_RESET;
    accel8_generic_write( &accel8, ACCEL8_REG_PWR_MGMT_1, &temp_write, 1 );
    Delay_ms( 500 );
    temp_write = ACCEL8_GYRO_RESET | ACCEL8_ACCEL_RESET | ACCEL8_TEMP_RESET;
    accel8_generic_write( &accel8, ACCEL8_REG_SIGNAL_PATH_RESET, &temp_write, 1 );
	Delay_ms( 500 );
    log_printf( &logger, " *-* Device Configuration *-* \r\n" );
    accel8_default_cfg ( &accel8, ACCEL8_ACCEL_CFG_FULL_SCALE_RANGE_2g, ACCEL8_GYRO_CFG_FULL_SCALE_RANGE_250dbs, &range);

    Delay_ms( 1000 );
    log_printf( &logger, " --- Start Measurement --- \r\n" );Delay_ms( 100 );
}

void application_task ( void )
{   
    float temperature;
    int16_t x_gyro_axis;
    int16_t y_gyro_axis;
    int16_t z_gyro_axis;
    int16_t x_accel_axis;
    int16_t y_accel_axis;
    int16_t z_accel_axis;

    //  Task implementation.

    accel8_get_accel_axis( &accel8,&x_accel_axis, &y_accel_axis, &z_accel_axis );
    accel8_get_gyro_axis( &accel8, &x_gyro_axis, &y_gyro_axis , &z_gyro_axis );
    temperature = accel8_get_temperature( &accel8 );
    
    // LOGS DATA

    log_printf( &logger, "________________ Accel 8 click _________\r\n" );
    log_printf( &logger, "|  Data   | X axis | Y axis | Z axis |  Range  |\r\n" );
    log_printf( &logger, "|______|______|______|_____|________|\r\n" );
    log_printf( &logger, "|  Accel  | %d    | %d    | %d    | %dg    |\r\n", x_accel_axis, y_accel_axis, z_accel_axis, &range.accel_range );
    log_printf( &logger, "|_______|______|_____|_______|_______|\r\n" );
    log_printf( &logger, "|  Gyro    | %d     | %d     | %d     | %ddps   |\r\n", x_gyro_axis, y_gyro_axis, z_gyro_axis, &range.gyro_range );
    log_printf( &logger, "|_______|_______|______|______|________|\r\n" );
    log_printf( &logger, "|  Temp   | %.2f  C         |\r\n" , temperature);
    log_printf( &logger, "|_______|____________|\r\n" );

    log_printf( &logger, " \r\n" );
    Delay_ms( 2000 );
}

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.