Volt Docs

Reference

HMC5883L

3-axis magnetometer / compass (found on the GY-85 9-DoF board).

Connects over
I²C
Address
0x1E
Made by
Honeywell
Datasheet
cdn-shop.adafruit.com

Use it

main.volt
hardware {
    device hmc5883l: HMC5883L
}

every 1s {
    let value: float = hmc5883l.x()
    log("hmc5883l", "x={value}")
}

On its own, the declaration puts the HMC5883L on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x1E. To choose the pins or the address, declare the bus and attach the device: device hmc5883l: HMC5883L on i2c0 at 0x1E with i2c i2c0(sda: 21, scl: 22).

Methods

  • hmc5883l.x() -> float

    X field in gauss

  • hmc5883l.y() -> float

    Y field in gauss

  • hmc5883l.z() -> float

    Z field in gauss

  • hmc5883l.heading() -> float

    Heading in degrees (0-360, board held flat)

Wiring

PinConnect to
VCC3.3V or 5V on GY-85
GNDGround
SDAGPIO21 on ESP32
SCLGPIO22 on ESP32

Specifications

Voltage
3.3V (GY-85 has an onboard regulator)
Range
±1.3 gauss (1090 LSB/gauss)
Sample rate
15 Hz continuous

Tips

  • Many boards sold as HMC5883L actually carry a QMC5883L at 0x0D — scan the bus if 0x1E is missing.
  • Keep it away from the SIM800L antenna and any relay; both distort the field.

Alternatives worth knowing:

  • QMC5883L: Cheaper clone at 0x0D, different registers.