# Adafruit MSA301 Triple Axis Accelerometer

## Overview

Warning: The MSA301 sensor reached end-of-life and is no longer available. Adafruit suggests the [Adafruit MSA311 Triple Axis Accelerometer](https://www.adafruit.com/product/5309) for new projects. This guide is here to assist in any use of the discontinued product.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/691/medium800/sensors_3quarter.jpg?1566359692)

The MSA301 is a super small and low cost&nbsp; **triple-axis accelerometer**. It's inexpensive, but has just about every 'extra' you'd want in an accelerometer:

- Three axis sensing, 14-bit resolution
- ±2g/±4g/±8g/±16g selectable scaling
- I2C interface on fixed I2C address 0x26
- Interrupt output
- Multiple data rate options from 1 Hz to 500 Hz
- As low as 2uA current draw in low power mode (just the chip itself, not including any supporting circuitry)
- Tap, Double-tap, orientation & freefall detection

![](https://cdn-learn.adafruit.com/assets/assets/000/079/692/medium800/sensors_qt_wiring_example.jpg?1566359766)

To make life easier, so you can focus on your important work, we've taken the MSA301 and put it onto a breakout PCB along with support circuitry to let you use this little wonder with 3.3V (Feather/Raspberry Pi) or 5V (Arduino/ Metro 328) logic levels. Additionally, since it speaks I2C, you can easily connect it up with two wires (plus power and ground!).&nbsp; We've even included&nbsp;[SparkFun qwiic](https://www.sparkfun.com/qwiic)&nbsp;compatible**&nbsp;[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)**&nbsp;connectors for the I2C bus, so&nbsp; **you don't even need to solder!** &nbsp;Just wire up to your favorite microcontroller and&nbsp;[you can use our CircuitPython/Python&nbsp;](https://github.com/adafruit/Adafruit_CircuitPython_MSA301)or&nbsp;[Arduino drivers to easily interface with the MSA301](https://github.com/adafruit/Adafruit_MSA301)&nbsp;and get motion measurements ASAP.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/694/medium800/sensors_qt_closeup.jpg?1566359847)

# Adafruit MSA301 Triple Axis Accelerometer

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/079/674/medium800/sensors_front_crop.jpg?1566341441)

## Power Pins

- **Vin** - this is the power pin. Since the sensor chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
- **3Vo** - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
- **GND** - common ground for power and logic

## I2C Logic Pins

- **SCL** - this is the I2C clock pin, connect to your microcontroller's I2C clock line.
- **SDA** - this is the I2C data pin, connect to your microcontroller's I2C data line
- **[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;-** These connectors allow you to connectors to dev boards with&nbsp; **STEMMA QT** connectors or to other things with&nbsp;[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204)

## Other Pins

- **INT&nbsp;** -This is the interrupt pin. You can setup the MSA301 to pull this low when certain conditions are met such as taps being detected.

# Adafruit MSA301 Triple Axis Accelerometer

## Arduino

- Connect&nbsp; **&nbsp;**** Metro or Arduino&nbsp; ****5V** to&nbsp; **board**  **VIN**
- Connect **Metro or Arduino**  **GND** to **board**  **GND**
- Connect **Metro or Arduino**  **SCL** to **board SCL**
- Connect **Metro or Arduino**  **SDA** to **board SDA**

![sensors_arduino_fritz.png](https://cdn-learn.adafruit.com/assets/assets/000/079/685/medium640/sensors_arduino_fritz.png?1566359357)

The final results should resemble the illustration above, showing an [Adafruit Metro](https://www.adafruit.com/product/2488) development board.

## Installation

We've written a sensor library for you for the MSA301 which uses our **Adafruit\_Sensor** and **BusIO** libraries.&nbsp;You can install both the [**Adafruit\_MSA301 Library**](https://github.com/adafruit/Adafruit_MSA301) and the **Adafruit BusIO Library** for Arduino using the Library Manager in the Arduino IDE:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/676/medium800/sensors_library_manager_menu.png?1566341879)

Click the&nbsp; **Manage Libraries ...** &nbsp;menu item, search for&nbsp; **Adafruit MSA301** ,&nbsp;and select the&nbsp; **Adafruit\_MSA301** &nbsp;library:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/699/medium800/sensors_msa301_arduino_install.png?1566406549)

Then follow the same process for the&nbsp; **Adafruit BusIO** library:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/677/medium800/sensors_adafrtui_busio_arduino.png?1566341971)

Finally do the same for the&nbsp; **Adafruit Unified Sensor** library

![](https://cdn-learn.adafruit.com/assets/assets/000/083/222/medium800/sensors_Unified_Sensor_LibMGR.png?1572381778)

## Accelerometer Demo

This first demo will show you how to get readings of what an accelerometer does best: measure acceleration!

Open up&nbsp; **File -\> Examples -\> Adafruit MSA301&nbsp;**** -\> acceldemo&nbsp;**and upload to your Arduino wired up to the sensor.

Upload the sketch to your board and open up the Serial Monitor ( **Tools -\> Serial Monitor** ) at 115200 baud. You should see the the values for the current configuration settings printed on startup, followed by acceleration readings for the X, Y, and Z axes similar to this:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/680/medium800/sensors_arduino_example_screenshot.png?1566343833)

You can tilt the sensor in different directions to see the values for the different axes change.

## Tap Demo

This next demo will demonstrate how to use the tap detection feature of the MSA301. By tapping the accelerometer or the PCB or something the PCB is attached to you can create a type of interface.

Open up&nbsp; **File -\> Examples -\> Adafruit MSA301&nbsp;**** -\> tapdemo&nbsp;**and upload to your Arduino wired up to the sensor.

Once the sketch is loaded, open up the Serial Monitor ( **Tools -\> Serial Monitor** ) at 115200 baud. When you tap, you should see the sketch report that a tap was detected:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/804/medium800/sensors_arduino_tap_demo.png?1566513152)

The tap detection works by looking for when one of the axes has an acceleration higher than a certain **threshold** &nbsp;followed by a&nbsp; **quiet** period where there are no more acceleration spikes above the **threshold**.

After an initial "spike" of acceleration above the&nbsp; **threshold,&nbsp;** any additional spikes within a window of time defined by the&nbsp; **shock** parameter are ignored.&nbsp;

For double tap detection, after an initial tap has been detected, another tap event within the window of time specified by the&nbsp; **duration** parameter will trigger a double tap interrupt if they are enabled.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/808/medium800/sensors_tap_diagram.png?1566515800)

The tap detection parameters are set by calling&nbsp; **setClick:**

```
msa.setClick(false, false, MSA301_TAPDUR_250_MS, 25);
// Method signature:
// void setClick(bool tap_quiet, bool tap_shock, msa301_tapduration_t tapduration, uint8_t tapthresh);
  
```

The **threshold** is in 'raw' values so you have to adjust it based on the scale/range you've configured for the sensor.&nbsp;Larger numbers are less sensitive, you'll really need to just tweak as necessary for your project.

The&nbsp; **duration** parameter&nbsp; **only applies to double tap detection.** It is specified by passing an&nbsp;**[msa301\_tapduration\_t](https://adafruit.github.io/Adafruit_MSA301/html/_adafruit___m_s_a301_8h.html#ad3222eb550403305b115ac3e37541397).&nbsp;**A shorter duration will require a quicker double tap to be detected.

The **quiet** duration is either&nbsp; **20ms** if&nbsp; **true** or **30ms** if **false**. Similarly the&nbsp; **shock** duration is either&nbsp; **70ms** if&nbsp; **true** or **50ms** if **false**.

Additionally after configuring tap detection, you will need to enable the tap detection interrupts:

```
msa.enableInterrupts(true, true); // enable single, double tap
```

If you wish to have the tap detection activate the interrupt pin, you will have to enable that as well:

```
msa.mapInterruptPin(true, true); // enable the INT pin for single, double tap
```

## Acceleration Example Code

The following code is part of the standard library and illustrates the basic function of measuring acceleration:

https://github.com/adafruit/Adafruit_MSA301/blob/master/examples/acceldemo/acceldemo.ino

## Tap Detection Example Code

Here is the full code for the tap detection example:

https://github.com/adafruit/Adafruit_MSA301/blob/master/examples/tapdemo/tapdemo.ino

# Adafruit MSA301 Triple Axis Accelerometer

## Arduino Docs

# Adafruit MSA301 Triple Axis Accelerometer

## Python & CircuitPython

It's easy to use the MSA301 sensor with CircuitPython and the&nbsp;[Adafruit CircuitPython MSA301](https://github.com/adafruit/Adafruit_CircuitPython_MSA301)&nbsp;module.&nbsp; This module allows you to easily write Python code that reads the acceleration and adjust the measurement settings.  
  
You can use this sensor with any CircuitPython microcontroller board or with a Linux single board computer that has GPIO and Python&nbsp;[thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

## CircuitPython Microcontroller Wiring

First wire up a MSA301 to your board exactly as follows. Here is an example of the MSA301 wired to a [Feather](https://www.adafruit.com/product/3857) using I2C:

- **Board 3V** &nbsp;to&nbsp; **sensor VIN**
- **Board GND** &nbsp;to&nbsp; **sensor GND**
- **Board SCL** &nbsp;to&nbsp; **sensor SCL**
- **Board SDA** &nbsp;to&nbsp; **sensor SDA**

![sensors_cp_fritz.png](https://cdn-learn.adafruit.com/assets/assets/000/079/686/medium640/sensors_cp_fritz.png?1566359417)

Primary: 

## Python Computer Wiring

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for [Raspberry Pi](https://www.adafruit.com/product/3055). For other platforms,&nbsp;[please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V3** &nbsp;to&nbsp; **sensor VIN**
- **Pi GND** &nbsp;to&nbsp; **sensor GND**
- **Pi SCL** &nbsp;to&nbsp; **sensor SCL**
- **Pi SDA** &nbsp;to&nbsp; **sensor SDA**

![sensors_rpi_fritz.png](https://cdn-learn.adafruit.com/assets/assets/000/079/687/medium640/sensors_rpi_fritz.png?1566359475)

## CircuitPython Installation of MSA301 Library

You'll need to install the&nbsp;[Adafruit CircuitPython MSA301](https://github.com/adafruit/Adafruit_CircuitPython_MSA301) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_msa301.mpy**
- **adafruit\_bus\_device**
- **adafruit\_register**

Before continuing make sure your board's **lib** folder or root filesystem has the&nbsp; **adafruit\_msa301.mpy,**  **adafruit\_bus\_device** , and&nbsp; **adafruit\_register** files and folders **&nbsp;** copied over.

Next&nbsp;[connect to the board's serial REPL&nbsp;](https://learn.adafruit.com/welcome-to-circuitpython/the-repl)so you are at the CircuitPython&nbsp;`>>>`&nbsp;prompt.

## Python Installation of MSA301 Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-msa3xx`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

## CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll initialize it and read the acceleration measurements from the board's Python REPL.

Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

```python
import time
import board
import adafruit_msa3xx

i2c = board.I2C()

msa = adafruit_msa3xx.MSA301(i2c)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/102/065/medium800/sensors_msa301.png?1620650596)

Now you're ready to read the **acceleration** values from the sensor using the property provided by the library.&nbsp;  
  
Here is an example showing how to print the acceleration values:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/682/medium800/sensors_read_accel_repl_screenshot.png?1566346029)

You can find more details about what the library allows by reading the&nbsp;[library documentation](https://circuitpython.readthedocs.io/projects/msa301/en/latest/).  
  
That's it! Using the MSA301 accelerometer with CircuitPython makes it easy to get started.

## Tap Detection

Next, let's take a look at another neat feature of the MSA301: Tap detection!  
  
Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/859/medium800/sensors_tap_setup.png?1566588990)

Next we'll configure tap detection by calling [enable\_tap\_detection](https://circuitpython.readthedocs.io/projects/msa301/en/latest/api.html#adafruit_msa301.MSA301.enable_tap_detection). Here we're giving an example of the different parameters you can tune, but calling it without any arguments will set it to detect single taps with reasonable settings defaults:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/860/medium800/sensors_py_setup_double_tap.png?1566589091)

Finally we set up a loop, calling the&nbsp; **tapped&nbsp;** property to check and print if a double tap has been detected, since we passed&nbsp; **2** to the&nbsp;[**enable\_tap\_detection**](https://circuitpython.readthedocs.io/projects/msa301/en/latest/api.html#adafruit_msa301.MSA301.enable_tap_detection)which&nbsp;specifies double tap detection:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/862/medium800/sensors_py_double_tap_loop.png?1566589245)

## Acceleration Example Code
https://github.com/adafruit/Adafruit_CircuitPython_MSA301/blob/main/examples/msa301_simpletest.py

## Tap Detection Example Code
https://github.com/adafruit/Adafruit_CircuitPython_MSA301/blob/main/examples/msa301_tap_example.py

# Adafruit MSA301 Triple Axis Accelerometer

## Python Docs

# Adafruit MSA301 Triple Axis Accelerometer

## Downloads

## Files

[MSA301 Datasheet](https://github.com/adafruit/Adafruit_MSA301/blob/master/MSA301-V1.0-ENG.PDF)  
[EagleCAD files on GitHub](https://github.com/adafruit/Adafruit-MSA301-PCB)  
[3D CAD files on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/master/4344%20MSA301%20Accelerometer)  
[Fritzing object in Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/raw/master/parts/Adafruit%20MSA301.fzpz)

## Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/079/683/medium800/sensors_schematic.png?1566346844)

## Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/079/684/medium800/sensors_fab_print.png?1566346856)


## Primary Products

### Adafruit MSA301 Triple Axis Accelerometer - STEMMA QT / Qwiic

[Adafruit MSA301 Triple Axis Accelerometer - STEMMA QT / Qwiic](https://www.adafruit.com/product/4344)
[Discontinued - **you can grab** Adafruit MSA311 Triple Axis Accelerometer - STEMMA QT / Qwiic **instead!&nbsp;**](https://www.adafruit.com/product/5309)

The MSA301 is a super small and low-cost **triple-axis accelerometer**. It's inexpensive, but has...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4344)
[Related Guides to the Product](https://learn.adafruit.com/products/4344/guides)

## Featured Products

### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

In Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### Adafruit METRO 328 - Arduino Compatible - with Headers

[Adafruit METRO 328 - Arduino Compatible - with Headers](https://www.adafruit.com/product/2488)
This is the&nbsp; **Adafruit METRO Arduino-Compatible - with&nbsp;headers.&nbsp;** It's a fully assembled and tested microcontroller and physical computing board with through-hole headers attached.&nbsp; If you don't want a&nbsp;Metro with the headers attached for...

In Stock
[Buy Now](https://www.adafruit.com/product/2488)
[Related Guides to the Product](https://learn.adafruit.com/products/2488/guides)
### Adafruit Feather M4 Express - Featuring ATSAMD51

[Adafruit Feather M4 Express - Featuring ATSAMD51](https://www.adafruit.com/product/3857)
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox, half bird, OK?) This feather is powered by our new favorite chip, the **ATSAMD51J19** -&nbsp; with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3857)
[Related Guides to the Product](https://learn.adafruit.com/products/3857/guides)
### Raspberry Pi 3 - Model B - ARMv8 with 1G RAM

[Raspberry Pi 3 - Model B - ARMv8 with 1G RAM](https://www.adafruit.com/product/3055)
Did you really think the Raspberry Pi would stop getting better? At this point, we sound like a broken record, extolling on the new Pi’s myriad improvements like we’re surprised that the folks at the Raspberry Pi Foundation are continuously making their flagship board better.&nbsp;...

In Stock
[Buy Now](https://www.adafruit.com/product/3055)
[Related Guides to the Product](https://learn.adafruit.com/products/3055/guides)
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)

## Related Guides

- [Adafruit Feather M4 Express](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51.md)
- [Adafruit VCNL4040 Proximity Sensor](https://learn.adafruit.com/adafruit-vcnl4040-proximity-sensor.md)
- [CircuitPython displayio Setup for TFT FeatherWings](https://learn.adafruit.com/using-circuitpython-displayio-with-a-tft-featherwing.md)
- [Esenciales para CircuitPython](https://learn.adafruit.com/esenciales-para-circuitpython.md)
- [Air Quality Sensor 3D Printed Enclosure](https://learn.adafruit.com/air-quality-sensor-silo-house.md)
- [CircuitPython with Jupyter Notebooks](https://learn.adafruit.com/circuitpython-with-jupyter-notebooks.md)
- [Currying in CircuitPython](https://learn.adafruit.com/partials-in-circuitpython.md)
- [MIDI Solenoid Drum Kit](https://learn.adafruit.com/midi-solenoid-drum-kit.md)
- [Ocean Epoxy Resin Lightbox with RGB LED Matrix Image Scroller](https://learn.adafruit.com/ocean-epoxy-resin-lightbox-with-rgb-led-matrix-image-scroller.md)
- [Playa Festival Bike](https://learn.adafruit.com/playa-festival-bike.md)
- [Party Parrot Zoetrope](https://learn.adafruit.com/party-parrot-zoetrope.md)
- [Sketch Drawing Toy with CircuitPython](https://learn.adafruit.com/sketch-drawing-toy.md)
- [Fake TV Light for Engineers](https://learn.adafruit.com/fake-tv-light-for-engineers.md)
- [Holiday Icicle Lights with Flair](https://learn.adafruit.com/holiday-icicle-lights-with-flair.md)
- [Glitter Positioning System](https://learn.adafruit.com/glitter-positioning-system.md)
