---
description: MAG3110
---

# Magnetometer

Code to interface a Magnetometer(mag3110)

```
#!/usr/bin/env python

from __future__ import print_function
import time, sys, atexit
from upm import pyupm_mag3110 as MAG3110

def main():
    # Instantiate the Three-Axis Digital Magnetometer Sensor on I2C on bus 1
    mySensor = MAG3110.MAG3110(2)
    data = MAG3110.mag3110_data_t()
    # activate periodic measurements
    mySensor.setActive();
    # Print out the x, y, z, status and die temperature value every 0.5 seconds

    while(1):
        mySensor.getData(data, True)
        print("X-Axis: "+str(data.x),"Y-Axis: "+str(data.y),"Z-Axis: "+str(data.z),"Status:"+hex(data.status),"Temp : "+str(data.dtemp))
        time.sleep(.5)
if __name__ == '__main__':
main()
```

**To run the program,** \
**Step 1: save the file as hdc1000.py**\
**Step 2: Run the Program in the board's terminal using** `python3 hdc1000.py`
