FT232H - can't install python libraries

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
FelixVi
 
Posts: 8
Joined: Sat Jun 20, 2015 8:47 pm

FT232H - can't install python libraries

Post by FelixVi »

Hi,

I'm having trouble with the python libraries to use MPSSE on a PC running Ubuntu 14.04. I followed the steps provided on the website, but can't import ftdi1.

I know I am not the first person to report this, nevertheless, I think my problem is having multiple Python versions installed. The system defaul is Python 2.7, but I would like to use the library in Python 3.4.

When following the provided instructions, the lib is installed properly for Python 2.7 and works fine there. Now, how can it be installed for Python 3.4 as well? Is there configuration options to specify a Python version?

Any help is greatly appreciated!

Best,
Felix

User avatar
FelixVi
 
Posts: 8
Joined: Sat Jun 20, 2015 8:47 pm

Re: FT232H - can't install python libraries

Post by FelixVi »

*bump*

Is anybody using the library in Py3 while having Py2 installed?

Thanks!

Felix

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: FT232H - can't install python libraries

Post by adafruit_support_mike »

Most Python for the RasPi is done in version 2.7, but this post explains how to install the Python3 package manager: http://forums.adafruit.com/viewtopic.ph ... p3#p383784

User avatar
FelixVi
 
Posts: 8
Joined: Sat Jun 20, 2015 8:47 pm

Re: FT232H - can't install python libraries

Post by FelixVi »

Hi Mike,

I have the package manager installed and it's working fine. Nevertheless, I was not successful in finding the Adafruit FT232H package listed. What's the name of it for use with the package manager?

Thanks!

Felix

User avatar
FelixVi
 
Posts: 8
Joined: Sat Jun 20, 2015 8:47 pm

Re: FT232H - can't install python libraries

Post by FelixVi »

Hi Mike,

I have now reverted to Py2 in order to use the library. This helped and I am able to use is in IDLE(Py2), but when I use Spyder which came with my Anaconda the library is again not found.

Am I the only person having this problem? At least to me it seems confusing what the installer does and where it is putting files - so adding a PATH for example is difficult.

Can this problem be overcome or will I be better off using another library? So far, my project same to a stop because I can't figure out a way to get this to work.

Felix

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: FT232H - can't install python libraries

Post by tdicola »

Thanks for checking out the FT232H! Yep stick with Python 2.x for now--I'll try take a look at what's wrong with Python 3.x to see if it's easy to port, but for now it's just Python 2.x. If you're using Anaconda it sounds like it might be confused about where the library is installed. It's been a while since I've used Anaconda but does it have you run a batchfile/command to set all the environment variables to use Python? If so you'll want to run that first, and then run through the steps to install the library. That will make sure that the Python Anaconda uses is actually the one the library gets installed inside (instead of getting installed in another Python installation, like the official python.org version for example). Let me know if that helps, thanks!

User avatar
FelixVi
 
Posts: 8
Joined: Sat Jun 20, 2015 8:47 pm

Re: FT232H - can't install python libraries

Post by FelixVi »

Hi Tony,

Thanks for your reply, I think what you say makes a lot of sense. I tried to add the library's folder as a path variable but without success.

To make this easier, would you be willing to create a PyPI package so that pip can be used to install the lib? Alternatively, is there a GitHub folder so that one can just pass that as a pip parameter for installation?

I think either one option would make life a whole lot easier and resolve a lot of the "lib not found" issues that people are experiencing.

PS: Are you planning to port all the functions included in the C MPSSE library eventually? I'm still not very proficient in Python, but if you already have the imports figured out, wouldn't that be a "just" a matter of adding function wrappers?

Felix

User avatar
FelixVi
 
Posts: 8
Joined: Sat Jun 20, 2015 8:47 pm

Re: FT232H - can't install python libraries

Post by FelixVi »

Hi Tony,

To me it appears easier to install the library directly from the archive using pip. That way, the library is always installed for the current virtual environment and there seems to be no issues. Maybe adding a note to the tutorial would be a good idea.

Another thing that I can't find right now is documentation for the library. Is there a page that shows what functions have been ported and which ones haven't?

The biggest problem is device iteration. Is there any way to connect to a device with a certain serial number as you can do in the original C library? What does it take to port the library's remaining functions to Python?

Felix

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: FT232H - can't install python libraries

Post by tdicola »

Sorry catching up a little late to reply, but yeah those are great suggestion to add to PyPi to make it available with a pip install. The only tricky thing is keeping the library on PyPi up to date with the github code, but we're hoping to get some automation to help with that so we can put all the python libraries on PyPi and keep them up to date automatically. Good to hear pip install with the archive works though--that might be the easiest option for folks for now.

For documentation actually check out the docs that python will generate based on the doc strings. I tried to describe each function and its parameters so you can see how to use them. A good way to look at these docs is with the pydoc command, for example run:

Code: Select all

pydoc Adafruit_GPIO.FT232H
That should print out the class, methods, etc. and a description of them. For example:

Code: Select all

Help on module Adafruit_GPIO.FT232H in Adafruit_GPIO:

NAME
    Adafruit_GPIO.FT232H

FILE
    /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-0.9.3-py2.7.egg/Adafruit_GPIO/FT232H.py

DESCRIPTION
    # Copyright (c) 2014 Adafruit Industries
    # Author: Tony DiCola
    
CLASSES
    Adafruit_GPIO.GPIO.BaseGPIO(__builtin__.object)
        FT232H
    __builtin__.object
        I2CDevice
        SPI
    
    class FT232H(Adafruit_GPIO.GPIO.BaseGPIO)
     |  Method resolution order:
     |      FT232H
     |      Adafruit_GPIO.GPIO.BaseGPIO
     |      __builtin__.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, vid=1027, pid=24596, serial=None)
     |      Create a FT232H object.  Will search for the first available FT232H
     |      device with the specified USB vendor ID and product ID (defaults to
     |      FT232H default VID & PID).  Can also specify an optional serial number
     |      string to open an explicit FT232H device given its serial number.  See
     |      the FT232H.enumerate_device_serials() function to see how to list all
     |      connected device serial numbers.
     |  
     |  close(self)
     |      Close the FTDI device.  Will be automatically called when the program ends.
     |  
     |  get_i2c_device(self, address, **kwargs)
     |      Return an I2CDevice instance using this FT232H object and the provided
     |      I2C address.  Meant to be passed as the i2c_provider parameter to objects
     |      which use the Adafruit_Python_GPIO library for I2C.
     |  
     |  input(self, pin)
     |      Read the specified pin and return HIGH/true if the pin is pulled high,
     |      or LOW/false if pulled low.
     |  
     |  input_pins(self, pins)
     |      Read multiple pins specified in the given list and return list of pin values
     |      GPIO.HIGH/True if the pin is pulled high, or GPIO.LOW/False if pulled low.
     |  
     |  mpsse_gpio(self)
     |      Return command to update the MPSSE GPIO state to the current direction
     |      and level.
     |  
     |  mpsse_read_gpio(self)
     |      Read both GPIO bus states and return a 16 bit value with their state.
     |      D0-D7 are the lower 8 bits and C0-C7 are the upper 8 bits.
     |  
     |  mpsse_set_clock(self, clock_hz, adaptive=False, three_phase=False)
     |      Set the clock speed of the MPSSE engine.  Can be any value from 450hz
     |      to 30mhz and will pick that speed or the closest speed below it.
     |  
     |  mpsse_write_gpio(self)
     |      Write the current MPSSE GPIO state to the FT232H chip.
     |  
     |  output(self, pin, value)
     |      Set the specified pin the provided high/low value.  Value should be
     |      either HIGH/LOW or a boolean (true = high).
     |  
     |  output_pins(self, pins, write=True)
     |      Set multiple pins high or low at once.  Pins should be a dict of pin
     |      name to pin value (HIGH/True for 1, LOW/False for 0).  All provided pins
     |      will be set to the given values.
     |  
     |  setup(self, pin, mode)
     |      Set the input or output mode for a specified pin.  Mode should be
     |      either OUT or IN.
     |  
     |  setup_pins(self, pins, values={}, write=True)
     |      Setup multiple pins as inputs or outputs at once.  Pins should be a
     |      dict of pin name to pin mode (IN or OUT).  Optional starting values of
     |      pins can be provided in the values dict (with pin name to pin value).
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |  
     |  HIGH = True
     |  
     |  IN = 1
     |  
     |  LOW = False
     |  
     |  OUT = 0
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from Adafruit_GPIO.GPIO.BaseGPIO:
     |  
     |  add_event_callback(self, pin, callback)
     |      Add a callback for an event already defined using add_event_detect().
     |      Pin should be type IN.
     |  
     |  add_event_detect(self, pin, edge)
     |      Enable edge detection events for a particular GPIO channel.  Pin 
     |      should be type IN.  Edge must be RISING, FALLING or BOTH.
     |  
     |  cleanup(self, pin=None)
     |      Clean up GPIO event detection for specific pin, or all pins if none 
     |      is specified.
     |  
     |  event_detected(self, pin)
     |      Returns True if an edge has occured on a given GPIO.  You need to 
     |      enable edge detection using add_event_detect() first.   Pin should be 
     |      type IN.
     |  
     |  is_high(self, pin)
     |      Return true if the specified pin is pulled high.
     |  
     |  is_low(self, pin)
     |      Return true if the specified pin is pulled low.
     |  
     |  remove_event_detect(self, pin)
     |      Remove edge detection for a particular GPIO channel.  Pin should be
     |      type IN.
     |  
     |  set_high(self, pin)
     |      Set the specified pin HIGH.
     |  
     |  set_low(self, pin)
     |      Set the specified pin LOW.
     |  
     |  wait_for_edge(self, pin, edge)
     |      Wait for an edge.   Pin should be type IN.  Edge must be RISING, 
     |      FALLING or BOTH.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Adafruit_GPIO.GPIO.BaseGPIO:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
    
    class I2CDevice(__builtin__.object)
     |  Class for communicating with an I2C device using the smbus library.
     |  Allows reading and writing 8-bit, 16-bit, and byte array values to registers
     |  on the device.
     |  
     |  Methods defined here:
     |  
     |  __init__(self, ft232h, address, clock_hz=100000)
     |      Create an instance of the I2C device at the specified address on the
     |      specified I2C bus number.
     |  
     |  ping(self)
     |      Attempt to detect if a device at this address is present on the I2C
     |      bus.  Will send out the device's address for writing and verify an ACK
     |      is received.  Returns true if the ACK is received, and false if not.
     |  
     |  readList(self, register, length)
     |      Read a length number of bytes from the specified register.  Results
     |      will be returned as a bytearray.
     |  
     |  readRaw8(self)
     |      Read an 8-bit value on the bus (without register).
     |  
     |  readS16(self, register, little_endian=True)
     |      Read a signed 16-bit value from the specified register, with the
     |      specified endianness (default little endian, or least significant byte
     |      first).
     |  
     |  readS16BE(self, register)
     |      Read a signed 16-bit value from the specified register, in big
     |      endian byte order.
     |  
     |  readS16LE(self, register)
     |      Read a signed 16-bit value from the specified register, in little
     |      endian byte order.
     |  
     |  readS8(self, register)
     |      Read a signed byte from the specified register.
     |  
     |  readU16(self, register, little_endian=True)
     |      Read an unsigned 16-bit value from the specified register, with the
     |      specified endianness (default little endian, or least significant byte
     |      first).
     |  
     |  readU16BE(self, register)
     |      Read an unsigned 16-bit value from the specified register, in big
     |      endian byte order.
     |  
     |  readU16LE(self, register)
     |      Read an unsigned 16-bit value from the specified register, in little
     |      endian byte order.
     |  
     |  readU8(self, register)
     |      Read an unsigned byte from the specified register.
     |  
     |  write16(self, register, value, little_endian=True)
     |      Write a 16-bit value to the specified register.
     |  
     |  write8(self, register, value)
     |      Write an 8-bit value to the specified register.
     |  
     |  writeList(self, register, data)
     |      Write bytes to the specified register.
     |  
     |  writeRaw8(self, value)
     |      Write an 8-bit value on the bus (without register).
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
    
    class SPI(__builtin__.object)
     |  Methods defined here:
     |  
     |  __init__(self, ft232h, cs=None, max_speed_hz=1000000, mode=0, bitorder=0)
     |  
     |  read(self, length)
     |      Half-duplex SPI read.  The specified length of bytes will be clocked
     |      in the MISO line and returned as a bytearray object.
     |  
     |  set_bit_order(self, order)
     |      Set order of bits to be read/written over serial lines.  Should be
     |      either MSBFIRST for most-significant first, or LSBFIRST for
     |      least-signifcant first.
     |  
     |  set_clock_hz(self, hz)
     |      Set the speed of the SPI clock in hertz.  Note that not all speeds
     |      are supported and a lower speed might be chosen by the hardware.
     |  
     |  set_mode(self, mode)
     |      Set SPI mode which controls clock polarity and phase.  Should be a
     |      numeric value 0, 1, 2, or 3.  See wikipedia page for details on meaning:
     |      http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
     |  
     |  transfer(self, data)
     |      Full-duplex SPI read and write.  The specified array of bytes will be
     |      clocked out the MOSI line, while simultaneously bytes will be read from
     |      the MISO line.  Read bytes will be returned as a bytearray object.
     |  
     |  write(self, data)
     |      Half-duplex SPI write.  The specified array of bytes will be clocked
     |      out the MOSI line.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)

FUNCTIONS
    disable_FTDI_driver()
        Disable the FTDI drivers for the current platform.  This is necessary
        because they will conflict with libftdi and accessing the FT232H.  Note you
        can enable the FTDI drivers again by calling enable_FTDI_driver.
    
    enable_FTDI_driver()
        Re-enable the FTDI drivers for the current platform.
    
    enumerate_device_serials(vid=1027, pid=24596)
        Return a list of all FT232H device serial numbers connected to the
        machine.  You can use these serial numbers to open a specific FT232H device
        by passing it to the FT232H initializer's serial parameter.
    
    use_FT232H()
        Disable any built in FTDI drivers which will conflict and cause problems
        with libftdi (which is used to communicate with the FT232H).  Will register
        an exit function so the drivers are re-enabled on program exit.

DATA
    FT232H_PID = 24596
    FT232H_VID = 1027
    LSBFIRST = 1
    MSBFIRST = 0
    __loader__ = <zipimporter object "/usr/local/lib/python2.7/di...es/Ada...
    logger = <logging.Logger object>

Great question about enumeration--that was actually something I added a little bit after the tutorial, so here's quick rundown of how to use it. You can call the FT232H.enumerate_device_serials() function (which optionally takes a VID & PID to search for, but stick with the default unless you have some custom FT232H chip) and it will return a list of serial numbers for any found FT232H chips. Then you can pass one of those serial numbers to the FT232H initializer's serial parameter. For example:

Code: Select all

import Adafruit_GPIO.FT232H as FT232H

# Grab as list of all the FT232H devices and print it out.
serials = FT232H.enumerate_device_serials()
print 'Found these FT232H devices:'
for s in serials:
    print s

# Now create an FT232H instance for the first device.
ft232h = FT232H.FT232H(serial=serials[0])
Give code like that a shot and let me know if you run into issues, thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”