Tableau à clics avec boussole
Tableau à clics avec boussole
La carte Compass Click Board™ est une carte complémentaire au format mikroBUS. Elle est équipée du module de boussole électronique ultra-compact et hautes performances LSM303DLHC. Elle comprend un élément de détection spécifique et une interface IC capable de mesurer à la fois l'accélération linéaire (pleine échelle de ±2g/±4g/±8g/±16g) et le champ magnétique (de ±1,3 à ±8,1 gauss pleine échelle) et fournit une sortie de données 16 bits via l'interface I2C. Les lectures reçues du circuit intégré peuvent être traitées et utilisées pour déterminer le pôle nord magnétique de la Terre.
La carte Compass Click Board™ est conçue pour utiliser uniquement une alimentation de 3,3 V. Toutes ces fonctionnalités rendent cette carte idéale pour la boussole compensée, la détection de position, la rotation de carte, le podomètre, l'orientation de l'affichage et bien plus encore.
Now add compass to your design using the Compass Click Board™ from MikroElektronika to your design. This accessory board incorporates an ultra-compact LSM303DLHC e-compass module that showcases low power consumption and high performance. The module has a 3D digital linear acceleration sensor and a 3D digital magnetic sensor. It also features 3 magnetic field channels and 3 acceleration channels. Compass Click Board™ provides a 16-bit data output through I2C serial bus interface.
Designed to just plug directly into a MikroBUS socket after soldering the header pins, the module features two independent programmable interrupt generators meant for free-fall and motion detection. The IC interface transmits readings, which are processed, and used to determine the earth's magnetic north pole. Compass Click Board™ communicates with the target board MCU through the MikroBUS I2C (SDA, SCL), INT and RST lines.
It makes an ideal choice for a range of applications, including a compensated compass, position detection, map rotation, pedometer, display orientation, and many more. It is designed to support 3.3V power supply only
IC/Module: LSM303DLHC E-compass Module
Compass Click Board™ carries a high performance LSM303DLHC E-compass Module, available in a plastic land grid array package. This module has linear acceleration full scales of.
Software Support
This example is a showcase the ability of the device to read 3 axis data of magnetic raw value when data is ready.
The demo application is composed of two sections :
Application Init
Initialization of communication modules (I2C, UART) and data ready pin as input. Then reads identification data and checks if some of them have wrong value, and configures device for reading.
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
compass6_cfg_t compass6_cfg; /**< Click config object. */
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
compass6_cfg_setup( &compass6_cfg );
COMPASS6_MAP_MIKROBUS( compass6_cfg, MIKROBUS_1 );
err_t init_flag = compass6_init( &compass6, &compass6_cfg );
if ( I2C_MASTER_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
uint8_t temp_data = 0;
compass6_generic_read( &compass6, COMPASS6_REG_WHO_I_AM, &temp_data );
log_printf( &logger, " > Who am I: 0x%.2X\r\n", ( uint16_t )temp_data );
if ( COMPASS6_WHO_AM_I != temp_data )
{
log_error( &logger, " Who am I. " );
}
compass6_generic_read( &compass6, COMPASS6_REG_INFO_VERSION, &temp_data );
log_printf( &logger, " > Version: 0x%.2X\r\n", ( uint16_t )temp_data );
if ( COMPASS6_VERSION != temp_data )
{
log_error( &logger, " Version. " );
}
compass6_generic_read( &compass6, COMPASS6_REG_INFO_ALPS, &temp_data );
log_printf( &logger, " > ALPS: 0x%.2X\r\n", ( uint16_t )temp_data );
if ( COMPASS6_ALPS != temp_data )
{
log_error( &logger, " ALPS. " );
}
compass6_default_cfg ( &compass6 );
log_info( &logger, " Application Task " );
Delay_ms( 2000 );
}
Application Task
Checks Data ready pin and if asserted high it will read data of all 3 axes(x, y, z) and log data to Terminal and set delay of 500ms.
void application_task ( void )
{
if ( compass6_data_ready( &compass6 ) )
{
compass6_axes_t axes_data;
compass6_get_axes_data( &compass6, &axes_data );
log_printf( &logger, " > X: %d\r\n", axes_data.x );
log_printf( &logger, " > Y: %d\r\n", axes_data.y );
log_printf( &logger, " > Z: %d\r\n", axes_data.z );
log_printf( &logger, "*********************\r\n" );
Delay_ms( 500 );
}
}
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.
Software Support
This example is a showcase the ability of the device to read 3 axis data of magnetic raw value when data is ready.
The demo application is composed of two sections :
Application Init
Initialization of communication modules (I2C, UART) and data ready pin as input. Then reads identification data and checks if some of them have wrong value, and configures device for reading.
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
compass6_cfg_t compass6_cfg; /**< Click config object. */
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
compass6_cfg_setup( &compass6_cfg );
COMPASS6_MAP_MIKROBUS( compass6_cfg, MIKROBUS_1 );
err_t init_flag = compass6_init( &compass6, &compass6_cfg );
if ( I2C_MASTER_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
uint8_t temp_data = 0;
compass6_generic_read( &compass6, COMPASS6_REG_WHO_I_AM, &temp_data );
log_printf( &logger, " > Who am I: 0x%.2X\r\n", ( uint16_t )temp_data );
if ( COMPASS6_WHO_AM_I != temp_data )
{
log_error( &logger, " Who am I. " );
}
compass6_generic_read( &compass6, COMPASS6_REG_INFO_VERSION, &temp_data );
log_printf( &logger, " > Version: 0x%.2X\r\n", ( uint16_t )temp_data );
if ( COMPASS6_VERSION != temp_data )
{
log_error( &logger, " Version. " );
}
compass6_generic_read( &compass6, COMPASS6_REG_INFO_ALPS, &temp_data );
log_printf( &logger, " > ALPS: 0x%.2X\r\n", ( uint16_t )temp_data );
if ( COMPASS6_ALPS != temp_data )
{
log_error( &logger, " ALPS. " );
}
compass6_default_cfg ( &compass6 );
log_info( &logger, " Application Task " );
Delay_ms( 2000 );
}
Application Task
Checks Data ready pin and if asserted high it will read data of all 3 axes(x, y, z) and log data to Terminal and set delay of 500ms.
void application_task ( void )
{
if ( compass6_data_ready( &compass6 ) )
{
compass6_axes_t axes_data;
compass6_get_axes_data( &compass6, &axes_data );
log_printf( &logger, " > X: %d\r\n", axes_data.x );
log_printf( &logger, " > Y: %d\r\n", axes_data.y );
log_printf( &logger, " > Z: %d\r\n", axes_data.z );
log_printf( &logger, "*********************\r\n" );
Delay_ms( 500 );
}
}
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.
Tableau à clics avec boussole
Frequently Asked Questions
Have a Question?
Be the first to ask a question about this.