Arduino driver for the Texas Instruments TMAG5273 3-axis Hall-effect magnetic sensor.
The TMAG5273 provides high-accuracy magnetic field measurement, temperature sensing, and angle calculation.
-
Full TMAG5273 register control
-
Magnetic field measurement (X, Y, Z)
-
Magnetic angle calculation
-
Temperature measurement
-
Magnetic threshold detection
-
Interrupt configuration
-
Magnetic gain and offset calibration
-
Low-power and continuous measurement modes
-
Conversion status monitoring
The TMAG5273 communicates using I²C.
| TMAG5273 Pin | MCU Pin | Notes |
|---|---|---|
| VCC | 3.3V | 3.3V only |
| GND | GND | Common ground |
| SDA | SDA | I²C data |
| SCL | SCL | I²C clock |
| INT | GPIO (optional) | Interrupt output |
-
Default I²C address: 0x35
-
Supported bus speeds:
-
100 kHz
-
400 kHz (recommended)
-
-
Arduino Library Manager
-
Open Arduino IDE
-
Go to Library Manager
-
Search for 7Semi TMAG5273
-
Click Install
-
-
Manual Installation
-
Download this repository as ZIP
-
Arduino IDE → Sketch → Include Library → Add .ZIP Library
-
float x, y, z;
sensor.readMag(x, y, z);- Returns magnetic field strength in milliTesla (mT).
float temperature;
sensor.readTemperatureC(temperature);- Returns temperature in °C.
The TMAG5273 can be used for magnetic rotary encoders.
float angle;
sensor.calculateAngleXY(angle);- Returns 0-360° angle based on the magnetic field.
The TMAG5273 supports multiple operating modes:
- Continuous measurement
- Low power mode
- Wake-up and sleep mode
- Triggered measurements
These modes allow balancing power consumption and response time depending on the application.
Example:
sensor.setOperatingMode(MODE_CONTINUOUS);Magnetic field range can be configured.
Range Field Strength XY_8192 ±40 mT XY_16384 ±80 mT
Example:
sensor.setXYRange(XY_16384);
sensor.setZRange(Z_16384);The sensor supports interrupt generation for events such as:
Magnetic threshold detection
Conversion completion
System diagnostics
Example:
sensor.setInterrupt(true, false, false, INTERRUPT_MODE_INT);Threshold detection allows the sensor to trigger interrupts when magnetic field values exceed a defined level.
sensor.setMagThreshold(20, 20, 20);Check if a new measurement is ready.
ConvStatus status;
sensor.readConversionStatus(status);
if(status.resultReady)
{
Serial.println("New data available");
}The sensor provides internal status information.
DeviceStatus status;
sensor.readDeviceStatus(status);
if(status.vccUV)
{
Serial.println("Undervoltage detected");
}make read me file for this library in this format