TOP Contributors

  1. MIKROE (2784 codes)
  2. Alcides Ramos (392 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (123 codes)
  5. Bugz Bensce (97 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (140544 times)
  2. FAT32 Library (73037 times)
  3. Network Ethernet Library (58043 times)
  4. USB Device Library (48215 times)
  5. Network WiFi Library (43826 times)
  6. FT800 Library (43295 times)
  7. GSM click (30359 times)
  8. mikroSDK (28990 times)
  9. PID Library (27116 times)
  10. microSD click (26721 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

Compass 5 Click

Rating:

0

Author: MIKROE

Last Updated: 2024-10-31

Package Version: 2.1.0.14

mikroSDK Library: 2.0.0.0

Category: Magnetic

Downloaded: 183 times

Not followed.

License: MIT license  

Compass 5 Click is a compact add-on board that contains a 3-axis magnetometer device suitable for compass application. This board features the AK09918C, a 3-axis electronic compass with high sensitive Hall sensor technology from AKM Semiconductor.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "Compass 5 Click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "Compass 5 Click" changes.

Do you want to report abuse regarding "Compass 5 Click".

  • mikroSDK Library 1.0.0.0
  • Comments (0)

mikroSDK Library Blog


Compass 5 Click

Compass 5 Click is a compact add-on board that contains a 3-axis magnetometer device suitable for compass application. This board features the AK09918C, a 3-axis electronic compass with high sensitive Hall sensor technology from AKM Semiconductor.

compass5_click.png

Click Product page


Click library

  • Author : Jelena Milosavljevic
  • Date : Jul 2021.
  • Type : I2C type

Software Support

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

Standard key functions :

  • compass5_cfg_setup Config Object Initialization function.

    void compass5_cfg_setup ( compass5_cfg_t *cfg );
  • compass5_init Initialization function.

    err_t compass5_init ( compass5_t *ctx, compass5_cfg_t *cfg );

Example key functions :

  • compass5_write_byte This function writes a desired number of data bytes starting from the selected register by using I2C serial interface.

    void compass5_write_byte ( compass5_t *ctx, uint8_t reg, uint8_t tx_data );
  • compass5_read_byte This function read 1 byte.

    uint8_t compass5_read_byte ( compass5_t *ctx, uint8_t reg );
  • compass5_sw_reset This function for software reset.

    void compass5_sw_reset ( compass5_t *ctx );

Example Description

This is an example that demonstrates the use of Compass 5 Click board that reads data from magnetic sensors for X, Y, and Z axes,processes it and displays it via the UART terminal.

The demo application is composed of two sections :

Application Init

Initializes I2C and starts to write log, performs power down mode, sets continuous measurement mode; also write log.


void application_init ( void ) {
    log_cfg_t log_cfg;                /**< Logger config object. */
    compass5_cfg_t compass5_cfg;      /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );
    Delay_ms ( 100 );

    // Click initialization.
    compass5_cfg_setup( &compass5_cfg );
    COMPASS5_MAP_MIKROBUS( compass5_cfg, MIKROBUS_1 );
    err_t init_flag = compass5_init( &compass5, &compass5_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    compass5_sw_reset( &compass5 );
    Delay_ms ( 500 );

    compass5_get_id( &compass5, &company_id, &device_id );

    if  ( ( company_id == COMPASS5_COMPANI_ID_NUM ) && ( device_id == COMPASS5_DEVICE_ID_NUM ) ) {
        log_printf( &logger, "--------------------\r\n" );
        log_printf( &logger, "  Compass 3 Click   \r\n" );
        log_printf( &logger, "--------------------\r\n" );
    }
    else {
        log_printf( &logger, "   Fatal error!!!   \r\n" );
        for ( ; ; );
    }
    Delay_ms ( 100 );

    log_printf( &logger, "  Power Down Mode  \r\n" );
    log_printf( &logger, "-------------------\r\n" );
    compass5_set_operation_mode( &compass5, COMPASS5_MODE_POWER_DOWN );
    Delay_ms ( 100 );

    log_printf( &logger, "    Continuous     \r\n" );
    log_printf( &logger, " Measurement Mode  \r\n" );
    log_printf( &logger, "-------------------\r\n" );
    compass5_set_operation_mode( &compass5, COMPASS5_MODE_CON_MEASUREMENT_100HZ );
    Delay_ms ( 100 );

    log_printf( &logger, " Start Measurement \r\n" );
    log_printf( &logger, "-------------------\r\n" );
    Delay_ms ( 100 );
    log_info( &logger, " Application Task " );
}

Application Task

When Compass 5 Click is connected to a mikroBUS, this example collects data on the current position of the X, Y and Z axes via I2C communication, processes and displays the data via the UART terminal. All axis data is printed every 2 seconds.


void application_task ( void ) {
    int16_t x_val;
    int16_t y_val;
    int16_t z_val;

    if ( compass5_check_data_ready( &compass5 ) == COMPASS5_DATA_READY ) {
        compass5_measurement_axis( &compass5, &x_val, &y_val, &z_val );
        Delay_ms ( 10 );

        log_printf( &logger, " X-axis: %d mG\r\n", x_val );
        log_printf( &logger, " Y-axis: %d mG\r\n", y_val );
        log_printf( &logger, " Z-axis: %d mG\r\n", z_val );        
        log_printf( &logger,  "--------------------\r\n" );
    }
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

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

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.


ALSO FROM THIS AUTHOR

Hall Current 15 Click

0

Hall Current 15 Click is a compact add-on board that provides precise AC or DC current-sensing solution. This board features the TMCS1101-Q1, a galvanically isolated Hall-effect current sensor capable of DC or AC current measurement with high accuracy, excellent linearity, and temperature stability from Texas Instruments. A low-drift, temperature-compensated signal chain provides <1.5% full-scale error across a broad operating temperature range. It also provides a reliable 600V lifetime working voltage and 3kVRMS isolation between the current path and circuitry with uni/bidirectional current sensing. Besides, the user is allowed to process the output signal in analog or digital form.

[Learn More]

Expand 14 Click

0

Expand 14 Click is a compact add-on board that contains a multi-port I/O expander. This board features the CAT9555, a CMOS device that provides 16-bit parallel input/output port expansion from ON Semiconductor. The CAT9555 contains two 8-bit configuration ports (input or output), input, output, and polarity inversion registers, alongside an I2C-compatible serial interface. Any of the sixteen I/Os can be configured as an input or output by writing to the configuration register. It also features an active-low interrupt output, indicating to the host controller that an input state has been changed.

[Learn More]

RS485 6 click

5

RS485 6 Click is offers a half-duplex RS-485 communication with integrated surge protection, which can be used as an interface between the TTL level UART and the RS485 communication bus. It is based on THVD1429DT, a transceiver from Texas Instruments with signaling rate of up to 20 Mbps.

[Learn More]