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.MC3479class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C import micropython_mc3479 as MC3479Once this is done you can define your
machine.I2Cobject 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_250x1025 HzMC3479.BANDWIDTH_500x1150 HzMC3479.BANDWIDTH_62_50x1262.5 HzMC3479.BANDWIDTH_1000x13100 HzMC3479.BANDWIDTH_1250x14125 HzMC3479.BANDWIDTH_2500x15250 HzMC3479.BANDWIDTH_5000x16500 HzMC3479.BANDWIDTH_10000x171000 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_2G0b000MC3479.ACCEL_RANGE_4G0b001MC3479.ACCEL_RANGE_8G0b010MC3479.ACCEL_RANGE_16G0b011MC3479.ACCEL_RANGE_12G0b100Example¶
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_ENABLE0b0MC3479.LPF_DISABLE0b1Example¶
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_10b001Fc = IDR / 4.255MC3479.BANDWIDTH_20b010Fc = IDR / 6MC3479.BANDWIDTH_30b011Fc = IDR / 12MC3479.BANDWIDTH_50b101Fc = 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.STANDBY0MC3479.NORMAL1