Set up MCP2221

This guide assumes you've set up your computer to interface with the MCP2221. If you have not yet set up the MCP2221 for your computer, click the link below and come back to this page once you have everything set up.

Install Anaconda

If you're new to all this, the Jupyter Project recommends installing Anaconda. This package installs the latest stable version of Python, Jupyter Notebook, and other commonly used packages for scientific computing and data science.

Navigate to the Anaconda downloads page, select your operating system, and download the installer including Python 3.7+.

Install the version of Anaconda you downloaded by following the executable's instructions.

Launching Jupyter Notebook

Once Anaconda is installed, open the Anaconda Navigator Application.

Under Jupyter Notebook, click Launch

We are using Jupyter Notebook for this guide. At the time of writing, Jupyter Lab has problems with displaying Matplotlib's interactive elements and real-time data animations and is not recommended for this guide.

Jupyter Notebook should open in a new web browser at the URL http://localhost:8888/notebooks. To ensure you set up the MCP2221 correctly, we created a Jupyter Notebook.

Download all the notebooks required for this project by clicking Download: Project ZIP on the upper left hand side of the embedded preview below. 

Once downloaded, unzip the file and keep it somewhere safe like on your desktop.

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python Software Package Installation\n",
    "import sys\n",
    "!{sys.executable} -m pip install adafruit-blinka adafruit-circuitpython-msa301 hidapi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set an Environment Variable so Adafruit Blinka knows we're using the MCP2221\n",
    "import os\n",
    "os.environ[\"BLINKA_MCP2221\"] = \"1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Attempt to import a CircuitPython Module\n",
    "import board"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

From Jupyter, click the Upload button.

From your file browser, navigate to and select the MCP2221_Test.ipynb file.

The Jupyter notebook should appear in the file browser. Click upload.

Once the Jupyter Notebook has been successfully uploaded, it will show up in the file browser. Click MCP2221_Test.ipynb to launch the notebook.

Code Usage

Jupyter Notebooks are split into cells. Cells may contain code, images, equations or text. This example notebook only contains code cells.

The first code cell contains two lines. The first imports the sys module which imports functions that interact with the Python interpreter. The second line installs all the dependencies we need to use this notebook with the MCP2221, including adafruit-blinka and hardware support packages. 

To execute this cell, click the first "cell" containing code. Click the run button to execute the code within the cell.

You should observe the output from the Python interpreter print out underneath the cell. Once complete, the cell should display a [1] next to it, indicating the interpreter has completed executing the cell.

The next cell will set an Environment Variable (BLINKA_MCP2221) so Adafruit Blinka knows we're using the MCP2221 board. Click the cell to highlight it, then click the run button or press ctrl/cmd+enter to execute the code within the cell.

You should get no errors at all, in which case you can continue onto the examples!

Error: Board not supported None

If you get NotImplementedError: Board not supported None,

That could mean you did not set the MCP2221 environmental variable or you don't have the latest Python libraries installed or the MCP2221 is not plugged in to USB.

Error: BLINKA_MCP2221 environment variable set, but no MCP2221 device found

If you get this error, check your USB cable - it could be that you have a charge-only not charge+sync cable. Your board may also be unplugged from USB.

This guide was first published on Dec 24, 2019. It was last updated on Dec 24, 2019.

This page (Installing Anaconda) was last updated on Oct 15, 2021.

Text editor powered by tinymce.