mc3479

MC3479 Accelerometer Driver

  • Author(s): Jose D. Montoya

Implementation Notes

Software and Dependencies:

class mc3479.MC3479(i2c_bus: I2C, address: int = _I2C_ADDR)

Driver for the MC3479 Sensor connected over I2C.

Parameters:
  • i2c_bus (I2C) – The I2C bus the MC3479 is connected to.

  • address (int) – The I2C device address. Defaults to 0x4C

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

Here is an example of using the MC3479 class. First you will need to import the libraries to use the sensor

import board
import mc3479 as MC3479

Once this is done you can define your board.I2C object and define your sensor object

i2c = 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_25

0x10 25 Hz

MC3479.BANDWIDTH_50

0x11 50 Hz

MC3479.BANDWIDTH_62_5

0x12 62.5 Hz

MC3479.BANDWIDTH_100

0x13 100 Hz

MC3479.BANDWIDTH_125

0x14 125 Hz

MC3479.BANDWIDTH_250

0x15 250 Hz

MC3479.BANDWIDTH_500

0x16 500 Hz

MC3479.BANDWIDTH_1000

0x17 1000 Hz

Example

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_2G

0b000

MC3479.ACCEL_RANGE_4G

0b001

MC3479.ACCEL_RANGE_8G

0b010

MC3479.ACCEL_RANGE_16G

0b011

MC3479.ACCEL_RANGE_12G

0b100

Example

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_ENABLE

0b0

MC3479.LPF_DISABLE

0b1

Example

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_1

0b001 Fc = IDR / 4.255

MC3479.BANDWIDTH_2

0b010 Fc = IDR / 6

MC3479.BANDWIDTH_3

0b010 Fc = IDR / 12

MC3479.BANDWIDTH_5

0b010 Fc = IDR / 16

Example

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.STANDBY

0

MC3479.NORMAL

1