Adafruit FT232H User Manual

CircuitPython Libraries on any Computer with FT232H
Created by Carter Nelson
Last updated on 2020-10-23 03:43:34 PM EDT
Overview
This guide will show you how to use an FT232H to connect to I2C and SPI sensors and breakouts from your desktop
PC running Windows, Mac OSX, or Linux. The FT232H also allows for general purpose digital input and output (GPIO)
The cool part about this is that you can then use any of the CircuitPython Libraries that have been written for the
numerous sensors and breakouts.
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. To explain this
further, let's go over the main hardware platforms and explain where the FT232H fits in to all this.
CircuitPython on Microcontrollers
This is the most straight forward setup.
If you are using a microcontroller (https://adafru.it/Em8) that can run CircuitPython, then you will most likely have the
low level hardware interfaces needed to access the many sensors and other breakout boards - I2C, SPI, and GPIO.
Even better, there is most likely a CircuitPython library written for the sensor.
In this case, you simply install CircuitPython (https://adafru.it/Amd), add the libraries (https://adafru.it/ABU), and then
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 4 of 57
follow whatever guide (https://adafru.it/dIu) goes along with your sensor.
CircuitPython on Single Board Computers
This setup requires a special shim library called Blinka (https://adafru.it/EQa).
Single Board Computers (SBC), like the Raspberry Pi and Beagle, also typically have I2C, SPI, and GPIO interfaces
available. These boards are also powerful enough to run complete operating systems, like Linux. They can't run
CircuitPython directly, but generally don't need to. They can run the much larger Python implementations, like CPython.
To allow use of SBCs running Python to use CircuitPython libraries to access sensors over I2C/SPI/GPIO, the
Blinka (https://adafru.it/EQa) library was created.
In this case, you pip install Blinka (https://adafru.it/EQa), pip install libraries (https://adafru.it/Deo), and then follow
whatever guide (https://adafru.it/dIu) goes along with your sensor.
CircuitPython on Personal Computers
This is where the FT232H comes in. Here's why.
So what about your super powerful desktop or laptop PC? They can most definitely run Python. But can they also use
CircuitPython libraries and talk to I2C/SPI sensors? Can they blink LEDs? Read buttons? Generally, no. As powerful as
your Windows, Mac, or Linux PC is, it most likely does not have those low level hardware interfaces. Look on the back
of your computer. Do you see an I2C port? A SPI port? A cluster of pins labeled GPIO? Nope.
So what can we do? Well, look again at the back of your PC. See any USB ports? Most likely there are several. Heck,
there are probably even several USB ports on the front of your PC! Can we use USB? Yes, thanks to a specialized USB
bridge chip made by FTDI - the FT232H (https://adafru.it/xhf).
This will allow us to do something like this:
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 5 of 57
With FT232H support added to Blinka, we can follow a similar approach as with the SBCs. The FT232H attached to the
USB port acts as our surrogate set of low level hardware interfaces.
Neat! Let's see how we can get this all setup and working.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 6 of 57
Setup
The support for the FT232H in Blinka utilizes the pyftdi library (https://adafru.it/FVF) by eblot (https://adafru.it/FVG). This
in turn relies on a few other things, like libusb. So before we can actually use the FT232H, 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 install info from the pyftdi library itself:
https://adafru.it/FVH
https://adafru.it/FVH
But first try the install instructions on the pages that follow for your OS.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 7 of 57
Windows
Getting this all set up on Windows is not fun - but it is possible. Follow each step below to get it working on 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
Plug in FT232H & Fix Driver with Zadig
Unlike Mac or Linux, Windows doesn't like devices that are 'driverless' - every hardware device must have a driver
attached to it. To
fix
the driver on Windows, we must use a tool called Zadig
Download the appropriate Zadig tool for your version of Windows at its homepage (https://adafru.it/eaI). This tool
simplifies the installation of a libusb driver for the FT232H device.
Before you run the tool unplug all FTDI devices from your computer. This includes devices like Arduinos which include an FTDI chip as a USB to serial converter. You want to unplug these devices to make sure you don't accidentally select one with the tool and replace its driver.
After all the FTDI devices are unplugged, plug in your FT232H breakout to the computer so it is the only FTDI device
connected to the computer.
Now run the Zadig tool executable you just downloaded (there is no installation necessary, the executable is the program). Click the Options menu and select the List All Devices item below:
You only have to 'Zadig' the board once per computer. If you get another FT232H board, you will need to run
Zadig again to set the driver for the second board. Other than that, you only have to run it once.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 8 of 57
The list box of devices should populate with many devices. Select the USB Serial Converter device shown below.
Note: Make sure to select the device with Driver equal to FTDIBUS and USB ID equal to 0403 6014! If you pick the
wrong device you might accidentally uninstall another device's driver and make it inoperable.
Click the up/down arrows on the driver select box to the right of the green arrow and select the libusbK driver as
shown above.
Now click the Replace Driver button to replace the FTDI driver with the libusbK-based driver. After the driver
replacement finishes you can close Zadig tool.
To check that the driver was successfully replaced, open Device Manager from Control Panel or searching in the Start menu. You should see a new top level node libusbK devices and the USB Serial Converter underneath it as shown
below.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 9 of 57
If you see the libusb-win32 node and USB serial device, move on to the next step to install libftdi.
If you don't see the libusb-win32 node, try unplugging and plugging back in the FT232H breakout. If you still don't see
the node, run Zadig tool again and follow the steps above again to make sure you replace the FTDI driver for the
device with the libusb-win32 driver.
Install pyftdi and (fixed) pyusb
Next lets install pyusb and pyftdi. We have to do a little trickery here so before you start run
pip3 uninstall pyusb
pip3 uninstall pyftdi
(or pip instead of pip3 if that's how you have it named)
To make sure you do
not
have pyusb and pyftdi installed
Run them again to make absolutely sure!
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 10 of 57
We need to get a fork of pyusb to fix a bug that affects windows:
git clone https://github.com/minkustree/pyusb.git
Then
cd pyusb
python setup.py install
if you get a permission denied error, try
python setup.py install --user
Now you can run pip install pyftdi
Test pyusb and pyftdi
Now that you have pyusb and pyftdi installed correctly, run python and paste in the following (with the FT232H
plugged in)
import usb import usb.util dev = usb.core.find(idVendor=0x0403, idProduct=0x6014) print(dev)
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 11 of 57
You should get something like the following, not that dev is None or any other weird failure
If you get usb.core.NoBackendError: No backend available
Download libusb (https://adafru.it/LxD), uncompress it with WinRar or some other decompression tool that can open 7z
files.
If you are on 64-bit Windows, copy the MS64\dll\libusb-1.0.dll file into C:\Windows\System32 and
C:\Windows\SysWOW64I
If you are on 32-bit Windows, copy the MS32\dll\libusb-1.0.dll file into C:\Windows\System32
Install Adafruit Blinka
Run pip 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_FT232H=1
If you are using Windows Powershell, the syntax is a little different. In that case do:
$env:BLINKA_FT232H=1
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 12 of 57
Check Platform was detected
In the same command window you set BLINKA_FT232H=1 env var, run python and run
import board
dir(board)
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-on-any-computer-with-ft232h Page 13 of 57
Mac OSX
We assume you already have Python 3 and brew available on your Mac. Thankfully, setup on MacOS X is not so bad!
Note: If you are running VMWare Fusion on MacOS, then you can also try the Windows install (https://adafru.it/FX6)
process.
Install libusb
Start by installing libusb with
brew install libusb
Install pyftdi and Blinka
Then, pip3 install pyftdi which will also install some other libraries
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 14 of 57
Then pip3 install adafruit-blinka
Test!
Finally, set the environment variable with
export BLINKA_FT232H=1
and run python3. In the REPL, type
import board dir(board)
You should get no errors, and a list of the pins available
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 15 of 57
Linux
The following shows a typical run through installing and setting things up on Linux.
Install libusb
Run the following:
sudo apt-get install libusb-1.0
and answer Y to the prompt. This should install libusb.
Setup udev rules
Use a text editor to create and edit the file /etc/udev/rules.d/11-ftdi.rules and add the following contents.
# /etc/udev/rules.d/11-ftdi.rules SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", GROUP="plugdev", MODE="0666" SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6011", GROUP="plugdev", MODE="0666" SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6010", GROUP="plugdev", MODE="0666" SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6014", GROUP="plugdev", MODE="0666" SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="6015", GROUP="plugdev", MODE="0666"
Here we use nano, so run:
sudo nano /etc/udev/rules.d/11-ftdi.rules
like this:
add the contents from above:
and then press CTRL-X and Y to save and exit.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 16 of 57
The settings will take effect the next time you plug in the FT232H.
Install pyftdi
To install pyftdi and its dependencies, run:
pip3 install pyftdi
Install Blinka
To install Blinka and its dependencies, run:
pip3 install adafruit-blinka
The settings will take effect the next time you plug in the FT232H.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 17 of 57
Set environment variable
We need to manually signal to Blinka that we have a FT232H attached. To do this, we set the environment variable BLINKA_FT232H. The value doesn't matter, just use 1:
export BLINKA_FT232H=1
Run the sanity check.
Now move on to the Sanity Check section and run the commands there to make sure everything is installed correctly.
Don't forget this step. Things won't work unless BLINKA_FT232H is set.
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 18 of 57
Post Install Checks
After going through all the install steps for your OS, run this as a simple test 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 FT232H to a USB port on your PC.
Check pyftdi is installed correctly
Launch Python:
python3
and enter these commands:
from pyftdi.ftdi import Ftdi Ftdi().open_from_url('ftdi:///?')
You should get a list of connected FTDI devices. Most likely, there will be only one.
If an FTDI device can not be found for some reason, you'll see something like this:
If you get
NotImplementedError: Operation not supported or unimplemented on this platform
© Adafruit Industries https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h Page 19 of 57
Loading...
+ 38 hidden pages