MSA301¶
CircuitPython library for the MSA301 Accelerometer
- Author(s): Bryan Siepert
Implementation Notes¶
Hardware:
- Adafruit MSA301 Triple Axis Accelerometer
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
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_HZorBandWidth.RATE_500_HZPossible values areBandWidth.RATE_1_HZBandWidth.RATE_1_95_HZBandWidth.RATE_3_9_HZBandWidth.RATE_7_81_HZBandWidth.RATE_15_63_HZBandWidth.RATE_31_25_HZBandWidth.RATE_62_5_HZBandWidth.RATE_125_HZBandWidth.RATE_250_HZBandWidth.RATE_500_HZBandWidth.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_HZorDataRate.RATE_1000_HZPossible values areDataRate.RATE_1_HZDataRate.RATE_1_95_HZDataRate.RATE_3_9_HZDataRate.RATE_7_81_HZDataRate.RATE_15_63_HZDataRate.RATE_31_25_HZDataRate.RATE_62_5_HZDataRate.RATE_125_HZDataRate.RATE_250_HZDataRate.RATE_500_HZDataRate.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
MSA301class. First you will need to import the libraries to use the sensorimport board import adafruit_msa301
Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA msa = adafruit_msa301.MSA301(i2c)
Now you have access to the
accelerationattributeacc_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 isTrue - 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 isTrue. - 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 isTapDuration.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)
-
-
class
adafruit_msa301.Mode¶ An enum-like class representing the different modes that the MSA301 can use. The values can be referenced like
Mode.NORMALorMode.SUSPENDPossible values areMode.NORMALMode.LOW_POWERMode.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_GorRange.RANGE_16_GPossible values areRange.RANGE_2_GRange.RANGE_4_GRange.RANGE_8_GRange.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_GorRange.RANGE_16_GPossible values areResolution.RESOLUTION_14_BITResolution.RESOLUTION_12_BITResolution.RESOLUTION_10_BITResolution.RESOLUTION_8_BIT
-
class
adafruit_msa301.TapDuration¶ An enum-like class representing the options for the “double_tap_window” parameter of
enable_tap_detection