smartsens  2.0.0.0
Main Page

Smart Sens click

Smart Sens Click is a compact add-on board that contains an intelligent sensor hub with an integrated IMU sensor. This board utilizes the BHI260 and BMM150, an environmental sensor and magnetometer from Bosch Sensortech. The BHI260 includes a programmable and powerful 32-bit MCU, a 6-axis IMU, and a robust software framework. In addition to its internal functions, it also performs signal data processing from the BMM150 that performs measurements of the magnetic field in three perpendicular axes.

click Product page


Click library

  • Author : Luka Filipovic
  • Date : Oct 2021.
  • Type : I2C/SPI type

Software Support

We provide a library for the Smart Sens Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for Smart Sens Click driver.

Standard key functions :

Example key functions :

Example Description

This example showcases the ability of the Smart Sens click board.

It has multiple examples that you can easily select with the defines at top of the main. There are 5 examples Euler, Quaternion, and Vector examples for Accelerometer, Gyroscope, and Magnetometer.

The demo application is composed of two sections :

Application Init

Initialization of communication modules(SPI/I2C, UART) and additional

pins(int_pin, rst). Then after going through reset sequence and checking device and product IDs, interrupt mask, and host control is set to 0, so every interrupt enabled. IF boot status is OK boot sequence is initiated, depending on the defines from the library header it will use RAM or Flash type of the boot. If RAM is selected firmware image first needs to be uploaded to RAM and then it will be booted. If Flash example is selected it will try to boot firmware first if it fails it will then write firmware image to flash and then try to boot it again. When firmware boot is finished Kernel version and Feature registers will be read to check if the firmware is loaded. Then all the callback function will be registered(meta event callback and whatever type of example parser you set), and driver will update its the list of virtual sensors present, and finally will configure virtual sensor that will be used in the selected example.

void application_init ( void )
{
log_cfg_t log_cfg;
smartsens_cfg_t smartsens_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
smartsens_cfg_setup( &smartsens_cfg );
SMARTSENS_MAP_MIKROBUS( smartsens_cfg, MIKROBUS_1 );
err_t init_flag = smartsens_init( &smartsens, &smartsens_cfg );
if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
/* It can take a few seconds to configure and boot device*/
log_info( &logger, " Configuring device..." );
if ( SMARTSENS_ERROR == smartsens_default_cfg ( &smartsens ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Setting callbacks..." );
/*Set callbacks*/
parse_meta_event, (void*)&accuracy ) )
{
log_error( &logger, " FIFO sys meta event." );
for( ; ; );
}
parse_meta_event, ( void* )&accuracy ) )
{
log_error( &logger, " FIFO sys meta event wu." );
for( ; ; );
}
#if EULAR
parse_euler, ( void* )&accuracy ) )
#elif QUATERNION
parse_quaternion, NULL ) )
#elif VECTOR
#if ACCELEROMETER
parse_3axis_s16, &parse_table ) )
#elif GYROSCOPE
parse_3axis_s16, &parse_table ) )
#elif MAGNOMETER
parse_3axis_s16, &parse_table ) )
#else
#error NO_VECTOR_EXAMPLE_DEFINED
#endif
#else
#error NO_EXAMPLE_DEFINED
#endif
{
log_error( &logger, " FIFO sensor id." );
for( ; ; );
}
/*Go through fifo process*/
{
log_error( &logger, " FIFO get and process." );
for( ; ; );
}
/*Update virtual sensor list in context object*/
{
log_error( &logger, " Update virtual sensor list." );
for( ; ; );
}
/*Set virtual sensor configuration*/
float sample_rate = 100.0; /* Read out data measured at 100Hz */
uint32_t report_latency_ms = 0; /* Report immediately */
#if EULAR
sample_rate, report_latency_ms ) )
#elif QUATERNION
sample_rate, report_latency_ms ) )
#elif VECTOR
#if ACCELEROMETER
sample_rate, report_latency_ms ) )
#elif GYROSCOPE
sample_rate, report_latency_ms ) )
#elif MAGNOMETER
sample_rate, report_latency_ms ) )
#else
#error NO_VECTOR_EXAMPLE_DEFINED
#endif
#else
#error NO_EXAMPLE_DEFINED
#endif
{
log_error( &logger, " Set virtual sensor configuration." );
for( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Wait for an interrupt to occur. When occurred read wake-up, non-weak-up, and status FIFO.

Parse received that and run the callback parsers to show received data.

void application_task ( void )
{
/*Check interrupt and get and process fifo buffer*/
if ( smartsens_get_interrupt( &smartsens ) )
{
/* Data from the FIFO is read and the relevant callbacks if registered are called */
{
log_error( &logger, " Get and process fifo." );
for( ; ; );
}
}
}

Note

You need to select one of the examples to use this application. You can choose one of 3

type of parsers: Eular, Quaternion, Vector. If Vector example is selected you need to choose one of the 3 sensors to show x,y,z values: Accelerometer, Gyroscope, or Magnetometer.

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.SmartSens

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


smartsens_register_fifo_parse_callback
err_t smartsens_register_fifo_parse_callback(smartsens_t *ctx, uint8_t sensor_id, smartsens_fifo_parse_callback_t callback, void *callback_ref)
Link a callback to virtual sensor.
cmd
uint16_t cmd
Definition: main.c:64
parse_ref::scaling_factor
float scaling_factor
Definition: main.c:155
parse_ref::sensor
struct parse_ref::@0 sensor[SMARTSENS_SENSOR_ID_MAX]
SMARTSENS_SENSOR_ID_ACC
#define SMARTSENS_SENSOR_ID_ACC
Definition: smartsens.h:185
smartsens_power_on_device
err_t smartsens_power_on_device(smartsens_t *ctx)
Power on device boot/upload firmware to device.
smartsens_cfg_t
Smart Sens Click configuration object.
Definition: smartsens.h:586
smartsens_s
Smart Sens Click context object.
Definition: smartsens.h:561
work_buffer
uint8_t work_buffer[WORK_BUFFER_SIZE]
Definition: main.c:62
SMARTSENS_SET_DATA_SAMPLE_EDGE
#define SMARTSENS_SET_DATA_SAMPLE_EDGE
Data sample selection.
Definition: smartsens.h:407
SMARTSENS_SYS_ID_META_EVENT_WU
#define SMARTSENS_SYS_ID_META_EVENT_WU
Definition: smartsens.h:262
application_task
void application_task(void)
Definition: main.c:348
SMARTSENS_SENSOR_ID_GYRO
#define SMARTSENS_SENSOR_ID_GYRO
Definition: smartsens.h:191
smartsens_update_virtual_sensor_list
err_t smartsens_update_virtual_sensor_list(smartsens_t *ctx)
Update the callback table's information.
smartsens_default_cfg
err_t smartsens_default_cfg(smartsens_t *ctx)
Smart Sens default configuration function.
SMARTSENS_SENSOR_ID_ORI_WU
#define SMARTSENS_SENSOR_ID_ORI_WU
Definition: smartsens.h:212
smartsens_get_parameter
err_t smartsens_get_parameter(smartsens_t *ctx, uint16_t parameter, uint8_t *parameter_buf, uint16_t *parameter_len)
Get command parameters resposne.
smartsens_get_and_process_fifo
err_t smartsens_get_and_process_fifo(smartsens_t *ctx, uint8_t *work_buffer, uint32_t buffer_size)
Get and process the FIFO.
accuracy
uint8_t accuracy
Definition: main.c:191
parse_table
struct parse_ref parse_table
Definition: main.c:160
smartsens_set_virt_sensor_cfg
err_t smartsens_set_virt_sensor_cfg(smartsens_t *ctx, uint8_t sensor_id, float sample_rate, uint32_t latency)
Set configuration fro virtual sensor.
smartsens_get_interrupt
uint8_t smartsens_get_interrupt(smartsens_t *ctx)
Get interrupt.
SMARTSENS_SENSOR_ID_RV_WU
#define SMARTSENS_SENSOR_ID_RV_WU
Definition: smartsens.h:206
application_init
void application_init(void)
Definition: main.c:223
SMARTSENS_SENSOR_ID_MAG
#define SMARTSENS_SENSOR_ID_MAG
Definition: smartsens.h:197
smartsens_cfg_setup
void smartsens_cfg_setup(smartsens_cfg_t *cfg)
Smart Sens configuration object setup function.
smartsens_cmd_write
err_t smartsens_cmd_write(smartsens_t *ctx, uint16_t cmd, uint8_t *cmd_buf, uint16_t cmd_len)
Send command.
SMARTSENS_ERROR
@ SMARTSENS_ERROR
Definition: smartsens.h:614
smartsens_init
err_t smartsens_init(smartsens_t *ctx, smartsens_cfg_t *cfg)
Smart Sens initialization function.
SMARTSENS_MAP_MIKROBUS
#define SMARTSENS_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: smartsens.h:426
SMARTSENS_SYS_ID_META_EVENT
#define SMARTSENS_SYS_ID_META_EVENT
Definition: smartsens.h:258
WORK_BUFFER_SIZE
#define WORK_BUFFER_SIZE
Definition: main.c:61