Datasheet

# Configure digital inputs and outputs using the setup function.
# Note that pin numbers 0 to 15 map to pins D0 to D7 then C0 to C7 on the board.
ft232h.setup(7, GPIO.IN) # Make pin D7 a digital input.
ft232h.setup(8, GPIO.OUT) # Make pin C0 a digital output.
# Loop turning the LED on and off and reading the input state.
print 'Press Ctrl-C to quit.'
while True:
# Set pin C0 to a high level so the LED turns on.
ft232h.output(8, GPIO.HIGH)
# Sleep for 1 second.
time.sleep(1)
# Set pin C0 to a low level so the LED turns off.
ft232h.output(8, GPIO.LOW)
# Sleep for 1 second.
time.sleep(1)
# Read the input on pin D7 and print out if it's high or low.
level = ft232h.input(7)
if level == GPIO.LOW:
print 'Pin D7 is LOW!'
else:
print 'Pin D7 is HIGH!'
Save the file and then open a command line terminal and navigate to the folder with gpio_test.py. Run the script by executing on
Windows:
python gpio_test.py
Or on Mac OSX or Linux run the script as root by executing:
sudo python gpio_test.py
You should see the LED start to blink once a second, and the state of the D7 input is also printed. For example if D7 is connected
to ground you'll see:
Press Ctrl-C to quit.
Pin D7 is LOW!
Pin D7 is LOW!
Pin D7 is LOW!
Try moving the jumper wire for D7 from ground to 5 volts. You should see the input start to read a high value:
Pin D7 is HIGH!
Pin D7 is HIGH!
Pin D7 is HIGH!
Swap the jumper wire between ground and 5 volts to see the input value change.
Let's look a little more closely at the code to understand how reading and writing digital GPIO works.
# Import standard Python time library.
import time
# Import GPIO and FT232H modules.
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.FT232H as FT232H
First the required modules are loaded for this script. The time module will be used to delay for a short period of time.
The Adafruit_GPIO and Adafruit_GPIO.FT232H modules will be imported with shorter names using the 'as' keyword. These
modules have all the logic for reading and writing GPIO on the FT232H.
# Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms.
FT232H.use_FT232H()
Next the use_FT232H() function is called to temporarily disable any FTDI serial drivers. This command is necessary on Mac or
Linux platforms because the libftdi library will interfere with the built-in FTDI serial drivers.
You don't really need to run this command on Windows because the FTDI serial driver was disabled using the Zadig tool,
however it can't hurt to call the function as it will do nothing on Windows.
© Adafruit Industries https://learn.adafruit.com/adafruit-ft232h-breakout Page 25 of 36