I've been taking a break from FPGA projects for the last couple of weeks. We've had hazardous air quality due to the wildfires and even indoors with a HEPA filter I've found it difficult to concentrate.
I was browsing the Adafruit store looking for a board to try running TinyML and I stumbled upon a very inexpensive MCP2221A Breakout board ($6.50) ADAFRUIT MCP2221A Breakout.
I know that shabaz and others have used the MCP2221 as a USB to UART interface on PCBs that they've built but I had never really looked at the part specification. Turns out that it is very versatile - in addition to the UART it has an I2C interface and 4 GPIO pins. The GPIO pins can also be used as 3 10 bit ADC inputs or a 5 bit DAC output. The board has a USB-C connector for the host interface and power and a Stemma-QT (QWIIC) connector to interface an I2C sensor. The MCP2221 pins are also broken out into a breadboard friendly 0.1" pattern.
Adafruit has a great tutorial on using this board with CircuitPython so that you can test sensors using your host computer (Windows, Mac, Linux) directly without needing to use a microcontroller board. What really caught my attention was the tutorial that they have on using the MCP2221 with Jupyter Notebooks and CircuitPython libraries: jupyter-on-any-computer-with-circuitpython-libraries-and-mcp2221. I've been using Jupyter Notebooks with PYNQ on the Zynq FPGA boards and I like the capability to prototype and document your code, so I thought that I'd give this a try.
The recommendation is to use Anaconda which installs Python and Jupyter Notebook. I already have a working installation of Python on my Windows 10 computer but because Anaconda includes and manages a diverse set of tools - I decided to install it as an independent framework that allows me to access the tools it is managing only through the Navigator Panel (basically just don't allow it to change PATH or Registry entries when it installs). Anaconda is an open source platform (distribution) that includes a number of preinstalled programs targeted at Data Science applications. It is supposed to handle dependency management better than the PIP package manager. If it works well I may opt in the future to use it rather than the separately installed programs.
Here's a screenshot of the Navigator Panel after installation:
Jupyter Notebook will launch in a browser window at http://localhost:8888/notebooks - you just pick which browser if you have multiple installed - I tend to use Chrome. You also need to have set up the MCP2221 with Adafruit Blinka so that it is configured for CiruitPython: circuitpython-libraries-on-any-computer-with-mcp2221/setup. When you use the MCP2221 you need to set an environment variable BLINKA_MCP2221 = 1 to identify it.
Test using BME280 I2C sensor
I decided to try using a BME280 sensor which measures temperature, humidity, and barometric pressure. The BME280 can communicate via I2C or SPI but this particular board only pins out the I2C. The sensor board also does not have a QWIIC connector so I did the hookup on a solderless breadboard.
It's easiest to use a sensor that has a CircuitPython library available. The first step is to install the appropriate library. This step is only required the first time that you use a new sensor type.
Here is the output from the Jupyter Notebook. I could have run this from a terminal but it's useful to have the installation documented.
Then set the board environment variable.
Print out the sensor readings. Altitude is computed from barometric pressure so it is somewhat inaccurate. The altitude at this location should be about 119 meters.
Display the temperature data as it's captured. I perturbed the temperature by putting my finger on the sensor.
Seems like a very useful setup to play with sensors before I try to use them in specific applications. It will also allow me to get more experience with Jupyter Notebooks and the price was certainly right for that MCP2221 breakout board !
Top Comments