Intermediate
30 min

Experience the future of spatial awareness with BNO080 and STM32G071RB

The power of three!

Smart DOF Click with Nucleo 64 with STM32G071RB MCU

Published Oct 08, 2024

Click board™

Smart DOF Click

Dev. board

Nucleo 64 with STM32G071RB MCU

Compiler

NECTO Studio

MCU

STM32G071RB

Explore the convergence of three sensors on a single chip in our Smart DOF solution, empowering developers, engineers, and researchers to redefine motion sensing across a multitude of applications

A

A

Hardware Overview

How does it work?

Smart DOF Click is based on the BNO080, a System in Package (SiP) that integrates a triaxial accelerometer, triaxial gyroscope, magnetometer and a 32-bit ARM® Cortex®-M0+ MCU from Bosch Sensortec. The integrated MCU core runs the proprietary Hillcrest SH-2 firmware, which includes the support for the MotionEngine™ software and its sophisticated signal processing algorithms. Thanks to this, the SmartDOF can provide very accurate and precise 3D acceleration, magnetic, and angular velocity data, in real-time. The additional output modes include orientation outputs by combining data from various sensors. There are many different rotation vectors available on a top of other readings, including geomagnetic rotation vector (does not use the gyroscope sensor), game rotation vector (no magnetometer), etc. The datasheet of the BNO080 offers a full list of outputs, each with a detailed explanation. As a device built to be used primarily in smartphones, BNO080 brings events detection and classification system. Stability classification distinguishes among three stability classes: "on the table" (the device is at a fixed position), "stable" (held in hand but in a stationary manner), or at "motion" (the

device is in motion). Stability classification is not the only classification for this device. For more information, please refer to the datasheet of the BN080 SiP. The detection engine allows many different events to be detected and reported as an interrupt, including tap detector, step detector, step counter, shake detector, etc. Both classification and detection systems use configurable thresholds. More information about how to set them up can be found in the SH-2 Reference Manual. However, the mikroSDK compatible library offers a well-documented set of functions, for simplified firmware development. The BNO080 offers both static and dynamic calibration features, which allow for increased precision. Static calibration is applied to the output data for the properties which do not change over time, or with temperature (i.e cross-axis sensitivity, gain, sensor orientation in respect to the frame of reference…) Dynamic calibration is used for the parameters which vary over time or temperature (i.e. zero-rate offset, zero-g offse, and more). Besides the compensation parameters, the user is able to tare the device, using two tare modes: tare around all axes, or tare around the

z-axis. The result of a tare operation is applied wherever power is applied to the device. The tare value can be permanently stored with the Persist Tare function. The BNO080 will be started in the Bootloader mode. This mode allows updating the embedded firmware over the I2C interface. When this pin is pulled to a LOW logic level, the device will boot up in the Bootloader mode after the next restart. This pin is routed to the mikroBUS™ PWM pin and it is labeled as BT. The BNO080 datasheet describes the firmware update process in more details. The Click board™ uses the I2C interface to communicate with the host MCU. It has an SMD jumper labeled as ADD SEL, which can be used to select the slave I2C address. This allows more than one device on a single I2C bus. 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.

Smart DOF Click top side image
Smart DOF Click bottom side image

Features overview

Development board

Nucleo-64 with STM32G071RB MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32G071RB MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

128

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

36864

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 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 STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PC12
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Boot Enable
PC8
PWM
Interrupt
PC14
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB8
SCL
I2C Data
PB9
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Smart DOF Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-64 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 64 with STM32G071RB MCU as your development board.

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
LTE IoT 5 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 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
Clicker 4 for STM32F4 HA 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

Software Support

Library Description

This library contains API for Smart DOF Click driver.

Key functions:

  • smartdof_receive_packet - This function waits for INT pin to go LOW, receives 4 header bytes and than parses header bytes to get data length of entire packet and stores header bytes to header buffer

  • smartdof_get_feature_response - This function receives get feature response report bytes

  • smartdof_set_feature_command - This function sends set feature request report to device

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief SmartDof Click example
 * 
 * # Description
 * This Click integrates a triaxial accelerometer, triaxial gyroscope and magnetometer.
 * It can provide very accurate and precise 3D acceleration, magnetic, and angular velocity data, in real-time. 
 * 
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes I2C driver and Smart DOF device
 *  
 * ## Application Task  
 * Executes one of 'smartdof_xxx_task()' additional functions
 * 
 * *note:* 
 * <pre>
 * Additional Functions :
 * - accelerometer_task() - initializes accelerometer reports in 100000 micro second intervals, receives, parses and logs report data
 * - gyroscope_task() - initializes gyroscope calibrated reports in 100000 micro second intervals, receives, parses and logs report data
 * - magnetometer_task() - initializes magnetometer calibrated reports in 100000 micro second intervals, receives, parses and logs report data
 * </pre>
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "smartdof.h"

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

static smartdof_t smartdof;
static smartdof_rr_t smartdof_rr;
static smartdof_sfc_t smartdof_sfc;
static smartdof_pir_t smartdof_pir;
static log_t logger;

static uint8_t sensor_status;
static uint8_t aux_error_flag;
static uint8_t int_pin_flag;

static int16_t x_axis_i;
static int16_t y_axis_i;
static int16_t z_axis_i;
static float x_axis_f;
static float y_axis_f;
static float z_axis_f;

static uint8_t data_header[ 4 ];
static uint8_t data_buffer[ 300 ];
static uint16_t data_length;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

void check_sensor_status ( )
{
    switch ( sensor_status )
    {
        case 0 :
        {
            log_printf( &logger, "unreliable\r\n" );
            break;
        }
        case 1 :
        {
            log_printf( &logger, "low\r\n" );
            break;
        }
        case 2 :
        {
            log_printf( &logger, "medium\r\n" );
            break;
        }
        case 3 :
        {
            log_printf( &logger, "high\r\n" );
            break;
        }
        default :
        {
            break;
        }
    }
}

void accelerometer_task ( smartdof_t *ctx, smartdof_sfc_t *sfc )
{
    sfc->feature_report_id = SMARTDOF_FEAT_REP_ID_ACCEL;
    sfc->feature_flags = 0x00; 
    sfc->change_sensitivity = 0x0000;
    sfc->report_interval = 100000;
    sfc->batch_interval = 0; 
    sfc->sensor_specific_config = 0;
     
    smartdof_set_feature_command( ctx, sfc );
    Delay_ms ( 500 );
    aux_error_flag = smartdof_get_feature_response( ctx, sfc );
    if ( aux_error_flag != 0)
    {
        log_printf( &logger, "> Error setting feature\r\n" );
        for ( ; ; );
    }
    else
    {
        Delay_ms ( 10 );
    }

    for ( ; ; )
    {
        aux_error_flag = smartdof_receive_packet( ctx, 10000000 );
        if ( aux_error_flag == 0 )
        {
            smartdof_get_data( ctx, &data_header[ 0 ], &data_length, &data_buffer[ 0 ] );
            if ( ( data_buffer[ 0 ] == SMARTDOF_FEAT_REP_ID_BASE_TIMESTAMP ) && ( data_buffer[ 5 ] == SMARTDOF_FEAT_REP_ID_ACCEL ) )
            {
                sensor_status = data_buffer[ 7 ];
                
                x_axis_i = 0;
                y_axis_i = 0;
                z_axis_i = 0;
                x_axis_i |= data_buffer[ 10 ];
                x_axis_i <<= 8;
                x_axis_i |= data_buffer[ 9 ];
                y_axis_i |= data_buffer[ 12 ];
                y_axis_i <<= 8;
                y_axis_i |= data_buffer[ 11 ];
                z_axis_i |= data_buffer[ 14 ];
                z_axis_i <<= 8;
                z_axis_i |= data_buffer[ 13 ];
                x_axis_f = smartdof_q_point_to_float( x_axis_i, SMARTDOF_QPOINT_ACCEL );
                y_axis_f = smartdof_q_point_to_float( y_axis_i, SMARTDOF_QPOINT_ACCEL );
                z_axis_f = smartdof_q_point_to_float( z_axis_i, SMARTDOF_QPOINT_ACCEL );

                log_printf( &logger, "\r\n" );
                log_printf( &logger, "Sensor type     : accelerometer\r\n" );
                log_printf( &logger, "Sensor accuracy : " );

                check_sensor_status( );

                log_printf( &logger, "X-Axis : %.2f m/s^2\r\n", x_axis_f );
                log_printf( &logger, "Y-Axis : %.2f m/s^2\r\n", y_axis_f );
                log_printf( &logger, "Z-Axis : %.2f m/s^2\r\n", z_axis_f );
            }
        }
        Delay_ms ( 1 );
    }
}

void magnetometer_task ( smartdof_t *ctx, smartdof_sfc_t *sfc )
{
    sfc->feature_report_id      = SMARTDOF_FEAT_REP_ID_MAGNET;
    sfc->feature_flags          = 0x00; 
    sfc->change_sensitivity     = 0x0000;
    sfc->report_interval        = 100000;
    sfc->batch_interval         = 0; 
    sfc->sensor_specific_config = 0;
    smartdof_set_feature_command( ctx, sfc);
    Delay_ms ( 500 );
    aux_error_flag = smartdof_get_feature_response( &smartdof, &smartdof_sfc );
    if ( aux_error_flag != 0 )
    {
        log_printf( &logger, "> Error setting feature\r\n" );
        for ( ; ; );
    }
    else
    {
        Delay_ms ( 10 );
    }

    for ( ; ; )
    {
        aux_error_flag = smartdof_receive_packet( &smartdof, 10000000 );
        if ( aux_error_flag == 0 )
        {
            smartdof_get_data( ctx, &data_header[ 0 ], &data_length, &data_buffer[ 0 ] );
            if ( ( data_buffer[ 0 ] == SMARTDOF_FEAT_REP_ID_BASE_TIMESTAMP ) && ( data_buffer[ 5 ] == SMARTDOF_FEAT_REP_ID_MAGNET ) )
            {
                sensor_status = data_buffer[ 7 ];

                x_axis_i = 0;
                y_axis_i = 0;
                z_axis_i = 0;
                x_axis_i |= data_buffer[ 10 ];
                x_axis_i <<= 8;
                x_axis_i |= data_buffer[ 9 ];
                y_axis_i |= data_buffer[ 12 ];
                y_axis_i <<= 8;
                y_axis_i |= data_buffer[ 11 ];
                z_axis_i |= data_buffer[ 14 ];
                z_axis_i <<= 8;
                z_axis_i |= data_buffer[ 13 ];
                x_axis_f = smartdof_q_point_to_float( x_axis_i, SMARTDOF_QPOINT_MAGNET_CALIB );
                y_axis_f = smartdof_q_point_to_float( y_axis_i, SMARTDOF_QPOINT_MAGNET_CALIB );
                z_axis_f = smartdof_q_point_to_float( z_axis_i, SMARTDOF_QPOINT_MAGNET_CALIB );

                log_printf( &logger, "Sensor type     : magnetometer\r\n" );
                log_printf( &logger, "Sensor accuracy : " );

                check_sensor_status( );

                log_printf( &logger, "X-Axis : %.2f uTesla\r\n", x_axis_f );
                log_printf( &logger, "Y-Axis : %.2f uTesla\r\n", y_axis_f );
                log_printf( &logger, "Z-Axis : %.2f uTesla\r\n", z_axis_f );
            }
        }
        Delay_ms ( 1 );
    }
}

void gyroscope_task ( smartdof_t *ctx, smartdof_sfc_t *sfc )
{
    sfc->feature_report_id      = SMARTDOF_FEAT_REP_ID_GYRO;
    sfc->feature_flags          = 0x00; 
    sfc->change_sensitivity     = 0x0000;
    sfc->report_interval        = 100000;
    sfc->batch_interval         = 0; 
    sfc->sensor_specific_config = 0;
    smartdof_set_feature_command( ctx, sfc );
    Delay_ms ( 500 );
    aux_error_flag = smartdof_get_feature_response( ctx, sfc );
    if ( aux_error_flag != 0)
    {
        log_printf( &logger, "> Error setting feature\r\n" );
        for ( ; ; );
    }
    else
    {
        Delay_ms ( 10 );
    }

    for ( ; ; )
    {
        aux_error_flag = smartdof_receive_packet( &smartdof, 10000000 );
        if ( aux_error_flag == 0 )
        {
            smartdof_get_data( ctx, &data_header[ 0 ], &data_length, &data_buffer[ 0 ] );
            if ( ( data_buffer[ 0 ] == SMARTDOF_FEAT_REP_ID_BASE_TIMESTAMP ) && ( data_buffer[ 5 ] == SMARTDOF_FEAT_REP_ID_GYRO ) )
            {
                sensor_status = data_buffer[ 7 ];

                x_axis_i = 0;
                y_axis_i = 0;
                z_axis_i = 0;
                x_axis_i |= data_buffer[ 10 ];
                x_axis_i <<= 8;
                x_axis_i |= data_buffer[ 9 ];
                y_axis_i |= data_buffer[ 12 ];
                y_axis_i <<= 8;
                y_axis_i |= data_buffer[ 11 ];
                z_axis_i |= data_buffer[ 14 ];
                z_axis_i <<= 8;
                z_axis_i |= data_buffer[ 13 ];
                x_axis_f = smartdof_q_point_to_float( x_axis_i, SMARTDOF_QPOINT_GYRO_CALIB );
                y_axis_f = smartdof_q_point_to_float( y_axis_i, SMARTDOF_QPOINT_GYRO_CALIB );
                z_axis_f = smartdof_q_point_to_float( z_axis_i, SMARTDOF_QPOINT_GYRO_CALIB );

                log_printf( &logger, " \r\n" );
                log_printf( &logger, "Sensor type     : gyroscope\r\n" );
                log_printf( &logger, "Sensor accuracy : " );

                check_sensor_status( );

                log_printf( &logger, "X-Axis : %f rad/s\r\n", x_axis_f );
                log_printf( &logger, "Y-Axis : %f rad/s\r\n", y_axis_f );
                log_printf( &logger, "Z-Axis : %f rad/s\r\n", z_axis_f );
            }
        }
        Delay_ms ( 1 );
    }
}

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

void application_init ( void )
{
    uint8_t p;
    log_cfg_t log_cfg;
    smartdof_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.

    smartdof_cfg_setup( &cfg );
    SMARTDOF_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    smartdof_init( &smartdof, &cfg );

    if ( smartdof_default_cfg ( &smartdof ) !=0 )
    {
        log_info( &logger, "Error during default configuration" );
    }
}

void application_task ( void )
{
    magnetometer_task( &smartdof, &smartdof_sfc );
    //accelerometer_task( &smartdof, &smartdof_sfc );
    //gyroscope_task( &smartdof, &smartdof_sfc );  
}

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

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.