Let's talk to an I2C sensor!

The Pico has two I2C ports. Remember that you can attach multiple sensors to a single port as long as each has a unique I2C address. So you don't need to use two just because you have two sensors.

We'll use the MSA301 sensor which can read acceleration. Here we show wiring via the header pins. But if you wanted to use the STEMMA QT connector, you could by using one of the pigtail breakout cables.

Trying to use an I2C port with nothing attached can cause the system to hang.
I2C0 is the default port used by board.I2C() and SCL/SDA pins.

Install MSA301 Library

To install the MSA301 library, run the following:

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:

python3 msa301_simpletest.py

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

This guide was first published on May 01, 2021. It was last updated on May 01, 2021.

This page (I2C) was last updated on May 17, 2021.

Text editor powered by tinymce.