Try to avoid hot plugging I2C sensors. The MCP2221 doesn't seem to like that. Remove USB power first.

Let's talk to an I2C sensor.

We'll use the MSA301 sensor which can read acceleration. Since the MCP2221 and the MSA301 both have STEMMA QT connectors, you have two options for making the connections.

You can either wire everything up on a breadboard, like this:

Or use a STEMMA QT cable:

STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long

PRODUCT ID: 4401
This 4-wire cable is a little over 200mm / 7.8" 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...
OUT OF STOCK

STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

PRODUCT ID: 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...
OUT OF STOCK

STEMMA QT / Qwiic JST SH 4-Pin Cable

PRODUCT ID: 4399
This 4-wire cable is 50mm / 1.9" 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...
OUT OF STOCK

Install MSA301 Library

To install the MSA301 library, run the following:

Download: file
sudo pip3 install adafruit-circuitpython-msa301

Note that this step is the same as shown in the main MSA301 guide. You would do the same general process for any other sensor with a CircuitPython library.

Example Code

And then we can run the example from the library. Download it from here:

save it as msa301_simpletest.py and run it with:

Download: file
python3 msa301_simpletest.py

Pick up the board and spin it around. You should see the values change:

This guide was first published on Dec 22, 2019. It was last updated on Dec 22, 2019.
This page (I2C) was last updated on Jun 03, 2020.