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:
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:
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. 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:
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.