smartdof4  2.1.0.0
Main Page

Smart DOF 4 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : Aug 2024.
  • Type : I2C/SPI type

Software Support

We provide a library for the Smart DOF 4 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 DOF 4 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of Smart DOF 4 click board by reading the accelerometer, gyroscope, and magnetometer data measurements.

The demo application is composed of two sections :

Application Init

Initializes the driver and performs the click default configuration enabling

accelerometer, gyroscope, and magnetometer sensors with an output data rate of 10Hz. After that, it reads the software version, part number, and build number information.

void application_init ( void )
{
log_cfg_t log_cfg;
smartdof4_cfg_t smartdof4_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
smartdof4_cfg_setup( &smartdof4_cfg );
SMARTDOF4_MAP_MIKROBUS( smartdof4_cfg, MIKROBUS_1 );
err_t init_flag = smartdof4_init( &smartdof4, &smartdof4_cfg );
if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( SMARTDOF4_ERROR == smartdof4_default_cfg ( &smartdof4 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
if ( SMARTDOF4_OK == smartdof4_read_pid ( &smartdof4, &pid ) )
{
log_printf ( &logger, " SW Version: %u.%u.%u\r\n", ( uint16_t ) pid.sw_ver_major,
( uint16_t ) pid.sw_ver_minor,
( uint16_t ) pid.sw_ver_patch );
log_printf ( &logger, " SW Part Number: %lu\r\n", pid.sw_part_num );
log_printf ( &logger, " SW Build Number: %lu\r\n\n", pid.sw_build_num );
}
log_info( &logger, " Application Task " );
}

Application Task

Reads the accelerometer (g), gyroscope (dps), and magnetometer (uT) measurements and displays results on the USB UART every 100ms approximately.

void application_task ( void )
{
static smartdof4_axis_t accel, gyro, mag;
if ( SMARTDOF4_OK == smartdof4_read_data ( &smartdof4, &accel, &gyro, &mag ) )
{
log_printf ( &logger, " Accel X: %.3f g\r\n", accel.x );
log_printf ( &logger, " Accel Y: %.3f g\r\n", accel.y );
log_printf ( &logger, " Accel Z: %.3f g\r\n", accel.z );
log_printf ( &logger, " Gyro X: %.1f dps\r\n", gyro.x );
log_printf ( &logger, " Gyro Y: %.1f dps\r\n", gyro.y );
log_printf ( &logger, " Gyro Z: %.1f dps\r\n", gyro.z );
log_printf ( &logger, " Mag X: %.1f uT\r\n", mag.x );
log_printf ( &logger, " Mag Y: %.1f uT\r\n", mag.y );
log_printf ( &logger, " Mag Z: %.1f uT\r\n\n", mag.z );
Delay_ms ( 100 );
}
}

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

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.


SMARTDOF4_ERROR
@ SMARTDOF4_ERROR
Definition: smartdof4.h:481
smartdof4_axis_t::z
float z
Definition: smartdof4.h:455
smartdof4_cfg_setup
void smartdof4_cfg_setup(smartdof4_cfg_t *cfg)
Smart DOF 4 configuration object setup function.
smartdof4_default_cfg
err_t smartdof4_default_cfg(smartdof4_t *ctx)
Smart DOF 4 default configuration function.
smartdof4_axis_t
Smart DOF 4 Click data axis object.
Definition: smartdof4.h:452
smartdof4_feature_t
Smart DOF 4 Click sensor feature object.
Definition: smartdof4.h:437
smartdof4_axis_t::y
float y
Definition: smartdof4.h:454
smartdof4_init
err_t smartdof4_init(smartdof4_t *ctx, smartdof4_cfg_t *cfg)
Smart DOF 4 initialization function.
application_task
void application_task(void)
Definition: main.c:78
SMARTDOF4_MAP_MIKROBUS
#define SMARTDOF4_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: smartdof4.h:343
smartdof4_s
Smart DOF 4 Click context object.
Definition: smartdof4.h:386
smartdof4_cfg_t
Smart DOF 4 Click configuration object.
Definition: smartdof4.h:410
SMARTDOF4_OK
@ SMARTDOF4_OK
Definition: smartdof4.h:480
smartdof4_pid_t::sw_build_num
uint32_t sw_build_num
Definition: smartdof4.h:469
smartdof4_pid_t::sw_ver_major
uint8_t sw_ver_major
Definition: smartdof4.h:466
application_init
void application_init(void)
Definition: main.c:31
smartdof4_pid_t::sw_ver_minor
uint8_t sw_ver_minor
Definition: smartdof4.h:467
smartdof4_read_data
err_t smartdof4_read_data(smartdof4_t *ctx, smartdof4_axis_t *accel, smartdof4_axis_t *gyro, smartdof4_axis_t *mag)
Smart DOF 4 read data function.
smartdof4_read_pid
err_t smartdof4_read_pid(smartdof4_t *ctx, smartdof4_pid_t *pid)
Smart DOF 4 read pid function.
smartdof4_pid_t
Smart DOF 4 Click product ID object.
Definition: smartdof4.h:464
smartdof4_pid_t::sw_part_num
uint32_t sw_part_num
Definition: smartdof4.h:468
smartdof4_axis_t::x
float x
Definition: smartdof4.h:453
smartdof4_pid_t::sw_ver_patch
uint16_t sw_ver_patch
Definition: smartdof4.h:470
smartdof4_feature_set
err_t smartdof4_feature_set(smartdof4_t *ctx, smartdof4_feature_t *feat)
Smart DOF 4 feature set function.