mc3479
¶
MC3479 Accelerometer MicroPython Driver
Author: Jose D. Montoya
-
class micropython_mc3479.mc3479.MC3479(i2c, address: int =
0x4C
)[source]¶ Driver for the MC3479 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
micropython_mc3479.MC3479
class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C import micropython_mc3479 as MC3479
Once this is done you can define your
machine.I2C
object and define your sensor objecti2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 mc3479 = MC3479.MC3479(i2c)
Now you have access to the attributes
accx, accy, accz = mc3479.acceleration
- property acceleration : tuple[float, float, float]¶
The device has the ability to read all sampled readings in a continuous sampling fashion. The device always updates the XOUT, YOUT, and ZOUT registers at the chosen output data rate
X, Y, and Z-axis accelerometer measurements are in 16-bit, signed 2’s complement format. Register addresses 0x0D to 0x12 hold the latest sampled data from the X, Y, and Z accelerometers.
- property acceleration_output_data_rate : str¶
Define the output data rate in Hz The output data rate is dependent of the power mode setting for the sensor
Mode
Value
MC3479.BANDWIDTH_50
0x08
50 HzMC3479.BANDWIDTH_100
0x09
100 HzMC3479.BANDWIDTH_125
0xA
125 HzMC3479.BANDWIDTH_200
0xB
200 HzMC3479.BANDWIDTH_250
0xC
250 HzMC3479.BANDWIDTH_500
0xD
500 HzMC3479.BANDWIDTH_1000
0xE
1000 HzMC3479.BANDWIDTH_2000
0xF
2000 HzExample¶
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 mc3479 = MC3479.MC3479(i2c) mc3479.acceleration_output_data_rate = MC3479.BANDWIDTH_500
- property acceleration_range : str¶
The range and scale control register sets the resolution, range, and filtering options for the accelerometer. All values are in sign-extended 2’s complement format. Values are reported in registers 0x0D - 0x12 (the hardware formats the output)
Mode
Value
MC3479.ACCEL_RANGE_2G
0b000
MC3479.ACCEL_RANGE_4G
0b001
MC3479.ACCEL_RANGE_8G
0b010
MC3479.ACCEL_RANGE_16G
0b011
MC3479.ACCEL_RANGE_12G
0b100
Example¶
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 mc3479 = MC3479.MC3479(i2c) mc3479.acceleration_range = MC3479.ACCEL_RANGE_12G
- property lpf_enabled : str¶
Low Power Filter Enabler
Mode
Value
MC3479.LPF_ENABLE
0b0
MC3479.LPF_DISABLE
0b1
Example¶
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 mc3479 = MC3479.MC3479(i2c) mc3479.lpf_enabled = MC3479.LPF_ENABLE
- property lpf_setting : str¶
Selects the Bandwidth for the Low Power Filter. Depends on the selection of the ODR/IDR
Mode
Value
MC3479.BANDWIDTH_1
0b001
Fc = IDR / 4.255MC3479.BANDWIDTH_2
0b010
Fc = IDR / 6MC3479.BANDWIDTH_3
0b011
Fc = IDR / 12MC3479.BANDWIDTH_5
0b101
Fc = IDR / 16Example¶
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 mc3479 = MC3479.MC3479(i2c) mc3479.lpf_setting = MC3479.BANDWIDTH_5
- property sensor_mode : str¶
Standby¶
Lowest power consumption
Internal clocking is halted
No motion detection, sampling, or calibration
The I2C/SPI bus can read and write to registers (resolution, range, thresholds and other settings can be changed)
Reset not allowed
Default state after a power-up
Normal¶
Highest power consumption
Internal clocking is enabled
Continuous motion detection and sampling; automatic calibration is available
The I2C/SPI bus can only write to the mode register and read all other registers
Reset allowed
Mode
Value
MC3479.STANDBY
0
MC3479.NORMAL
1