Work with IoT devices on a standard computer using CircuitPython and the Adafruit MCP2221 breakout board
The MCP2221 and FTD2302 are breakout boards that have a USB on one side and a series of structured and unstructured I/O pins on the other. The breakout boards have various GPIO, I2C other pins on them that you attach sensors, LEDs, or other components. This lets you indirectly attach GPIO inputs and outputs to a regular computer.
Adafrut's CircuitPython Blinka library emulates the CircuitPython IOT board interface that is the root of many of the Circuitpython distributions. That interface sits between standard Python and computer-attached I/O devices. It was originally designed to support the I/O pins of the Linux-based Raspberry Pi. In our case, it sits between standard Python and the I/O devices that exist on the other sides of the MCP2221 and FTD2302 breakout boards.The Stack
Python Program |
Python 3.x Runtime |
CircuitPython Framework |
Circuit Python Blinka board adapter |
Breakout Board Definition |
Individual Drivers for devices attached to the breakout board |
USB cable |
Breakout board |
Physically attached devices |
Pros and Cons
There are a couple advantages to this approach.
- You can run your control code with the comfort of all your desktop tools and computing power. Python has restrictions when running directly on Microcontrollers like the ESP32, PICO, or SAMD series of processors.
- You can run much of the same code on your development environment as you do on an IoT device as part of a faster edit/test/code cycle.
- It will not be near as real-time performant as running the code directly on a microcontroller.
- Tightly choreographed operations may be difficult due to system and communication channel overhead.
System Under Test
I purchased the Adafruit MCP2221 breakout board at Microcenter and had an I2C 16x2 LCD display from a previous project.
- https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221
- https://www.microcenter.com/product/618245/adafruit-industries-mcp2221a-breakout-general-purpose-usb-to-gpio-adc-i2c-stemma-qt-qwiic
- https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi
Video
- A PC, the MCP2221, and an Adafruit I2C panel.
- A PC, the MCP2221, and a 16x2 LCD with an PCF8574 I2C backpack - Non Adafruit driver demo
Hooking it up
This hookup will not work for SPI or LCD devices requiring many pins. There are not enough I/O lines on the breakout board for classic LCD panels, which require a bunch of extra wiring.
Sample Source Code
Problems with this Code
- Writing "Hello\nWorld" to the display took 8 seconds. Not sure if it is the nature of the connection, an issue with the LCD plate, or something else. I will update this blog if I ever figure out why.
- I got over 10 characters per second with the same hardware but this sample program and a different I2C driver and I2C backpack type for the LCD D Hylands LCD Python drivers for LCDs with PCF8574 I2C backpacks
Gratuitous Raspberry Pi connector diagram
Other Host adapters supported by Blinka
- Adafruit MCP2221A Breakout Board https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221
- Adafruit FT232H Breakout Board https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h
- Several RP2040 devices can run u2if Firmware including a Pico The u2if firmware project seems to be dead
- Great FET One from Great Scott Gadgets
- BinHo Nova Multi Protocol USB Adapter
Comments
Post a Comment