HMC-5883L

class electronics.devices.hmc5883l.HMC5883L(bus, address=30)

Interface for the Honeywell 3-Axis Digital Compass IC HMC5883L

Usage:
  • Use config() to specify the filtering and datarate
  • Use set_resolution() to configure the gain for the internal ADC
  • Use raw() and gauss() to get the sensor values
Example:
>>> sensor = HMC5883L(gw)
>>> sensor.config(averaging=4, datarate=15)
>>> sensor.set_resolution(1090)
>>> # Read a value
>>> sensor.gauss()
(2.3736, 7.1024, 11.831199999999999)
config(averaging=1, datarate=15, mode=0)

Set the base config for sensor

Parameters:
  • averaging – Sets the numer of samples that are internally averaged
  • datarate – Datarate in hertz
  • mode – one of the MODE_* constants
gauss()

Get the magnetometer values as gauss for each axis as a tuple (x,y,z)

Example:
>>> sensor = HMC5883L(gw)
>>> sensor.gauss()
(16.56, 21.2888, 26.017599999999998)
raw()

Get the magnetometer values as raw data from the sensor as tuple (x,y,z)

Example:
>>> sensor = HMC5883L(gw)
>>> sensor.raw()
(3342, 3856, 4370)
set_resolution(resolution=1090)

Set the resolution of the sensor

The resolution value is the amount of steps recorded in a single Gauss. The possible options are:

Recommended Gauss range Resolution Gauss per bit
0.88 Ga 1370 0.73 mGa
1.3 Ga 1090 0.92 mGa
1.9 Ga 820 1.22 mGa
2.5 Ga 660 1.52 mGa
4.0 Ga 440 2.27 mGa
4.7 Ga 390 2.56 mGa
5.6 Ga 330 3.03 mGa
8.1 Ga 230 4.35 mGa
Parameters:resolution – The resolution of the sensor