Beginner
10 min

Detect magnetic fields across three axes (X, Y, and Z) with the MLX90394 and STM32F031K6

Triaxis® Hall technology magnetometer for high-precision magnetic position sensing

3D Hall 14 Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

3D Hall 14 Click

Dev Board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Accurately detect movement and orientation of magnetic object in all three spatial dimensions, enabling precise position tracking in various applications

A

A

Hardware Overview

How does it work?

3D Hall 14 Click is based on the MLX90394, a high-precision 3-axis magnetometer from Melexis, which uses the Triaxis® Hall technology to deliver exceptional performance and enhance position sensing in various applications. The MLX90394 is made for micropower applications, making it an excellent choice for battery-powered solutions. It accurately measures magnetic fields along three axes (X, Y, and Z) and converts these measurements and IC temperature into 16-bit words. These data points are then communicated through an I2C interface. The sensor offers flexibility in operation, allowing for measurements to be taken either on demand or continuously, with user-selectable refresh rates. Despite its compact size, the MLX90394 excels in noise performance and maintains low power consumption across various configurations. One of the standout features of the MLX90394 is its intelligent wake-up modes, which enable the entire system to enter a deep sleep state until a magnetic field change is

detected. This detection can be based on different criteria: a change from an initial measurement (Static Delta), a change from the previous measurement (Dynamic Delta), or surpassing a predefined threshold (Absolute). This functionality ensures efficient power management by toggling the device between active and sleep modes, capturing both busy and slowly changing magnetic fields effectively. As mentioned, the 3D Hall 14 Click is ideal for various applications. It can be used in battery-powered tools, household appliances (white goods), industrial machinery, smart home devices, home security systems, and many other contexts where precise and reliable position sensing is crucial. This Click board™ is designed in a unique format supporting the newly introduced MIKROE feature called "Click Snap." Unlike the standardized version of Click boards, this feature allows the main sensor area to become movable by breaking the PCB, opening up many new possibilities for implementation. Thanks to the

Snap feature, the MLX9039 can operate autonomously by accessing its signals directly on the pins marked 1-8. Additionally, the Snap part includes a specified and fixed screw hole position, enabling users to secure the Snap board in their desired location. 3D Hall 14 Click uses a standard 2-Wire I2C interface to communicate with the host MCU with fast-mode support and frequencies up to 1MHz. In addition to I2C pins, this Click board™ also has the interrupt signal on the INT pin of the mikroBUS™ socket to provide a notification that violates programmed thresholds. This interrupt can serve as a wake-up on change (WOC) interrupt output or a synchronization output. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

3D Hall 14 Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F031K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

4096

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
ID COMM
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PA12
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

3D Hall 14 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F031K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
2x4 RGB Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-32 with STM32 MCU MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for 3D Hall 14 Click driver.

Key functions:

  • c3dhall14_get_magnetic_flux - This function reads the raw values of X, Y, and Z axis and converts them to magnetic flux data in microTesla.

  • c3dhall14_get_temperature - This function reads the raw temperature value and converts it to Celsius.

  • c3dhall14_set_range - This function sets the magnetic flux measurement range.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief 3D Hall 14 Click example
 *
 * # Description
 * This example demonstrates the use of 3D Hall 14 click board by reading
 * the magnetic field strength from 3 axes and the sensor internal temperature.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads data from the sensor and displays them on the USB UART every 200ms.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "c3dhall14.h"

static c3dhall14_t c3dhall14;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    c3dhall14_cfg_t c3dhall14_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 " );

    // Click initialization.
    c3dhall14_cfg_setup( &c3dhall14_cfg );
    C3DHALL14_MAP_MIKROBUS( c3dhall14_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == c3dhall14_init( &c3dhall14, &c3dhall14_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( C3DHALL14_ERROR == c3dhall14_default_cfg ( &c3dhall14 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float x_axis = 0;
    float y_axis = 0;
    float z_axis = 0;
    float temperature = 0;
    if ( C3DHALL14_OK == c3dhall14_get_magnetic_flux ( &c3dhall14, &x_axis, &y_axis, &z_axis ) )
    {
        log_printf( &logger, " X-axis: %.1f uT\r\n", x_axis );
        log_printf( &logger, " Y-axis: %.1f uT\r\n", y_axis );
        log_printf( &logger, " Z-axis: %.1f uT\r\n", z_axis );
    }
    if ( C3DHALL14_OK == c3dhall14_get_temperature ( &c3dhall14, &temperature ) )
    {
        log_printf( &logger, " Internal temperature: %.2f C\r\n\n", temperature );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.