MSA301

CircuitPython library for the MSA301 Accelerometer

  • Author(s): Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_msa301.BandWidth

An enum-like class representing the different bandwidths that the MSA301 can use. The values can be referenced like BandWidth.WIDTH_1_HZ or BandWidth.RATE_500_HZ Possible values are

  • BandWidth.RATE_1_HZ
  • BandWidth.RATE_1_95_HZ
  • BandWidth.RATE_3_9_HZ
  • BandWidth.RATE_7_81_HZ
  • BandWidth.RATE_15_63_HZ
  • BandWidth.RATE_31_25_HZ
  • BandWidth.RATE_62_5_HZ
  • BandWidth.RATE_125_HZ
  • BandWidth.RATE_250_HZ
  • BandWidth.RATE_500_HZ
  • BandWidth.RATE_1000_HZ
class adafruit_msa301.DataRate

An enum-like class representing the different data rates that the MSA301 can use. The values can be referenced like DataRate.RATE_1_HZ or DataRate.RATE_1000_HZ Possible values are

  • DataRate.RATE_1_HZ
  • DataRate.RATE_1_95_HZ
  • DataRate.RATE_3_9_HZ
  • DataRate.RATE_7_81_HZ
  • DataRate.RATE_15_63_HZ
  • DataRate.RATE_31_25_HZ
  • DataRate.RATE_62_5_HZ
  • DataRate.RATE_125_HZ
  • DataRate.RATE_250_HZ
  • DataRate.RATE_500_HZ
  • DataRate.RATE_1000_HZ
class adafruit_msa301.MSA301(i2c_bus)

Driver for the MSA301 Accelerometer.

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

Quickstart: Importing and using the device

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

import board
import adafruit_msa301

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
msa = adafruit_msa301.MSA301(i2c)

Now you have access to the acceleration attribute

acc_x, acc_y, acc_z = msa.acceleration
acceleration

The x, y, z acceleration values returned in a 3-tuple and are in \(m / s ^ 2\)

enable_tap_detection(*, tap_count=1, threshold=25, long_initial_window=True, long_quiet_window=True, double_tap_window=4)

Enables tap detection with configurable parameters.

Parameters:
  • tap_count (int) – 1 to detect only single taps, or 2 to detect only double taps. default is 1
  • threshold (int) – A threshold for the tap detection. The higher the value the less sensitive the detection. This changes based on the accelerometer range. Default is 25.
  • long_initial_window (int) – This sets the length of the window of time where a spike in acceleration must occour in before being followed by a quiet period. True (default) sets the value to 70ms, False to 50ms. Default is True
  • long_quiet_window (int) – The length of the “quiet” period after an acceleration spike where no more spikes can occur for a tap to be registered. True (default) sets the value to 30ms, False to 20ms. Default is True.
  • double_tap_window (int) – The length of time after an initial tap is registered in which a second tap must be detected to count as a double tap. Setting a lower value will require a faster double tap. The value must be a TapDuration. Default is TapDuration.DURATION_250_MS.

If you wish to set them yourself rather than using the defaults, you must use keyword arguments:

msa.enable_tap_detection(tap_count=2,
                         threshold=25,
                         double_tap_window=TapDuration.DURATION_700_MS)
tapped

True if a single or double tap was detected, depending on the value of the tap_count argument passed to enable_tap_detection

class adafruit_msa301.Mode

An enum-like class representing the different modes that the MSA301 can use. The values can be referenced like Mode.NORMAL or Mode.SUSPEND Possible values are

  • Mode.NORMAL
  • Mode.LOW_POWER
  • Mode.SUSPEND
class adafruit_msa301.Range

An enum-like class representing the different acceleration measurement ranges that the MSA301 can use. The values can be referenced like Range.RANGE_2_G or Range.RANGE_16_G Possible values are

  • Range.RANGE_2_G
  • Range.RANGE_4_G
  • Range.RANGE_8_G
  • Range.RANGE_16_G
class adafruit_msa301.Resolution

An enum-like class representing the different measurement ranges that the MSA301 can use. The values can be referenced like Range.RANGE_2_G or Range.RANGE_16_G Possible values are

  • Resolution.RESOLUTION_14_BIT
  • Resolution.RESOLUTION_12_BIT
  • Resolution.RESOLUTION_10_BIT
  • Resolution.RESOLUTION_8_BIT
class adafruit_msa301.TapDuration

An enum-like class representing the options for the “double_tap_window” parameter of enable_tap_detection