Using FTDI D2XX drivers with Python from Raspberry Pi on raspbian soft-float platform

We have a USB device controlled by FTDI D2XX drivers. Currently, it is controlled from a Windows machine via the Python interface, and as a fun project I tried to move the control to the Raspberry Pi (about 1/10 of the cost of the PC, not including the cost of the OS).

There were many obstacles to clear, but after a few weeks I finally found the answers to all the questions and earned. Answers were spread over several forums, so thanks to the Stack Overflow community. I thought I was consolidating them.

Firstly, a project is required:

I downloaded the Wheezy distribution and used Win32DiskImager to write to a 4-inch SD card. Raspberry Pi booted without problems. Then I unpacked the D2XX library (libftd2xx.so) and installed it in /usr/local/lib .

PyUSB (1.6) is currently tested only for Windows, but they provide source code. It is quite simple to compile a copy for Raspberry Pi. Basically, change setup.py to reference the libftd2xx.so library (no need to copy it). Also edit d2xx / _d2xx.c to comment on procedures without implementing Linux (currently ftobj_Rescan, ftobj_Reload ftobj_GetComPortNumber). Copy the WinTypes.h and ftd2xx.h files from the FTDI D2XX driver directory (in release) to ftdi-win32 and run python setup.py install , which will compile and install the Python module.

Once all this was done, I wrote a simple Python script to talk to the FTDI chip. Please note that you need to run through sudo.

 import d2xx jd = d2xx.open(0) pd = jd.eeRead() print pd 

The d2xx module cannot find the libftd2xx.so file. So, I set up setup.py script to reference a static copy of libftd2xx.a library. Voila, I had the first key to the problem: the D2XX library was built using soft-float, and my Wheezy distribution was configured to use floating point registers. That is, gcc on my system generated code that was binary, incompatible with the D2XX libraries and did not allow them to contact.

To fix this, I downloaded the soft-float debian "wheezy" distribution (2012-08-08) and wrote a 4 GB SD card. This time the image will not load. Looking back, I found this useful answer . In short, there is a problem with the boot image for soft-float, so for some Raspberry Pi boards it does not load. The solution is to replace the start.elf file with a soft-float distribution with one that works, for example. copy from Raspbian hard floating image. Fortunately, the SD card has two sections: FAT and ext3 (?). The boot image is located in the FAT section, so it was trivial to pop up the SD card hard drive into the Windows window, copy the start.elf file, pop up on the SD card with a soft float and update its start.elf using the hard-area. After that, Raspberry Pi did not load any problems.

After installing the FTDI D2XX drivers and building the Python d2xx module from PyUSB, I tried the test script again. Again, this did not work. The d2xx module could read the libftd2xx.so library without problems, but for some reason simply could not talk to the device.

+6
source share
2 answers

I was not sure where the problem was: was it PyUSB, a problem with FTDI libftd2xx.so, or some kind of problem with the Debian distribution?

There is a test in the FTDI package under release/examples/EEPROM/read . You have to build it, but it is just a matter of input. By running it (via sudo), he was unable to open the USB device, so this is clearly not PyUSB. After I spoke, I found a link to the driver, ftdi_sio, and that it might conflict with other D2XX drivers. So, using lsmod , I saw that ftdi_sio is already installed by default, so I ran rmmod ftdi_sio . After that, everything worked. The read command should show something like this:

 Library version = 0x10112 Opening port 0 FT_Open succeeded. Handle is 0xf7d240 FT_GetDeviceInfo succeeded. Device is type 4. FT_EE_Read succeeded. Signature1 = 0 Signature2 = -1 Version = 1 VendorId = 0x0407 ProductId = 0x6009 Manufacturer = MagicIncorporated ManufacturerId = wo Description = MyCompany Test Board SerialNumber = testit_028 MaxPower = 44 PnP = 1 SelfPowered = 0 RemoteWakeup = 1 2232RC: ------- Rev5 = 0x1 IsoInA = 0x0 IsoInB = 0x0 IsoOutA = 0x0 IsoOutB = 0x0 PullDownEnable5 = 0x0 SerNumEnable5 = 0x0 USBVersionEnable5 = 0x0 USBVersion5 = 0x110 AIsHighCurrent = 0x0 BIsHighCurrent = 0x0 IFAIsFifo = 0x0 IFAIsFifoTar = 0x0 IFAIsFastSer = 0x0 AIsVCP = 0x0 IFBIsFifo = 0x0 IFBIsFifoTar = 0x0 IFBIsFastSer = 0x0 BIsVCP = 0x0 Returning 0 

I also switched from PyUSB to ftd2xx because it is pure python, but it was not necessary.

+3
source

There is a special version of libftd2xx 1.1.12 that fixes problems with raspberries pi. This will probably fix your problem.

I forgot where I found it, but I have a copy on the download page of my website, the Lightput download page .

+1
source

All Articles