MicroPython QMC5883L Library¶
qmc5883l
¶
MicroPython Driver for the QMC5883L Accelerometer
Author(s): Jose D. Montoya
-
class micropython_qmc5883l.qmc5883l.QMC5883L(i2c, address: int =
0xD
)[source]¶ Driver for the QMC5883L Sensor connected over I2C.
- Parameters:¶
- Raises:¶
RuntimeError – if the sensor is not found
Quickstart: Importing and using the device
Here is an example of using the
QMC5883L
class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C from micropython_qmc5883l import qmc5883l
Once this is done you can define your
machine.I2C
object and define your sensor objecti2c = I2C(1, sda=Pin(2), scl=Pin(3)) qmc5883l = qmc5883l.QMC5883L(i2c)
Now you have access to the attributes
mag_x, mag_y, mag_z = qmc.magnetic
- property field_range : int¶
Field ranges of the magnetic sensor can be selected through the register RNG. The full scale field range is determined by the application environments. For magnetic clear environment, low field range such as +/- 2gauss can be used. The field range goes hand in hand with the sensitivity of the magnetic sensor. The lowest field range has the highest sensitivity, therefore, higher resolution.
Two field range values can be selected, 2G and 8G. With the following global variables.
Mode
Value
qmc5883l.FIELDRANGE_2G
0b00
qmc5883l.FIELDRANGE_8G
0b01
Example¶
i2c = board.I2C() qmc = qmc5883l.QMC5883L(i2c) qmc.field_range = qmc5883l.FIELDRANGE_2G
- property magnetic¶
Magnetic property
- property mode_control : int¶
Two bits of MODE registers can transfer mode of operations in the device, the two modes are Standby, and Continuous measurements. The default mode after Power-on-Reset (POR) is standby. There is no any restriction in the transferring between the modes.
Two modes can be selected Standby and Continuous With the following global variables.
Mode
Value
qmc5883l.MODE_CONTINUOUS
0b01
qmc5883l.MODE_STANDBY
0b00
Example¶
i2c = board.I2C() qmc = qmc5883l.QMC5883L(i2c) qmc.output_data_rate = qmc5883l.MODE_STANDBY
- property output_data_rate : int¶
Output data rate is controlled by ODR registers. Four data update frequencies can be selected: 10Hz, 50Hz, 100Hz and 200Hz. For most compassing applications, 10 Hz for low power consumption is recommended. For gaming, the high update rate such as 100Hz or 200Hz can be used.
Four oversample ratios can be selected, 10, 50, 100 or 200. With the following global variables.
Mode
Value
qmc5883l.OUTPUT_DATA_RATE_10
0b00
qmc5883l.OUTPUT_DATA_RATE_50
0b01
qmc5883l.OUTPUT_DATA_RATE_100
0b10
qmc5883l.OUTPUT_DATA_RATE_200
0b11
Example¶
i2c = board.I2C() qmc = qmc5883l.QMC5883L(i2c) qmc.output_data_rate = qmc5883l.OUTPUT_DATA_RATE_200
- property oversample : int¶
Over sample Rate (OSR) registers are used to control bandwidth of an internal digital filter. Larger OSR value leads to smaller filter bandwidth, less in-band noise and higher power consumption. It could be used to reach a good balance between noise and power.
Four oversample ratios can be selected, 64, 128, 256 or 512. With the following global variables.
Mode
Value
qmc5883l.OVERSAMPLE_64
0b11
qmc5883l.OVERSAMPLE_128
0b10
qmc5883l.OVERSAMPLE_256
0b01
qmc5883l.OVERSAMPLE_512
0b00
Example¶
i2c = board.I2C() qmc = qmc5883l.QMC5883L(i2c) qmc.oversample = qmc5883l.OVERSAMPLE_64