Skip to content

Introduction

Do you have a project that could use an inconspicuous HID (human interface device)? Ever wanted to tamper-proof your window alarm (i.e. contact sensors) from teenagers sneaking out or home intruders? Do you have a mechanical switch that keeps failing?

If you answered yes to any of those questions, the TMAG5273 from Texas Instruments could be the solution to your problems. The TMAG5273 is low-power 3D hall-effect sensor that is perfect for detecting and measuring changes in a nearby magnetic field. With a linear, magnetic range configurable to either ±40 mT or ±80 mT and TI's integrated angle calculation engine (CORDIC), the TMAG5273 can be used in various applications:

  • Detecting motor movement
  • Creating a HID (human interface device) (i.e. joysticks, knobs, scroll wheels, etc.)
  • Replacing various mechanical switches (i.e. rotary encoders, contact switches, reed switches, etc.)*

In addition, the included magnetic tamper detection and wake-up/threshold settings can be configured to trigger interrupts through the I2C interface or only with the dedicated interrupt pin.

 Required Materials

To get started, users will need a few items. Now some users may already have a few of these items, feel free to modify your cart accordingly.

  1. If your computer doesn't have a USB-A slot, then choose an appropriate cable or adapter.
  2. Check out our other Qwiic cable options.
  3. The mini version of this product is panel-mount compatible.
  4. Check out the other magnets in our catalog.
Headers and Wiring

To add headers or hookup wires, users will need soldering equipment and headers/wire.

New to soldering?

Check out our How to Solder: Through-Hole Soldering tutorial for a quick introduction!

Jumper Modification

To modify the jumpers, users will need soldering equipment and/or a hobby knife.

New to jumper pads?

Check out our Jumper Pads and PCB Traces Tutorial for a quick introduction!

 Suggested Reading

As a more sophisticated product, we will skip over the more fundamental tutorials (i.e. Ohm's Law and What is Electricity?). However, below are a few tutorials that may help users familiarize themselves with various aspects of the board.

Hardware Overview

Board Dimensions

The Qwiic Hall-Effect Sensors are laid out in the standardized 0.5"x 1" (1.77 x 2.54 cm) mini form-factor and the regular, 1" x 1" (2.54 x 2.54 cm) Qwiic breakout board. These boards also include standard 0.13" mounting holes, which are compatible with 4-40 screws. The dimensions of these boards are illustrated in the drawings below, where the listed measurements are in inches.

Board Dimensions of the standard board

Board Dimensions of the mini board

Dimensions (PDF) for the Qwiic Hall-Effect Sensor boards, in inches.

Need more measurements?

For more information about the board's dimensions, users can download the eagle files for the boards. These files can be opened in Eagle and additional measurements can be made with the dimensions tool.

Eagle - Free Download!

Eagle is a CAD program for electronics that is free to use for hobbyists and students. However, it does require an account registration to utilize the software.

Download from
Autodesk primary logo

📏 Dimensions Tool

This video from Autodesk demonstrates how to utilize the dimensions tool in Eagle, to include additional measurements:

QR code to play video

Power

The TMAG5273 requires a supply voltage between 2.3 to 3.6V (1). This power can be provided to the board, either, through one of the polarized Qwiic connectors or the dedicated 3.3V (3V3) and ground (GND) PTH pins broken out on the board.

  1. While the sensor's listed voltage range is 1.7 to 3.6V, its under-voltage range is 1.9 to 2.2V. Users may find that their sensor is unresponsive below 2.3V.

Power connections on the standard board

Power connections on the mini board

Qwiic Hall-Effect Sensor boards' power connections.

Warning

The Qwiic connect system is meant to run on 3.3V. Ensure that another voltage is not being supplied through the PTH pins when utilized in conjunction with this system.

Under-Voltage Threshold

The under-voltage threshold of the TMAG5273 is 1.9 to 2.2V. It is recommended that users provide an input voltage between 2.3 to 3.6V.

Info

For more details, users can reference the schematic and the TMAG5273 datasheet.

Power Status LED

The red, PWR LED will begin to light up once ~1.4V is supplied to the board; however, for most users, it will light up when 3.3V is supplied through the Qwiic connector. A jumper is available to disconnect the power from the LED, for low-power applications (see Jumpers section below).

Power LED on the standard board

Power LED on the mini board

The PWR status LED on the Qwiic Hall-Effect Sensor boards.

Minimum Voltage

Users should keep in mind that the forward voltage of the red LED is lower than the minimum voltage required to power the TMAG5273 sensor. Therefore, the LED could potentially be (dimly) lit, when there isn't enough voltage to power the sensor.

  TMAG5273

The Qwiic Hall-Effect Sensor board features the TMAG5273 sensor from Texas Instruments. The TMAG5273 is low-power 3D hall-effect sensor that is perfect for detecting and measuring changes in a nearby magnetic field. The magnetic range of the sensor is configurable to either ±40 mT or ±80 mT. In addition, the TMAG5273 features TI's integrated angle calculation engine (CORDIC) with gain adjustment, tamper detection, and temperature compensation (for NdBFe and ceramic magnet types). The operation sensor's interrupt can be configured to trigger through the I2C interface or an interrupt pin, based upon a wake-up/threshold setting or the conversion of a new measurement.

Features:

  • Configurable I2C Address:
    • Default (7-bit): 0x35 (hex) or 0110101 (bin)
  • Operating Voltage: 1.7 to 3.6V (1)
  • Current Draw:
    • Active: 2.3mA
    • Sleep Mode: 5nA
    • Wake-Up/Sleep (@ 1Hz): 1µA
  • Full-Scale Range: ±40mT or ±80mT (2)
  • Accuracy: ±5% (3)
    • Temperature Compensation (4)
  • CORDIC Engine (5)
  • Output Data Rate (Hz): (6)
    • 0.05, 0.2, 0.5, 1, 2, 10, 20, 33, 50, 66, 100, 200, or 1000
  • Operating Temperature: -40 to 125°C
  • Interrupt Triggers:
    • Threshold
    • Conversion
  1. The sensor may be unresponsive below 2.3V; its under-voltage range is 1.9 to 2.2V
  2. The range on each axis
  3. The typical sensitivity at room temperature
  4. Adjusts for magnet type (NdBFe or ceramic)
  5. Integrated angle calculation (along a single axis)
  6. CRC can be enabled

TMAG5273 sensor on the boards

The TMAG5273 sensor on the Qwiic Hall-Effect Sensor boards.

Sensor Alignment

We have positioned the TMAG5273 chip, based on the offset of the internal hall elements in the sensor.

TMAG5273 hall-effect elements position
Position of the hall elements in the TMAG5273. Source: TMAG5273 Datasheet

Info

For exact measurements, users can download and reference the eagle files of the boards. We recommend referencing the sensor's position based on the board's CNC milled, mounting holes.

Note

In manufacturing, we panelize our boards on a single PCB with a v-score separation. This is an efficient method to assemble multiple boards at once. After the panel is populated, cleaned, and inspected, the individual boards are separated by slicing the v-scores.

While efficient, this process means that measurements referencing the edges of the PCB won't be as accurate when compared to the included mounting holes.

The orientation of the sensor's axes is illustrated in the figure below.

TMAG5273 sensor's field orientations
The magnetic field orientation of the TMAG5273 hall-effect sensor. The TMAG5273's orientation is indicated by the black dot, just below the TI logo. Source: TMAG5273 Datasheet

Info

The orientation of the TMAG5273 sensor is indicated by the white silkscreen dot, next to the sensor, on the PCB of the Qwiic Hall-Effect Sensor boards. That dot correlates with the black dot just below the Texas Instruments logo in the figure above.

Interrupt Operation

The interrupt function for the TMAG5273 can be set up to operate on either the INT or SCL pins. Users can also configure what triggers the interrupt, a threshold or data conversion. Control of the interrupt's operation is managed in the following registers:

  • DEVICE_CONFIG_2
  • SENSOR_CONFIG_2
  • INT_CONFIG_1
Magnetic Offset Correction

The TMAG5273 features an offset correction, on a pair of magnetic axes for situations where the sensor might be affected by a persistent magnetic field. The offsets are configured in the following registers:

  • MAG_OFFSET_CONFIG_1
  • MAG_OFFSET_CONFIG_2
  • SENSOR_CONFIG_2

example of a magnetic offset
The magnetic flux measurements of a sine curve with an offset above the reference axis. Source: TMAG5273 Datasheet

Gain Adjustment

The TMAG5273 features a gain adjustment, on a pair of magnetic axes for situations where a magnet's rotation axis is offset from the position of the sensor's hall elements. The gain adjustments are configured in the following registers:

  • MAG_GAIN_CONFIG
  • SENSOR_CONFIG_2

example of a gain adjustment
The magnetic flux measurements of the TMAG5273 utilizing a magnet, with an on-axis and off-axis position. Source: TMAG5273 Datasheet

Tamper Detection

Magnetic tamper detection can be employed with the TMAG5273 by continuously monitoring for external magnetic fields. For more details, users can reference section 8.2.1 of the TMAG5273 datasheet and the application note.

Info

For more details, users can reference the TMAG5273 datasheet.

Breakout Pins

There are six PTH pins broken out on the Qwiic Hall-Effect Sensor boards. The pins are evenly spaced at 0.1" on the outer edge of the board; perfect for attaching headers. These pins provide access to the I2C interface and interrupt pin of the TMAG5273 sensor; and included is a DISABLE pin that controls the power to the sensor.

Note

The I2C interface can also be accessed through the Qwiic connectors on the board.

Disable Pin

Unfortunately, the TMAG5273 doesn't incorporate a software reset. The intended use of the TMAG5273 is to hard reset the sensor's power with a GPIO pin. However, with the Qwiic connect system, users may not want to power cycle the other Qwiic devices on the system. Therefore, we have incorporated DISABLE pin whose circuitry allows users to reset the TMAG5273, without interrupting the power of the Qwiic connect system.

Disable pin on the standard board

Disable pin on the mini board

The DISABLE pin on the Qwiic Hall-Effect Sensor boards.

Info

For more details, users can reference the schematic and the TMAG5273 datasheet.

Disable Button

A Disable button is only provided on the regular, 1" x 1" Qwiic board. This button is connected to the same reset circuitry of the DISABLE pin.

Disable button on the standard board

The Disable button on the Qwiic Hall-Effect Sensor.

Tip

The button casing appears to be ferromagnetic. Therefore, a strong magnetic field (i.e. from a rare Earth magnet) could potentially exert enough force to rotate or lift the board.

I2C Pins

The I2C interface can also be accessed either through the breakout pins or the Qwiic connectors on the board. In most cases, the Qwiic connector will be the simplest method to connect the Qwiic Hall-Effect Sensor boards to a microcontroller.

I2C pins on the standard board

I2C pins on the mini board

I2C pins on the Qwiic Hall-Effect Sensor boards.

Qwiic Connector

Qwiic connectors are provided for users to seamlessly integrate I2C devices with SparkFun's Qwiic Ecosystem.

Qwiic connector and pins on the standard board

Qwiic connector and pins on the mini board

Qwiic connector and its pins on the Qwiic Hall-Effect Sensor boards.

Interrupt Function

TI does not recommend sharing the same I2C bus with multiple secondary devices when using the SCL pin for interrupt function. The SCL interrupt may cause bus contention issues that would corrupt the I2C transactions with other secondary devices, when present on the same I2C bus.

Interrupt Pin

The interrupt function can be configured to operate through either the SCL or INT pins. When utilizing the interrupt pin (INT), the interrupt function can be configured to trigger once a conversion is completed or when a magnetic threshold has been surpassed.

Interrupt pin on the standard board

Interrupt pin on the mini board

Interrupt pin on the Qwiic Hall-Effect Sensor boards.

Qwiic Connectors

Qwiic connectors are provided for users to seamlessly integrate with SparkFun's Qwiic Ecosystem. Otherwise, users can access the I2C interface through the PTH pins broken out on the board.

Qwiic connector on the standard board

Qwiic connector on the mini board

Qwiic connectors on the Qwiic Hall-Effect Sensor boards.

What is Qwiic?

Qwiic Logo - light theme Qwiic Logo - dark theme


The Qwiic connect system is a solderless, polarized connection system that allows users to seamlessly daisy chain I2C boards together. Play the video below to learn more about the Qwiic connect system or click on the banner above to learn more about Qwiic products.

Features of the Qwiic System

no soldering - light theme no soldering - dark theme

Qwiic cables (4-pin JST) plug easily from development boards to sensors, shields, accessory boards and more, making easy work of setting up a new prototype.

polarized connector - light theme polarized connector - dark theme

There's no need to worry about accidentally swapping the SDA and SCL wires on your breadboard. The Qwiic connector is polarized so you know you’ll have it wired correctly every time, right from the start.

The PCB connector is part number SM04B-SRSS (Datasheet) or equivalent. The mating connector used on cables is part number SHR04V-S-B or an equivalent (1mm pitch, 4-pin JST connector).

daisy chainable - light theme daisy chainable - dark theme

It’s time to leverage the power of the I2C bus! Most Qwiic boards will have two or more connectors on them, allowing multiple devices to be connected.

Jumpers

Never modified a jumper before?

Check out our Jumper Pads and PCB Traces tutorial for a quick introduction!

There are three jumpers on the back of the board that can be used to easily modify the hardware connections of the board.

  • LED - This jumper can be used to disconnect power from the red, power LED for low-power applications.
  • I2C - This jumper can be used to remove the pull-up resistors on the I2C bus.
  • INT - This jumper can be used to remove the pull-up resistor from the INT pin.

Jumpers on the standard board

Jumpers on the back of the Qwiic Hall-Effect Sensor board.

Jumpers on the mini board

Jumpers on the Qwiic Hall-Effect Sensor board.

Hardware Assembly

Qwiic Cable

The simplest method to connect a microcontroller to a Qwiic Hall-Effect Sensor board is through the Qwiic connector.

Connecting Qwiic cable

Connecting a Qwiic cable to the Qwiic Hall-Effect Sensor board.

Info

The Qwiic connection system is a standardized solderless, polarized connector interface that allows users to seamlessly daisy chain I2C boards together.

Remove Tape

Users with the mini version of the Qwiic Hall-Effect Sensor board should remove the tape covering the Qwiic connector.

Removing tape
Removing the tape from the Qwiic connector to the Qwiic Hall-Effect Sensor board.

Info

The tape is used by the pick-and-place machine to place the connector on the board during assembly.

Note

The tweezers are not necessary, they were only used for illustration purposes. (Fingers would have obscured the camera shot.)

Breakout Pins

The PTH pins on the Qwiic Hall-Effect Sensor board are broken out into 0.1"-spaced pins on the outer edge of the board.

New to soldering?

If you have never soldered before or need a quick refresher, check out our How to Solder: Through-Hole Soldering guide.

Hookup Wires

For a more permanent connection, users can solder wires directly to the board.

Soldering wires

Soldering wires to the Qwiic Hall-Effect Sensor board.

Headers

When selecting headers, be sure you are aware of the functionality or physical arrangement required.

Soldering headers

Soldering headers to the Qwiic Hall-Effect Sensor board.

Software Overview

Arduino IDE

Tip

For first-time users, who have never programmed before and are looking to use the Arduino IDE, we recommend beginning with the SparkFun Inventor's Kit (SIK), which is designed to help users get started programming with the Arduino IDE.

Most users may already be familiar with the Arduino IDE and its use. However, for those of you who have never heard the name Arduino before, feel free to check out the Arduino website. To get started with using the Arduino IDE, check out our tutorials below:

Need help setting up the RedBoard Plus?

RedBoard Plus

The following instructions should help users get started with the RedBoard Plus. For more information about the board, please check out our hookup guide below:

CH340 Driver

Users will need to install the appropriate driver for their computer to recognize the serial-to-UART chip on their board/adapter. Most of the latest operating systems will recognize the CH340C chip on the board and automatically install the required driver.

Tip

To manually install the latest CH340 driver on their computer, users can download it from the WCH website. For more information, check out our How to Install CH340 Drivers Tutorial.

Selecting a Board

When selecting a board to program in the Arduino IDE, users should select the Arduino Uno from the Tools drop-down menu (_i.e. Tools > Board > Arduino AVR Boards > Arduino Uno).

Select the Arduino Uno from the Tools drop-down menu in the Arduino IDE.

Arduino IDE 2.x.x - Alternative Method

In the newest version of the Arduino IDE 2.x.x, users can also select their board (green) and port (blue) from the Select Board & Port dropdown menu (yellow).

Selecting the Arduino Uno and COM5 port from the Select Board & Port drop-down menu in the Arduino IDE (v2.0.3).

SparkFun TMAG5273 Arduino Library

The SparkFun TMAG5273 Arduino library can be installed from the library manager in the Arduino IDE by searching for:

SparkFun TMAG5273 Arduino library

SparkFun TMAG5273 Arduino library in the library manager of the Arduino IDE.

Manually Downloading the Arduino Library

For users who would like to manually download and install the library, the *.zip file can be accessed from the GitHub repository or downloaded by clicking the button below.

Download the Arduino Library

Example - Basic

Once the Arduino library has been installed, the Example1_BasicReadings.ino example file can be accessed from the File > Examples > SparkFun TMAG5273 Arduino Library > Example1_BasicReadings drop-down menu. This example reads the raw magnetic flux (mT) and temperature (°C) data from the TMAG5273 sensor through the I2C interface and displays them in the Serial Monitor.

Example1_BasicReadings.ino
Code Verification

This code was last verified to be functional under the following parameters:

Arduino IDE Version: 2.2.1
Arduino Library Version: 1.0.3

Hardware Platform:
- SparkFun RedBoard Plus
- SparkFun Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)
- SparkFun Mini Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)
#include <Wire.h>            // Used to establish serial communication on the I2C bus
#include "SparkFun_TMAG5273_Arduino_Library.h" // Used to send and recieve specific information from our sensor

TMAG5273 sensor; // Initialize hall-effect sensor

// I2C default address
uint8_t i2cAddress = TMAG5273_I2C_ADDRESS_INITIAL;

void setup() 
{
  Wire.begin();
  // Start serial communication at 115200 baud
  Serial.begin(115200);  

  // Begin example of the magnetic sensor code (and add whitespace for easy reading)
  Serial.println("TMAG5273 Example 1: Basic Readings");
  Serial.println("");

  // If begin is successful (0), then start example
  if(sensor.begin(i2cAddress, Wire) == 1)
  {
    Serial.println("Begin");
  }
  else // Otherwise, infinite loop
  {
    Serial.println("Device failed to setup - Freezing code.");
    while(1); // Runs forever
  }

}


void loop() 
{
  // Checks if mag channels are on - turns on in setup
  if(sensor.getMagneticChannel() != 0) 
  {
    sensor.setTemperatureEn(true);

    float magX = sensor.getXData();
    float magY = sensor.getYData();
    float magZ = sensor.getZData();
    float temp = sensor.getTemp();

    Serial.print("(");
    Serial.print(magX);
    Serial.print(", ");
    Serial.print(magY);
    Serial.print(", ");
    Serial.print(magZ);
    Serial.println(") mT");
    Serial.print(temp);
    Serial.println(" C");
  }
  else
  {
    // If there is an issue, stop the magnetic readings and restart sensor/example
    Serial.println("Mag Channels disabled, stopping..");
    while(1);
  }

  delay(100);
}

Hardware Connections

For this example, users simply need to connect their Qwiic Hall-Effect Sensor board to their microcontroller, utilizing the I2C interface. With the recommended hardware, users can easily connect their boards with the Qwiic connection system.

The sensor connected to a RedBoard Plus

The mini sensor connected to a RedBoard Plus

The Qwiic Hall-Effect Sensor boards are connected to a RedBoard Plus, with a Qwiic cable.

Pin Connections

For users with a development board without a Qwiic connector, the table below illustrates the required pin connections. Make sure that the logic-level of the sensor is compatible with the development board that is being connected.

Sensor Pin Microcontroller Pin RedBoard/Uno
SCL I2C - Serial Clock SCL/A5
SDA I2C - Serial Data SDA/A4
3V3 Power: 1.7 to 3.6V 3.3V
GND Ground GND

Serial Monitor

This example reads the magnetic flux (mT) and temperature values (°C) from the TMAG5273 sensor and displays them in the Serial Monitor.

Data stream in the serial monitor

The magnetic flux (mT) and temperature (°C) values streamed from the TMAG5273 sensor into the Serial Monitor.

Tip

For this example to work, users will need to move a magnet near the sensor.

Warning

The casing of rare Earth magnets is often conductive. Users should take precautions to avoid shorting out the components or electrical contacts with these types of magnets.

Example - Interrupt

The Example2_Interrupts.ino example file can be accessed from the File > Examples > SparkFun TMAG5273 Arduino Library > Example2_Interrupts drop-down menu. This example builds upon the previous code in Example1_BasicReadings.ino. Instead of constantly streaming the sensor values from the TMAG5273, the microcontroller enables a magnetic threshold interrupt on the x-axis. Then, it waits until an interrupt is triggered on the INT pin before the data is retrieved through the I2C interface.

Example2_Interrupts.ino
Code Verification

The code modification was last verified to be functional under the following parameters:

Arduino IDE Version: 2.2.1
Arduino Library Version: 1.0.3

Hardware Platform:
- SparkFun RedBoard Plus
- SparkFun Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)
- SparkFun Mini Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)

Required Modification

This code was developed to be utilized with the ESP32 on the IoT Motor Driver. Users will need to modify the example code, to utilize the interrupt pins of the ATmega328P on the RedBoard Plus. Replace uint8_t intPin = 4; with uint8_t intPin = 2; to utilize the D2 pin on the RedBoard Plus, which can handle interrupts.

Original Code:

// Interrupt pin used
// NOTE: This pin is specific to the SparkFun IoT Motor Driver
uint8_t intPin = 4;

Modified Code:

// Interrupt pin used
// NOTE: This pin is specific to the SparkFun IoT Motor Driver
uint8_t intPin = 2;
#include <Wire.h>               // Used to establish serial communication on the I2C bus
#include "SparkFun_TMAG5273_Arduino_Library.h"  // Used to send and recieve specific information from our sensor

TMAG5273 sensor;  // Initialize hall-effect sensor

// I2C default address
uint8_t i2cAddress = TMAG5273_I2C_ADDRESS_INITIAL;

// Interrupt pin used
// NOTE: This pin is specific to the SparkFun IoT Motor Driver
uint8_t intPin = 4;

// Start the flag as false
bool interruptFlag = false;

// ISR to print what interrupt was triggered
void isr1() 
{
  interruptFlag = true;
}


void setup() 
{
  Wire.begin();
  // Start serial communication at 115200 baud
  Serial.begin(115200);

  // Configure Interrupt Pin
  pinMode(intPin, INPUT);
  // Attach interrupt to pin 4 as a digital, falling pin
  attachInterrupt(digitalPinToInterrupt(intPin), isr1, CHANGE);

  // Begin example of the magnetic sensor code (and add whitespace for easy reading)
  Serial.println("TMAG5273 Example 2: Interrupts");
  Serial.println("");
  // If begin is successful (0), then start example
  if (sensor.begin(i2cAddress, Wire) == true)
  {
    Serial.println("Begin");
  } 
  else  // Otherwise, infinite loop
  {
    Serial.println("Device failed to setup - Freezing code.");
    while (1);  // Runs forever
  }

  // Set interrupt through !INT
  sensor.setInterruptMode(TMAG5273_INTERRUPT_THROUGH_INT);

  // Set the !INT pin state - pulse for 10us
  sensor.setIntPinState(true);

  // Enable the interrupt response for the thresholds
  sensor.setThresholdEn(true);

  //int pinStatus = sensor.getInterruptPinStatus();
  pinMode(intPin, INPUT);

  // Set X, Y, Z, and T Thresholds for interrupt to be triggered
  sensor.setXThreshold(5);            // mT
  //sensor.setYThreshold(5);            // mT
  //sensor.setZThreshold(5);            // mT
  //sensor.setTemperatureThreshold(50);  // C

  Serial.print("X Threshold Set: ");
  Serial.println(sensor.getXThreshold());
}

/* To use the other thresholds, simply change the names and use the other functions: 
- sensor.getYThreshold();
- sensor.getZThreshold();
- sensor.getTemperatureThreshold();
*/

void loop()
{
  if (interruptFlag == true) 
  {
    interruptFlag = false;
    Serial.println("X Threshold Reached!");

    int xThresh = sensor.getXThreshold();
    Serial.print("X Threshold: ");
    Serial.println(xThresh);

    if (sensor.getMagneticChannel() != 0)  // Checks if mag channels are on - turns on in setup
    {
      float magX = sensor.getXData();
      float magY = sensor.getYData();
      float magZ = sensor.getZData();
      float temp = sensor.getTemp();

      Serial.print("(");
      Serial.print(magX);
      Serial.print(", ");
      Serial.print(magY);
      Serial.print(", ");
      Serial.print(magZ);
      Serial.println(") mT");
      Serial.print(temp);
      Serial.println(" °C");
    } 
    else 
    {
      Serial.println("Mag Channels disabled, stopping..");
      while (1);
    }
  }
  else
  {
    Serial.println("Checking for Interrupts...");
  }

  delay(500);

}

Hardware Connections

For this example, users simply need to connect their Qwiic Hall-Effect Sensor board to their microcontroller, utilizing the I2C interface and interrupt pin. Users can easily connect the I2C interface with the Qwiic connection system on their boards. To connect the interrupt pin, we recommend utilizing an IC-hook for a temporary connection.

The sensor connected to a RedBoard Plus

The mini sensor connected to a RedBoard Plus

The Qwiic Hall-Effect Sensor boards are connected to a RedBoard Plus, with a Qwiic cable and an IC-hook.

Pin Connections

For users with a development board without a Qwiic connector, the table below illustrates the required pin connections. Make sure that the logic-level of the sensor is compatible with the development board that is being connected.

Sensor Pin Microcontroller Pin RedBoard/Uno
INT Interrupt Pin D2
SCL I2C - Serial Clock SCL/A5
SDA I2C - Serial Data SDA/A4
3V3 Power: 1.7 to 3.6V 3.3V
GND Ground GND

Serial Monitor

This example waits until an interrupt is triggered by the magnetic threshold before data is retrieved from the TMAG5273 sensor. The data is then displayed in the Serial Monitor.

Data stream in the serial monitor

The magnetic flux (mT) and temperature (°C) values streamed from the TMAG5273 sensor into the Serial Monitor.

Tip

For this example to work, users will need to move a magnet near the sensor to trigger the interrupt.

Warning

The casing of rare Earth magnets is often conductive. Users should take precautions to avoid shorting out the components or electrical contacts with these types of magnets.

Example - Angle Calculation

The Example3_AngleCalculations.ino example file can be accessed from the File > Examples > SparkFun TMAG5273 Arduino Library > Example3_AngleCalculations drop-down menu. This example demonstrates one of the advanced features of the TMAG5273; it enables a CORDIC engine to calculate the angle of a magnet rotating about the z-axis.

Example3_AngleCalculations.ino
Code Verification

This code was last verified to be functional under the following parameters:

Arduino IDE Version: 2.2.1
Arduino Library Version: 1.0.3

Hardware Platform:
- SparkFun RedBoard Plus
- SparkFun Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)
- SparkFun Mini Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)
#include <Wire.h>            // Used to establish serial communication on the I2C bus
#include "SparkFun_TMAG5273_Arduino_Library.h" // Used to send and recieve specific information from our sensor

// Create a new sensor object
TMAG5273 sensor; 

// I2C default address
uint8_t i2cAddress = TMAG5273_I2C_ADDRESS_INITIAL;

// Set constants for setting up device
uint8_t conversionAverage = TMAG5273_X32_CONVERSION;
uint8_t magneticChannel = TMAG5273_XYX_ENABLE;
uint8_t angleCalculation = TMAG5273_XY_ANGLE_CALCULATION;

void setup() 
{
  Wire.begin();
  // Start serial communication at 115200 baud
  Serial.begin(115200);   

  // Begin example of the magnetic sensor code (and add whitespace for easy reading)
  Serial.println("TMAG5273 Example 3: Angle Calculations");
  Serial.println("");
  // If begin is successful (0), then start example
  if(sensor.begin(i2cAddress, Wire) == true)
  {
    Serial.println("Begin");
  }
  else // Otherwise, infinite loop
  {
    Serial.println("Device failed to setup - Freezing code.");
    while(1); // Runs forever
  }

  // Set the device at 32x average mode 
  sensor.setConvAvg(conversionAverage);

  // Choose new angle to calculate from
  // Can calculate angles between XYX, YXY, YZY, and XZX
  sensor.setMagneticChannel(magneticChannel);

  // Enable the angle calculation register
  // Can choose between XY, YZ, or XZ priority
  sensor.setAngleEn(angleCalculation);

}


void loop() 
{
  if((sensor.getMagneticChannel() != 0) && (sensor.getAngleEn() != 0)) // Checks if mag channels are on - turns on in setup
  {
    float angleCalculation = sensor.getAngleResult();

    Serial.print("XYX: ");
    Serial.print(angleCalculation, 4);
    Serial.println("°");

  }
  else
  {
    Serial.println("Mag Channels disabled, stopping..");
    while(1);
  }

  delay(1000);
}

Hardware Connections

For this example, users simply need to connect their Qwiic Hall-Effect Sensor board to their microcontroller, utilizing the I2C interface. With the recommended hardware, users can easily connect their boards with the Qwiic connection system.

The sensor connected to a RedBoard Plus

The mini sensor connected to a RedBoard Plus

The Qwiic Hall-Effect Sensor boards are connected to a RedBoard Plus, with a Qwiic cable.

Pin Connections

For users with a development board without a Qwiic connector, the table below illustrates the required pin connections. Make sure that the logic-level of the sensor is compatible with the development board that is being connected.

Sensor Pin Microcontroller Pin RedBoard/Uno
SCL I2C - Serial Clock SCL/A5
SDA I2C - Serial Data SDA/A4
3V3 Power: 1.7 to 3.6V 3.3V
GND Ground GND

Serial Monitor

This example enables the CORDIC engine to calculate the angle of a magnet rotating about the z-axis, which is then displayed in the Serial Monitor.

Data stream in the serial monitor

The angle of the magnet is streamed from the TMAG5273 sensor into the Serial Monitor.

Tip

For this example to work, users should rotate a magnet's polarity about the z-axis of the TMAG5273 hall-effect sensor. Similar to how the magnetic knob is used for this stove top:

Warning

The casing of rare Earth magnets is often conductive. Users should take precautions to avoid shorting out the components or electrical contacts with these types of magnets.

Troubleshooting Tips

Need Help?

If you need technical assistance or more information on a product that is not working as you expected, we recommend heading on over to the SparkFun Technical Assistance page for some initial troubleshooting.

SparkFun Technical Assistance Page

If you can't find what you need there, the SparkFun Forums is a great place to search product forums and ask questions.

Account Registration Required

If this is your first visit to our forum, you'll need to create a Forum Account to post questions.

PWR LED dims when the board is disabled

The PWR LED on the Qwiic hall-effect sensor may only dim when it is disabled through the Disable button or DISABLE PTH pin. This will occur when the Qwiic hall-effect sensor is used in conjunction with development boards that have pull-up resistors on their SDA and SCL pins.

The combination of the pull-up resistors on the development board and the Qwiic hall-effect sensor will bypass the DISABLE pin's power cut-off circuitry. This results in the development board back-powering the Qwiic hall-effect sensor and its LED. In most circumstances, users shouldn't experience any issues, as the sensor should be within the under-voltage threshold and still reset.1 However, if the issue persists, users can disconnect the pull-up resistors on the Qwiic hall-effect sensor by cutting the I2C jumper.

Resources

Product Resources

Additional Resources

🏭 Manufacturer's Resources

ST Microelectronics also provides additional resources for the TMAG52735:

QR code to the hookup guide

Designing with Hall-effect sensors - electronic smart lock Designing joysticks with Hall-effect sensors


  1. We have thoroughly tested this issue with all of our development boards and have found that the Qwiic hall-effect sensor will still reset, when disabled because the sensor will be within its under-voltage threshold.