Kompass-Klick-Board
Kompass-Klick-Board
Overview
Das Compass Click Board™ ist eine Zusatzplatine im MikroBUS-Formfaktor. Es verfügt über das ultrakompakte Hochleistungs-E-Kompassmodul LSM303DLHC. Es umfasst ein spezielles Sensorelement und eine IC-Schnittstelle, die sowohl lineare Beschleunigung (Vollausschlag von ±2 g/±4 g/±8 g/±16 g) als auch magnetisches Feld (von ±1,3 bis ±8,1 Gauss Vollausschlag) messen kann und einen 16-Bit-Datenausgang über die I2C-Schnittstelle bietet. Vom IC empfangene Messwerte können verarbeitet und zur Bestimmung des magnetischen Nordpols der Erde verwendet werden.
Das Compass Click Board™ ist ausschließlich für die Verwendung mit einer 3,3-V-Stromversorgung ausgelegt. Dank all dieser Funktionen ist dieses Board ideal für kompensierten Kompass, Positionserkennung, Kartenrotation, Schrittzähler, Displayausrichtung und vieles mehr.
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.
Frequently Asked Questions
Have a Question?
Be the first to ask a question about this.