Reference
QMC5883L
Digital compass / magnetometer.
- Connects over
- I²C
- Address
- 0x0D
- Made by
- QST
- Datasheet
- datasheetspdf.com
Use it
hardware {
device qmc5883l: QMC5883L
}
every 1s {
let value: float = qmc5883l.x()
log("qmc5883l", "x={value}")
}
On its own, the declaration puts the QMC5883L on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x0D. To choose the pins or the address, declare the bus and attach the device: device qmc5883l: QMC5883L on i2c0 at 0x0D with i2c i2c0(sda: 21, scl: 22).
Methods
-
qmc5883l.x() -> float
X magnetic field (gauss)
-
qmc5883l.y() -> float
Y magnetic field
-
qmc5883l.z() -> float
Z magnetic field
-
qmc5883l.heading() -> float
Compass heading in degrees
Wiring
| Pin | Connect to |
|---|---|
VCC | 3.3V ONLY — 5V damages the chip |
GND | Ground |
SDA | Pull-up to 3.3V |
SCL | Pull-up to 3.3V |
DRDY | Data ready interrupt |
Specifications
- Voltage
- 2.16V – 3.6V
- Current
- 75 μA standby
- Range
- ±2 G or ±8 G
- Resolution
- 16-bit
- Sample rate
- 10 / 50 / 100 / 200 Hz
Tips
- Drop-in for the original HMC5883L — but different register layout. Many cheap 'HMC5883L' modules are actually QMC.
- Calibrate for hard-iron (offset) and soft-iron (scale) distortion — uncalibrated heading is useless.
- Tilt-compensate using accelerometer data for a usable compass on a tilted board.
Alternatives worth knowing:
- MMC5883MA: Memsic — better accuracy and stability.
- BNO055: Has a magnetometer + sensor fusion — much easier to use for compass.