smartsens2 2.2.0
Loading...
Searching...
No Matches
smartsens2


Smart Sens 2 Click

Smart Sens 2 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Jan 2022.
  • Type : I2C/SPI type

Software Support

Example Description

This example showcases the ability of the Smart Sens 2 Click board. It has multiple examples that you can easily select with the defines at the top of the main. There are 9 examples: Euler, Quaternion, Vector (Accelerometer, Gyroscope, Magnetometer), and Environmental (Temperature, Barometer, Humidity, Gas).

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.SmartSens2

Example Key Functions

Application Init

Initialization of communication modules (SPI/I2C) and additional pins(int_pin, rst). After that 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 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;
smartsens2_cfg_t smartsens2_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
smartsens2_cfg_setup( &smartsens2_cfg );
SMARTSENS2_MAP_MIKROBUS( smartsens2_cfg, MIKROBUS_1 );
err_t init_flag = smartsens2_init( &smartsens2, &smartsens2_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 ( SMARTSENS2_ERROR == smartsens2_default_cfg ( &smartsens2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Setting callbacks..." );
/* Set callbacks */
parse_meta_event, &accuracy ) )
{
log_error( &logger, " FIFO sys meta event." );
for ( ; ; );
}
parse_meta_event, &accuracy ) )
{
log_error( &logger, " FIFO sys meta event wu." );
for ( ; ; );
}
uint8_t sensor_id;
void *callback_ref;
#if EULER
callback = parse_euler;
callback_ref = &accuracy;
#elif QUATERNION
callback = parse_quaternion;
callback_ref = NULL;
#elif VECTOR
#if ACCELEROMETER
parse_table.sensor[ SMARTSENS2_SENSOR_ID_ACC ].scaling_factor = 1.0f / 4096.0f;
#elif GYROSCOPE
parse_table.sensor[ SMARTSENS2_SENSOR_ID_GYRO ].scaling_factor = 1.0f;
#elif MAGNETOMETER
parse_table.sensor[ SMARTSENS2_SENSOR_ID_MAG ].scaling_factor = 1.0f;
#else
#error NO_VECTOR_EXAMPLE_DEFINED
#endif
callback = parse_vector_s16;
callback_ref = &parse_table;
#elif ENVIRONMENTAL
#if TEMPERATURE
callback = parse_temperature;
#elif BAROMETER
callback = parse_barometer;
#elif HUMIDITY
callback = parse_humidity;
#elif GAS
callback = parse_gas;
#else
#error NO_ENVIRONMENTAL_EXAMPLE_DEFINED
#endif
callback_ref = NULL;
#else
#error NO_EXAMPLE_DEFINED
#endif
if ( smartsens2_register_fifo_parse_callback( &smartsens2, sensor_id, callback, callback_ref ) )
{
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 = 10.0; /* Read out data at 10Hz */
uint32_t report_latency_ms = 0; /* Report immediately */
if ( smartsens2_set_virt_sensor_cfg( &smartsens2, sensor_id, sample_rate, report_latency_ms ) )
{
log_error( &logger, " Set virtual sensor configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define SMARTSENS2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition smartsens2.h:440
#define SMARTSENS2_SENSOR_ID_GAS
Definition smartsens2.h:248
#define SMARTSENS2_SENSOR_ID_TEMP
Definition smartsens2.h:245
#define SMARTSENS2_SENSOR_ID_HUM
Definition smartsens2.h:247
#define SMARTSENS2_SYS_ID_META_EVENT
Definition smartsens2.h:272
#define SMARTSENS2_SYS_ID_META_EVENT_WU
Definition smartsens2.h:276
#define SMARTSENS2_SENSOR_ID_ACC
Definition smartsens2.h:199
#define SMARTSENS2_SENSOR_ID_MAG
Definition smartsens2.h:211
#define SMARTSENS2_SENSOR_ID_RV
Definition smartsens2.h:219
#define SMARTSENS2_SENSOR_ID_GYRO
Definition smartsens2.h:205
#define SMARTSENS2_SENSOR_ID_BARO
Definition smartsens2.h:246
#define SMARTSENS2_SENSOR_ID_ORI
Definition smartsens2.h:225
err_t smartsens2_update_virtual_sensor_list(smartsens2_t *ctx)
Update the callback table's information.
void application_init(void)
Definition main.c:213
#define WORK_BUFFER_SIZE
Definition main.c:73
uint8_t accuracy
Definition main.c:77
@ SMARTSENS2_ERROR
Definition smartsens2.h:630

Application Task

Wait for an interrupt to occur, then read wake-up, non-weak-up, and status FIFO. Parse received data and run the callback parsers to show data on the USB UART.

void application_task ( void )
{
/* Check interrupt and get and process fifo buffer */
if ( smartsens2_get_interrupt( &smartsens2 ) )
{
/* Data from the FIFO is read and the relevant callbacks if registered are called */
{
log_error( &logger, " Get and process fifo." );
for ( ; ; );
}
}
}
uint8_t smartsens2_get_interrupt(smartsens2_t *ctx)
Get interrupt.
void application_task(void)
Definition main.c:337

Note

Select one of the examples with macros at the top of the main file. Euler example is selected by default. You can choose one of 4 type of parsers: Euler, Quaternion, Vector, Environmental. If Vector example is selected you choose one of the 3 sensors to show X, Y, and Z values: Accelerometer, Gyroscope, or Magnetometer. If Environmental example is selected you choose one of the 4 sensors: Temperature, Barometer, Humidity, or Gas.

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

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.