Adafruit Industries MCP2221 User Manual

CircuitPython Libraries on any Computer with MCP2221
Created by Carter Nelson
Last updated on 2021-04-26 06:05:02 PM EDT
2 4
4 4
6
6
7 7 7
8
8
8 10 10 10 10 11 11 13
13 13 14 14 14 15 15
16
16 16 17
18
18 18 18 18 19 19
19 20
20
21
21 22 23
25
27 27
29
Guide Contents Overview
CircuitPython and CircuitPython Libraries CircuitPython Libraries on Personal Computers
Setup
Additional Information
Windows Have Python 3 Installed Install hidapi
Install Blinka
Set Environment Variable Check Platform was detected Mac OSX Python 3 Check Install hidapi Install Blinka Set Environment Variable Check that Platform was detected Linux
Install libusb and libudev Setup udev rules Install hidapi Remove Native MCP2221 Driver Install Blinka Set environment variable Run the sanity check.
Post Install Checks
Check that hidapi is installed correctly Check that MCP2221 can be found Check environment variable within Python
Pinout
Power Pins GPIO Pins I2C Pins UART Pins ADC Pins DAC Pins
Logic Level Examples
Installing Libraries for Breakouts
GPIO
Digital Output Digital Input Digtal Input and Output
I2C
Install MSA301 Library Example Code
ADC
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 2 of 43
31 32
32 32 32 33
35
35 35 35 35 36 36 37 37
37
37
42 42
DAC UART
Install pySerial Find COM port in Linux Find COM port in Windows UART Example with GPS
FAQ & Troubleshooting
Update Blinka/Platform Libraries Getting an error message about "board" not found or "board" has no attribute Mixed SPI mode devices Why am I getting AttributeError: 'SpiDev' object has no attribute 'writebytes2'? No Pullup/Pulldown support on some linux boards or MCP2221 Getting OSError: read error with MCP2221 Using FT232H with other FTDI devices. I can't get neopixel, analogio, audioio, rotaryio, displayio or pulseio to work! Help, I'm getting the message "error while loading shared libraries: libgpiod.so.2: cannot open shared object file: No such file or directory" When running the libgpiod script, I see the message: configure: error: "libgpiod needs linux headers version >= v5.5.0"
Downloads Schematic and Fab Print
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 3 of 43
Overview
This guide will show you how to use an MCP2221(A) to connect to I2C sensors and breakouts from your desktop PC running Windows, Mac OSX, or Linux. The MCP2221 also allows for general purpose digital input and output (GPIO) for things like buttons and LEDs, analog to digital conversion (ADC), and digital to analog (DAC).
The cool part about this is that you can then use any of the CircuitPython Libraries that have been written for the numerous I2C sensors and breakouts. You can bring that data directly into your PC for any kind of powerful analysis or presentation.
Our breakout uses the MCP2221A chip, but we may refer to it as MCP2221 as the difference are not relevant to using Blinka/CircuitPython libraries and use can use either version of the chip!
CircuitPython and CircuitPython Libraries
As you are going through this guide, keep in mind the difference between CircuitPython and CircuitPython Libraries:
CircuitPython - a microprocessor specific implementation of Python written in C. Here's the source
code (https://adafru.it/tB7). And here's the main CircuitPython guide (https://adafru.it/cpy-welcome).
CircuitPython Libraries - sensor and breakout specific code written in Python using the CircuitPython hardware API. There are a lot of these - check out the bundle (https://adafru.it/zdx).
There are various hardware combinations that allow for running CircuitPython and CircuitPython Libraries. In this guide we will not be using the actual CircuitPython firmware. But we will be using CircuitPython Libraries.
CircuitPython Libraries on Personal Computers
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 4 of 43
This is essentially the same idea as discussed in the FT232H Guide (https://adafru.it/GNe). How can we directly connect common hardware items like buttons and I2C breakouts to a PC?
The MCP2221 provides another way to do this by utlizing the USB bus. The MCP2221 just makes different trade offs relative to the FT232H. The biggest being no hardware SPI support . But you do gain ADC and DAC support. Also, it's much cheaper than the FT232H.
So you end up with something like this:
Great! Let's get everything setup so we can actually do some fun stuff.
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/circuitpython-libraries-on-any-computer-with-mcp2221 Page 5 of 43
Setup
The support for the MCP2221 in Blinka utilizes the hidapi library (https://adafru.it/HEI). This in turn relies on a few other things which vary for different OS's. So before we can actually use the MCP2221, we need to get everything setup. See the OS specific sections for what we went through to get things working for each.
Additional Information
Just for reference, here's the README from the hidapi source code repo, which has some install information:
https://adafru.it/HEJ
But first try the install instructions on the pages that follow for your OS.
https://adafru.it/HEJ
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 6 of 43
Windows Have Python 3 Installed
We assume you already have Python 3 installed on your computer. Note we do not support Python 2 - it's deprecated and no longer supported!
At your command line prompt of choice, check your Python version with python --version
Install hidapi
From the command line, manually install hidapi with
pip3 install hidapi
If the install fails with text that ends with something like:
distutils.errors.DistutilsError: Setup script exited with error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools":
https://visualstudio.microsoft.com/downloads/ (https://adafru.it/JBp)
then you will need to also install the Microsoft Visual C++ Build Tools. Thanks to @jklem for pointing this out in the forums (https://adafru.it/doW).
Download it from here (same link as in text):
https://adafru.it/JBp
NOTE: You do not need the full Visual Studio IDE. Just the Build Tools.
https://adafru.it/JBp
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 7 of 43
Scroll down to where it says Tools for Visual Studio
2019.
Expand the list to show the sub options. Click the Download button for Build Tools for Visual Studio 2019.
This downloads a .exe file with a name like vs_BuildTools.exe. Run that to install the build tools and then try the pip install again.
Install Blinka
To install Blinka and its dependencies, run:
pip3 install adafruit-blinka
Set Environment Variable
You must do this every time before running circuitpython code, you can set it permanently in windows if you like, for now just type into the same cmd window you're using with Python
set BLINKA_MCP2221=1
If you are using Windows Powershell, the syntax is a little different. In that case do:
$env:BLINKA_MCP2221=1
Check Platform was detected
In the same command window you set BLINKA_MCP2221=1 env var, run python and run
import board
dir(board)
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 8 of 43
at the Python REPL. If you get no errors, and you see a list of all the pins available - you're good to go!
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 9 of 43
Mac OSX Python 3 Check
We assume you already have Python 3 installed on your computer. Note we do not support Python 2 - it's deprecated and no longer supported!
At your command line prompt of choice, check your Python version with python3 --version
Install hidapi
From the command line, manually install hidapi (https://adafru.it/HIA) with:
pip3 install hidapi
Install Blinka
To install Blinka (https://adafru.it/BJX) and its dependencies, run:
pip3 install adafruit-blinka
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 10 of 43
Set Environment Variable
You'll need to set this variable every time before running CircuitPython code. To do this, we set the environment variable to BLINKA_MCP2221.,
You can set the variable by running:
export BLINKA_MCP2221="1"
Then, verify that the variable is set by running:
echo $BLINKA_MCP2221
Don't forget this step. Things won't work unless BLINKA_MCP2221 is set.
Check that Platform was detected
In the same terminal window you ran export BLINKA_MCP2221="1" , run python3 .
At the REPL, run:
import board
dir(board)
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 11 of 43
If you get no errors and see a list of all the pins available, you're good to go!
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 12 of 43
Linux
The following shows a typical run through installing and setting things up on Linux.
Install libusb and libudev
Run the following:
sudo apt-get install libusb-1.0 libudev-dev
and answer Y to the prompt. This should install libusb and libudev.
Setup udev rules
Use a text editor to create and edit the file /etc/udev/rules.d/99-mcp2221.rules and add the following contents.
SUBSYSTEM=="usb", ATTRS{idVendor}=="04d8", ATTR{idProduct}=="00dd", MODE="0666"
Here we use nano, so run:
like this:
and add the contents from above:
and then press CTRL-X and Y to save and exit.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 13 of 43
The settings will take effect the next time you plug in the MCP2221.
Install hidapi
To install hidapi, run:
pip3 install hidapi
Remove Native MCP2221 Driver
Starting with Linux Kernel 5.7 , a native MCP2221 is included with the installation. It can be removed with:
sudo rmmod hid_mcp2221
And then excluded from loading at boot by adding the line below to /etc/modprobe.d/blacklist.conf
blacklist hid_mcp2221
Install Blinka
To install Blinka and its dependencies, run:
pip3 install adafruit-blinka
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 14 of 43
Set environment variable
We need to manually signal to Blinka that we have a MCP2221 attached. To do this, we set the environment variable BLINKA_MCP2221. The value doesn't matter, just use 1:
export BLINKA_MCP2221=1
Don't forget this step. Things won't work unless BLINKA_MCP2221 is set.
Run the sanity check.
Now move on to the Post Install Checks section and run the commands there to make sure everything is installed correctly.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 15 of 43
Post Install Checks
After going through all the install steps for your OS, run these checks as simple tests to make sure everything is installed correctly. See the rest of the page for some potential hiccups you may run into.
Go ahead and plug in your MCP2221 to a USB port on your PC.
Most of these tests are done via the Python REPL, at the >>> prompt. To get there, simply launch Python:
$ python3 Python 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
Check that hidapi is installed correctly
At the Python REPL, type:
import hid hid.enumerate()
You should get a dump of everything attached to your USB ports.
Check that MCP2221 can be found
At the Python REPL, type:
import hid device = hid.device() device.open(0x04D8, 0x00DD)
it should run without any errors:
If for some reason the MCP2221 can not be found, you might see something like this:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 16 of 43
Check your USB cable connection.
Check environment variable within Python
At the Python REPL, type:
import os os.environ["BLINKA_MCP2221"]
If you get a KeyError it means you did not set the environment variable right:
If you have set it correctly, you'll get a value back:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 17 of 43
Pinout
The logic level is set to 3.3V by default.
Power Pins
5V - this is the 5V power from the USB input. 3V - this is the 3.3V power output from the voltage regulator. GND - this is the common ground for all power and logic. RST - reset pin, pulled high internally, set low to reset
GPIO Pins
G0 to G3 - can be used as either digital inputs or outputs, logic level is 3.3V by default but can be changed to 5V
The GPIO pins do not have internal pull-up or pull-down support! If you need pull resistors, add them externally.
I2C Pins
SCL - the I2C clock signal, there's a 5.1K pullup resistor on this pin to whatever the logic level is (default 3.3V) SDA - the I2C data signal, there's a 5.1K pullup resistor on this pin to whatever the logic level is (default 3.3V)
UART Pins
TX - transmit (out from board)
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 18 of 43
RX - receive (in to board)
The uart is totally separate from the GPIO pins, it's controlled as a USB CDC device not as the USB HID interface so it shows up as a serial COM/tty port like any other USB-to-serial converter
ADC Pins
ADC1 to ADC3 - can be used as analog inputs (10 bit)
DAC Pins
DAC - there is a single 5 bit DAC which outputs on both of these pins
Logic Level
The default logic level is 3.3V - this is for digital, analog, I2C and UART data. You can change it to 5V by cutting the jumper on the bottom from 3V and soldering it to the 5V side:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 19 of 43
Examples
All right, now that all that annoying install stuff is done, let's have some fun.
The following sections will provide some basic examples for the main use cases - GPIO, I2C, ADC, and DAC.
Make sure you've set the BLINKA_MCP2221 environment variable.
Installing Libraries for Breakouts
The general process for installing the CircuitPython library you are interested in will be the same as shown in the Python section of the Learn guide for your sensor. Just use pip3 .
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 20 of 43
GPIO
Digital Output
Let's blink a LED!
Here's the bread board layout. The resistor can be something around 1kOhm. We don't need to make the LED super bright.
First, let's do things interactively so you can see how it all works one line at a time. Start by launching Python:
python3
Then, at the Python >>> prompt, enter the following to import the needed modules:
import board import digitalio
Next we'll create our LED digital pin and set the mode to output:
led = digitalio.DigitalInOut(board.G0) led.direction = digitalio.Direction.OUTPUT
And that should be it. You should be able to turn ON the LED with:
led.value = True
And turn it OFF with:
led.value = False
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 21 of 43
And here's a complete blink program you can run to make the LED blink forever.
import time import board import digitalio
led = digitalio.DigitalInOut(board.G0) led.direction = digitalio.Direction.OUTPUT
while True: led.value = True time.sleep(0.5) led.value = False time.sleep(0.5)
Save it as something like blink.py and then you can run it with:
python3 blink.py
The LED should blink on and off.
Digital Input
Let's read a button!
Here's the bread board layout. Use something like a 10kOhm resistor.
The GPIO pins do not have internal pull-up or pull-down support! If you need pull resistors, add them externally as shown here!
We'll do this interactively also. So launch python:
python3
Then, at the Python >>> prompt, enter the following to import the needed modules:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 22 of 43
import board import digitalio
And now we create our button digital pin and set it to input.
button = digitalio.DigitalInOut(board.G0) button.direction = digitalio.Direction.INPUT
And that's it. To read the current state of the button use:
button.value
This will return False when the button is not pressed and True when it is pressed.
Digtal Input and Output
Ok, let's put those two together and make the button turn on the LED. So we'll use two digital pins - one will be an input (button) and one will be an output (LED).
Here's the bread board layout.
And here's the code.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 23 of 43
import board import digitalio
led = digitalio.DigitalInOut(board.G0) led.direction = digitalio.Direction.OUTPUT
button = digitalio.DigitalInOut(board.G1) button.direction = digitalio.Direction.INPUT
while True: led.value = button.value
Save that to a file with a name like button_and_led.py and then you can run it with:
python3 button_and_led.py
and the button should turn on the LED when pressed.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 24 of 43
I2C
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 (https://adafru.it/FDy) which can read acceleration. Since the MCP2221 and the MSA301 both have STEMMA QT (https://adafru.it/Ft4) 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:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 25 of 43
STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long
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
Out of
Stock
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 26 of 43
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
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... $0.95 In Stock
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 (https://adafru.it/HEK). 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:
https://adafru.it/HEL
save it as msa301_simpletest.py and run it with:
Out of
Stock
Add to Cart
https://adafru.it/HEL
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 27 of 43
python3 msa301_simpletest.py
Pick up the board and spin it around. You should see the values change:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 28 of 43
ADC
Let's read an analog signal!
For this, we'll use a small 10k trim pot (https://adafru.it/tba) to set up a voltage divider. Here's the wiring diagram:
And here's the code:
import time import board from analogio import AnalogIn
knob = AnalogIn(board.G1)
def get_voltage(raw): return (raw * 3.3) / 65536
while True: raw = knob.value volts = get_voltage(raw) print("raw = {:5d} volts = {:5.2f}".format(raw, volts)) time.sleep(0.5)
Save that as something like adc.py and then run it with:
python3 adc.py
Spin the knob and the values should change.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 29 of 43
Note that even though the MCP2221's ADC is only 10 bits, the value is scaled to 16 bits to comply with the CircuitPython API.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 30 of 43
DAC
Let's generate an analog signal!
Well, don't get too excited. There's only a single DAC and it's a whopping 5 bits! So don't expect super awesome high fidelity audio block rockin' beats or anything.
Here's a simple sine wave generator you can try:
import time import math import board from analogio import AnalogOut
dac = AnalogOut(board.G3)
while True: dac.value = int((2**16 - 1) * (0.5 + 0.5 * math.sin(time.monotonic()*10)))
Save that as something like dac.py and run it with:
python3 dac.py
And connect the G3 pin to an oscilloscope. You should see something like this:
Note that even though the MCP221's DAC is only 5 bits, you set it using a 16 bit value to comply with the CircuitPython API.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 31 of 43
UART
But wait! There's more!
The MCP2221 also provides a USB-to-UART bridge capability. When you plug in the MCP2221, it will show up as two devices:
HID Device - This is what we used for GPIO/I2C/SPI/ADC/DAC CDC Device - This is how you use the UART
We've already covered all the cool stuff the HID interface provides. So it's this second item were are interested in here. It is how you can use the TX and RX pins on the MCP2221 breakout.
Install pySerial
We will use the Python library pySerial to access the MCP2221's UART. So, first install that. Here's a link to installation instructions from the libraries homepage:
https://adafru.it/IQA
Find COM port in Linux
After plugging in the MCP2221, run dmesg and look in the output.
dmesg | tail
Like this:
Look for something with a name like ttyACMx. An entry for that device will have been created in your /dev folder. So in your code, you'll want to use /dev/ttACMx (replace x with the number). In the example output
above, the MCP2221's UART is available on /dev/ttyACM0 . It may be slightly different on your specific linux set up.
Find COM port in Windows
After plugging in the MCP2221, look in Device Manager under Ports (COM & LPT) . If you already have a lot of entries there, it may help to also look before plugging in the MCP2221. That way you can compare and look for the new entry.
It should show up as something like this:
https://adafru.it/IQA
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 32 of 43
In the above example, it shows up as COM3 . That's the value you'll use in your code.
UART Example with GPS
In this example we show how to use the MCP2221's UART to talk to an Ultimate GPS Breakout
Module (https://adafru.it/C7F). Here is how to wire the GPS module to the MCP2221.
Once you've found your COM port and have the MCP2221 and GPS breakout wired as above, you can then follow the example here:
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 33 of 43
https://adafru.it/H3E
NOTE: You will have to make some changes to the code.
You will want to follow the same general information as for the Raspberry Pi. So comment / uncomment the code as described so that you are using pySerial. Then, when you open the serial port, use the information above for your specific COM port location.
For example, on linux it will generally look the same as the Raspberry Pi example:
import serial uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=10)
On Windows, you'll want use something like this:
import serial uart = serial.Serial("COM3", baudrate=9600, timeout=10)
And that should be it. If you run the example, it should use the MCP2221's UART to talk to the GPS and evenutally, once it gets a fix, you should see GPS output.
https://adafru.it/H3E
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 34 of 43
FAQ & Troubleshooting
There's a few oddities when running Blinka/CircuitPython on linux. Here's a list of stuff to watch for that we know of!
This FAQ covers all the various platforms and hardware setups you can run Blinka on. Therefore, some of the information may not apply to your specific setup.
Update Blinka/Platform Libraries
Most issues can be solved by forcing Python to upgrade to the latest blinka / platform-detect libraries. Try running
sudo python3 -m pip install --upgrade --force-reinstall adafruit-blinka Adafruit-PlatformDetect
Getting an error message about "board" not found or "board" has no attribute
Somehow you have ended up with either the wrong board module or no board module at all.
DO NOT try to fix this by manually installing a library named board . There is one out
there (https://adafru.it/NCE) and it has nothing to do with Blinka. You will break things if you install that
library!
The easiest way to recover is to simply force a reinstall of Blinka with:
python3 -m pip install --upgrade --force-reinstall adafruit-blinka
Mixed SPI mode devices
Due to the way we share an SPI peripheral, you cannot have two SPI devices with different 'mode/polarity' on the same SPI bus - you'll get weird data
95% of SPI devices are mode 0, check the driver to see mode or polarity settings. For example:
LSM9DS1 is mode 1 (https://adafru.it/NCF), please use in I2C mode instead of SPI MAX31865 is phase 1 (https://adafru.it/NCG), try using this on a separate SPI device, or read data
twice.
Why am I getting AttributeError: 'SpiDev' object has no attribute 'writebytes2'?
This is due to having an older version of spidev (https://adafru.it/JEi). You need at least version 3.4. This should have been taken care of (https://adafru.it/NCH) when you installed Blinka, but in some cases it does not seem to happen.
To check what version of spidev Python is using:
$ python3
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 35 of 43
Python 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import spidev >>> spidev.__version__ '3.4' >>>
If you see a version lower then 3.4 reported, then try a force upgrade of spidev with (back at command line):
sudo python3 -m pip install --upgrade --force-reinstall spidev
No Pullup/Pulldown support on some linux boards or MCP2221
Some linux boards, for example, AllWinner-based, do not have support to set pull up or pull down on their GPIO. Use an external resistor instead!
Getting OSError: read error with MCP2221
If you are getting a stack trace that ends with something like:
return self._hid.read(64) File "hid.pyx", line 122, in hid.device.read OSError: read error
Try setting an environment variable named BLINKA_MCP2221_RESET_DELAY to a value of 0.5 or higher.
Windows:
set BLINKA_MCP2221_RESET_DELAY=0.5
Linux:
export BLINKA_MCP2221_RESET_DELAY=0.5
This is a value in seconds to wait between resetting the MCP2221 and the attempt to reopen it. The reset is seen by the operating system as a hardware disconnect/reconnect. Different operating systems can need different amounts of time to wait after the reconnect before the attempt to reopen. Setting the above environment variable will override the default reset delay time, allowing it to be increased as needed for different setups.
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 36 of 43
Using FT232H with other FTDI devices.
Blinka uses the libusbk driver to talk to the FT232H directly. If you have other FTDI devices installed that are using the FTDI VCP drivers, you may run into issues. See here for a possible workaround:
https://forums.adafruit.com/viewtopic.php?f=19&t=166999 (https://adafru.it/doW)
I can't get neopixel, analogio, audioio, rotaryio, displayio or pulseio to work!
Some CircuitPython modules like may not be supported.
Most SBCs do not have analog inputs so there is no analogio Few SBCs have neopixel support so that is only available on Raspberry Pi (and any others that have low level neopixel protocol writing
Rotary encoders ( rotaryio ) is handled by interrupts on microcontrollers, and is not supported on SBCs at this time
Likewise pulseio PWM support is not supported on many SBCs, and if it is, it will not support a carrier wave (Infrared transmission)
For display usage, we suggest using python Pillow library or Pygame , we do not have displayio support
We aim to have, at a minimum, digitalio and busio (I2C/SPI). This lets you use the vast number of driver libraries
For analog inputs, the MCP3xxx library (https://adafru.it/CPN) will give you AnalogIn objects. For PWM outputs, try the PCA9685 (https://adafru.it/tZF). For audio, use pygame or other Python3 libraries to play
audio.
Some libraries, like Adafruit_CircuitPython_DHT (https://adafru.it/Beq) will try to bit-bang if pulsein isn't available. Slow linux boards (<700MHz) may not be able to read the pins fast enough), you'll just have to try!
Help, I'm getting the message "error while loading shared libraries: libgpiod.so.2: cannot open shared object file: No such file or directory"
It looks like libgpiod may not be installed on your board.
Try running the command: sudo apt-get install libgpiod2
When running the libgpiod script, I see the message: configure: error: "libgpiod needs linux headers version >= v5.5.0"
Be sure you have the latest libgpiod.sh script and run it with the -l or --legacy flag:
./libgpiod.sh --legacy
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 37 of 43
All Raspberry Pi Computers Have:
1 x I2C port with busio (but clock stretching is not supported in hardware, so you must set the I2C bus speed to 10KHz to 'fix it') 2 x SPI ports with busio 1 x UART port with serial - note this is shared with the hardware console
pulseio.pulseIn using gpiod neopixel support on a few pins
No AnalogIn support (Use an MCP3008 or similar to add ADC) No PWM support (Use a PCA9685 or similar to add PWM)
Google Coral TPU Dev Boards Have:
1 x I2C port with busio 1 x SPI ports with busio 1 x UART port with serial - note this is shared with the hardware console 3 x PWMOut support pulseio.pulseIn using gpiod No NeoPixel support No AnalogIn support (Use an MCP3008 or similar to add ADC)
Orange Pi PC Plus Boards Have:
1 x I2C port with busio 1 x SPI ports with busio 1 x UART port with serial pulseio.pulseIn using gpiod No NeoPixel support No AnalogIn support (Use an MCP3008 or similar to add ADC) No PWM support (Use a PCA9685 or similar to add PWM)
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 38 of 43
Orange Pi R1 Boards Have:
1 x I2C port with busio 1 x SPI port with busio 1 x UART port with serial No NeoPixel support No AnalogIn support (Use an MCP3008 or similar to add ADC) No PWM support (Use a PCA9685 or similar to add PWM)
Odroid C2 Boards Have:
1 x I2C port with busio No SPI support 1 x UART port with serial - note this is shared with the hardware console No NeoPixel support No AnalogIn support (Use an MCP3008 or similar to add ADC) No PWM support (Use a PCA9685 or similar to add PWM)
DragonBoard 410c Boards Have:
2 x I2C port with busio 1 x SPI port with busio 1 x UART port with serial No NeoPixel support No AnalogIn support (Use an MCP3008 or similar to add ADC) No PWM support (Use a PCA9685 or similar to add PWM)
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 39 of 43
NVIDIA Jetson Nano Boards Have:
2 x I2C port with busio 2 x SPI ports with busio 2 x UART port with serial - note one of these is shared with the hardware console No NeoPixel support No AnalogIn support (Use an MCP3008 or similar to add ADC) No PWM support (Use a PCA9685 or similar to add PWM)
FT232H Breakouts Have:
1x I2C port OR SPI port with busio 12x GPIO pins with digitalio No UART No AnalogIn support No AnalogOut support No PWM support
If you are using Blinka in FT232H mode (https://adafru.it/FWD), then keep in mind these basic limitations.
SPI and I2C can not be used at the same time since they share the same pins. GPIO speed is not super fast, so trying to do arbitrary bit bang like things may run into speed issues. There are no ADCs. There are no DACs. UART is not available (its a different FTDI mode)
MCP2221 Breakouts Have:
1x I2C port with busio 4x GPIO pins with digitalio 3x AnalogIn with analogio 1x AnalogOut with analogio 1x UART with pyserial No PWM support No hardware SPI support
If you are using Blinka in MCP2221 mode, then keep in mind these basic limitations.
GPIO speed is not super fast, so trying to do arbitrary bit bang like things may run into speed issues. UART is available via pyserial , the serial COM port shows up as a second USB device during enumeration
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 40 of 43
Downloads
Files:
MCP2221 Datasheet (https://adafru.it/L2C) EagleCAD files on GitHub (https://adafru.it/HFA) Fritzing object in Adafruit Fritzing Library (https://adafru.it/HFB)
Schematic and Fab Print
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 41 of 43
© Adafruit Industries https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221 Page 42 of 43
© Adafruit Industries Last Updated: 2021-04-26 06:05:02 PM EDT Page 43 of 43
Loading...