Intermediate
30 min

Achieve precise orientation and angular velocity in various scenarios using I3G4250 and MK20DX128VFM5

Steady as a gyroscope: Your path to stability

Gyro 3 Click with UNI-DS v8

Published Oct 05, 2023

Click board™

Gyro 3 Click

Dev.Board

UNI-DS v8

Compiler

NECTO Studio

MCU

MK20DX128VFM5

With a gyroscope, you can achieve responsive motion sensing capabilities, enabling devices to react to changes in orientation and movement quickly and accurately

A

A

Hardware Overview

How does it work?

Gyro 3 Click is based on the I3G4250, a three-axis digital gyroscope sensor IC from STMicroelectronics. This device is produced using a proprietary CMOS micromachining technology, which results in a high level of integration, allowing very good linearity over temperature, and increased output stability when no motion applied (referred to as a zero-rate level in the I3G4250 datasheet). It also makes it resistant to shocks, allowing it to be used for speeds up to 2000 dps. It supports signal conditioning including low and high-pass filtering, as well as the threshold detection on each axis. Typically, higher dps range results in lower sensitivity. Therefore, the I3G4250 allows to dynamically select the full-scale range (FSR) value in several discrete steps: ±245, ±500, and ±2000 dps. This allows optimized performance for a given usage scenario. For example, if used in applications with faster angle rates such as sports equipment monitoring (golf club or tennis racket), a higher FSR might be required, at a cost of lower sensitivity. A high-accuracy 16-bit A/D converter sampled the MEMS output voltage, allowing the output in 2’s complement format. As mentioned above, different FS ranges have different sensitivity per LSB. Therefore, raw output values of the sensor will have to be multiplied with the sensitivity to obtain the values in degrees per second (dps). These

values can be obtained from the I3G4250 datasheet, for every FS range, respectively. There are two filters available on the I3G4250 sensor: an external low-pass (LP) filter, and a digital high-pass (HP) filter with user-selectable cutoff frequency. Both of these signals can be digitally selected and applied to an angular speed measurement, allowing the developer to reduce the noise or fine-tune the sensitivity within a desired bandwidth. The I3G4250 device features a FIFO buffer, which in combination with a dedicated interrupt line, allows firmware optimizations while reducing the power consumption of the application as a result. The FIFO buffer has 32 slots, each 16-bit wide, used to store output values. The I3G4250 device can be configured to use the FIFO buffer in three different modes: Bypass mode, FIFO mode, and Stream mode. While the first mode allows the developer to read the values directly from the output registers, two other modes allow the utilization of the buffer. The FIFO mode will collect the data and stop collecting until its read (or reset), while the Streaming mode will continuously fill the buffer, discarding the oldest value. One of the two interrupt lines is labeled as DRDY/INT2 on the schematic, and it is routed to the mikroBUS™ AN pin (labeled as DI2). This line is used to report one of the programmable FIFO events: watermark level is reached, FIFO buffer is empty, and there is

an overrun event on the FIFO buffer (FIFO is full).  The pin can also be used to report when there is a new data available at the output after the conversion period (data ready). To find out which event exactly has occurred, the host MCU should read the status of the respective flag bits from the STATUS register. The second interrupt line is used to report when the programmed threshold is reached. It is possible to detect events which are above or below a programmable threshold, and trigger an interrupt on the INT1 pin, routed to the mikroBUS™ INT pin. By directing the I3G4250 device to wait for a built-in timer to expire, a false triggering can be prevented. To detect an interrupt source, the MCU can should read the status of the respective flag bits from the INT1_SRC register. Gyro 3 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 I3G4250 slave I2C address. The Click board™ should be interfaced only with MCUs that use logic levels of 3.3V.

Gyro 3 Click top side image
Gyro 3 Click bottom side image

Features overview

Development board

UNI-DS v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different STM32, Kinetis, TIVA, CEC, MSP, PIC, dsPIC, PIC32, and AVR MCUs regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over WiFi. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, UNI-DS v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the UNI-DS v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector. Communication options such as USB-UART, USB

HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. UNI-DS v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

UNI-DS v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

ARM Cortex-M4

MCU Memory (KB)

160

Silicon Vendor

NXP

Pin count

32

RAM (Bytes)

16384

Used MCU Pins

mikroBUS™ mapper

Interrupt / Data Ready
PD5
AN
NC
NC
RST
SPI Chip Select
PD7
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
PD4
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB0
SCL
I2C Data
PB1
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Gyro 3 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI-DS v8 as your development board.

Fusion for PIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
v8 SiBRAIN 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Gyro 3 Click driver.

Key functions:

  • gyro3_get_temp - This function reads value stored in temperature register (26h)

  • gyro3_get_fifo_data_level - This function reads data level value in FIFO register from FIFO SRC register (2Fh) and stores result in fifo_data_level

  • gyro3_get_axes - This function reads values from XYZ axes registers and converts them to degrees per second value

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 Gyro3 Click example
 * 
 * # Description
 * This example shows values of the 3 axis from the gyroscope module.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes I2C driver, basic device configuration, I2C interface, LOG interface and GPIO pins.
 * 
 * ## Application Task  
 * Checks if new data is available on all three axes, If yes then reads and logs their values.
 * 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "gyro3.h"

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

static gyro3_t gyro3;
static log_t logger;

static uint8_t status_register;
static float x_axis;
static float y_axis;
static float z_axis;

static const char degrees_celsius[ 3 ] = { ' ', 'C', 0 };
static const char degrees_per_second[ 7 ] = { ' ', 'd', 'e', 'g', '/', 's', 0 };

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

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

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

    gyro3_cfg_setup( &cfg );
    GYRO3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    gyro3_init( &gyro3, &cfg );
    gyro3_default_cfg( &gyro3 );
}

void application_task ( void )
{
    //  Task implementation.

    gyro3_get_status( &gyro3, &status_register );

    if ( ( status_register & GYRO3_ZYX_NEW_DATA_MASK ) == GYRO3_ZYX_NEW_DATA_MASK )
    {

        gyro3_get_axes( &gyro3, &x_axis, &y_axis, &z_axis, GYRO3_MEAS_RANGE_2000 );

        log_printf( &logger, "\r\nx_axis : %.2f %s\t", x_axis, degrees_per_second );
        log_printf( &logger, "y_axis : %.2f %s\t", y_axis, degrees_per_second );
        log_printf( &logger, "z_axis : %.2f %s\r\n", z_axis, degrees_per_second );
        
    }

    Delay_ms( 1500 );
}

void main ( void )
{
    application_init( );

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


// ------------------------------------------------------------------------ END

Additional Support

Resources