Skip to content

HMC5883L — 3-axis magnetometer

I2C address 0x1E (30). Companion driver: QMC5883L at 0x0D (eyes17.SENSORS.QMC5883L).

Connect and read

from eyes17 import eyes
from eyes17.SENSORS import HMC5883L

p = eyes.open()
mag = HMC5883L.connect(p.I2C, address=0x1E)
print(mag.getRaw())   # [Bx, By, Bz] in scaled units

Configuration

Method Meaning
setGain(gain) Sensitivity index from gain_choices [8…1]
setDataOutputRate(rate) Hz from [0.75, 1.5, 3, 7.5, 15, 30, 75]
setSamplesToAverage(n) 1, 2, 4, or 8
init(...) rewrite CONFA/CONFB and continuous mode
mag.setGain(5)
mag.setDataOutputRate(75)
print(mag.getRaw())

Raw I2C equivalent (without the class):

p.I2C.writeBulk(30, [0x02, 0])          # continuous mode
vals = p.I2C.readBulk(30, 0x03, 6)