mc3479
MC3479 Accelerometer Driver
Author(s): Jose D. Montoya
Implementation Notes
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
- class mc3479.MC3479(i2c_bus: I2C, address: int = _I2C_ADDR)
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
MC3479class. First you will need to import the libraries to use the sensorimport board import mc3479 as MC3479
Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = board.I2C() # Uses board.SCL and board.SDA mc3479 = MC3479.MC3479(i2c)
Now you have access to the attributes
accx, accy, accz = mc3479.acceleration
- property acceleration: Tuple[int, int, int]
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: int
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 = board.I2C() mc3479 = MC3479.MC3479(i2c) mc3479.acceleration_output_data_rate = MC3479.BANDWIDTH_500
- property acceleration_range: int
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 = board.I2C() mc3479 = MC3479.MC3479(i2c) mc3479.acceleration_range = MC3479.ACCEL_RANGE_12G
- property lpf_enabled: int
Low Power Filter Enabler
Mode
Value
MC3479.LPF_ENABLE0b0MC3479.LPF_DISABLE0b1Example
i2c = board.I2C() mc3479 = MC3479.MC3479(i2c) mc3479.lpf_enabled = MC3479.LPF_ENABLE
- property lpf_setting: int
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_30b010Fc = IDR / 12MC3479.BANDWIDTH_50b010Fc = IDR / 16Example
i2c = board.I2C() mc3479 = MC3479.MC3479(i2c) mc3479.lpf_setting = MC3479.BANDWIDTH_5
- property sensor_mode: int
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