Adafruit CircuitPython Libraries and Jupyter Notebook User Manual

CircuitPython Libraries and Jupyter Notebook on any Computer with
MCP2221
Created by Brent Rubell
Last updated on 2021-03-26 10:16:02 AM EDT
2 3
3 3 4
4
4
5 6
6 6 6 8 9 9
10
11 12
15
17 17 19
20
Guide Contents
Guide Contents Overview
MCP2221 CircuitPython Libraries on your Computer Jupyter Notebook
Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text.
Parts
Materials Installing Anaconda
Set up MCP2221 Install Anaconda Launching Jupyter Notebook Code Usage Error: Board not supported None Error: BLINKA_MCP2221 environment variable set, but no MCP2221 device found
Jupyter Notebook Examples
Compatibility with FT232H
Temperature
Wiring Code Walkthrough
Accelerometer
Wiring
Code Usage
Increasing the Number of Sensor Readings Code Walkthrough About Notebook Performance
Thermal Camera Wiring
Code Usage
© Adafruit Industries
https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-
mcp2221
Page 2 of 23
Overview
This guide will show you how to use Jupyter Notebook with the MCP2221(A) to connect I2C sensors from your desktop PC running Windows, macOS or Linux . You can use any CircuitPython library for any of our I2C sensors to stream data into your computer's USB port.
We've written three interactive Jupyter Notebooks for three different types of sensors - a temperature sensor, an accelerometer and a thermal camera. All of these notebooks have animated graphs so you can see data streaming into your computer in
real-time
.
This guide is also compatible with the Adafruit FT232H breakout (https://adafru.it/xhf) (EXCEPT for the MLX thermal camera example). You'll need to make a small adjustment to the code. See the Jupyter Notebook Examples page for more information (https://adafru.it/HMf).
MCP2221
Our MCP2221A breakout board (https://adafru.it/HMA) allows your computer to talk to sensors or devices that use I2C or analog/digital GPIO.
There's no firmware to deal with, so you don't have to deal with how to "send data to and from an Arduino which is then sent to and from" an electronic sensor or display or part.
This board is plug & play compatible with with all of our Stemma QT/Qwiic connector
sensors with no soldering required (https://adafru.it/HMB).
CircuitPython Libraries on your Computer
In this guide we will not be using the actual CircuitPython firmware. But we will be installing and using CircuitPython Libraries on your Computer. This allows us to interface with a growing collection of 200+ libraries and drivers.
For more information about how this works, check out the CircuitPython Libraries on MCP2221 Guide here... (https://adafru.it/HMC)
Jupyter Notebook
Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text.
You'll use Jupyter to create interactive notebooks containing live code which interfaces with your MCP2221 and sensors.
Parts
Your browser does not support the video tag. Adafruit MCP2221A Breakout - General Purpose USB to GPIO ADC I2C
Wouldn't it be cool to drive a tiny OLED display, read a Out of Stock
Out of
Stock
© Adafruit Industries
https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-
mcp2221
Page 3 of 23
Adafruit PCT2075 Temperature Sensor - STEMMA QT / Qwiic
The Adafruit PCT2075 Temperature Sensor is a 'code compatible' drop-in replacement for a very... $4.95 In Stock
Your browser does not support the video tag. Adafruit LSM6DSOX 6 DoF Accelerometer and Gyroscope
Behold, the ST LSM6DSOX: The latest in a long line of quality Accelerometer+Gyroscope 6-DOF IMUs from ST.This IMU sensor has 6 degrees of freedom - 3 degrees each of linear... $11.95 In Stock
Your browser does not support the video tag. Adafruit MLX90640 24x32 IR Thermal Camera Breakout
You can now add affordable heat-vision to your project and with an Adafruit MLX90640 Thermal Camera Breakout. This sensor contains a 24x32 array of IR thermal sensors. When connected... Out of Stock
Materials
The MCP2221A has a USB-C connector, make sure you pick up the correct cable or adapter for your computer.
1 x USB C to USB C Cable, 1 meter USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long
1 x Micro B USB to USB C Adapter Micro B USB to USB C Adapter
The sensors we selected for this guide can be used with a STEMMA QT cable so you can plug-and-play with the MCP2221's STEMMA QT port.
1 x STEMMA QT Cable, 50mm STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long
1 x STEMMA QT Cable, 100mm STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long
1 x STEMMA QT Cable, 200mm STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long
1 x STEMMA QT to Male Headers Cable, 150mm STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable - 150mm Long
Add to Cart
Add to Cart
Out of
Stock
Add to Cart
Add to Cart
Add to Cart
Add to Cart
Add to Cart
Out of
Stock
© Adafruit Industries
https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-
mcp2221
Page 4 of 23
Installing Anaconda
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.
MCP2221 Setup Page (https://adafru.it/HMD)
Install Anaconda
If you're new to all this, the Jupyter Project recommends installing Anaconda (https://adafru.it/HME). 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 (https://adafru.it/FrB), 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.
© Adafruit Industries
https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-
mcp2221
Page 5 of 23
{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Python Software Package I nstallation\n", "import sys\n", "!{sys.executable} -m pip in stall adafruit-blinka adafruit-ci rcuitpython-msa301 hidapi" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set an Environment Variab le 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 Circu itPython 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 }
© Adafruit Industries
https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-
mcp2221
Page 6 of 23
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.
© Adafruit Industries
https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-
mcp2221
Page 7 of 23
Loading...
+ 16 hidden pages