Friday, June 19, 2015

Running the FF32 from Python in Windows environment




I recently discovered the Flyfish-tech FF32 device, which fulfills some functionality that I've wanted for a long time - easily interfacing programs on my Windows machine (Python scripts) with low-level communications (I2C, SPI, bit banging, ADC). This sort of thing can also be accomplished with FTDI chips but there's some extra go-betweens with the serial communcation, so I was very excited to find these parts. Unfortunately, the Python examples provided are meant to run under Linux, and it took me the better part of a day messing around with it to get it to operate under Windows. I'm writing this quick post as a guide for anyone else who might attempt this so they can avoid the same frustration. I've checked that this method works in Windows 7 and Windows 8 with Python 3.4.3 with the FF32 on firmware v0.5. I am a complete beginner with both Python and USB, so this may be obvious to others; it's written for the self-taught people like me who don't have a clue until they slog through hours of trial and error.
  1. Reinstall Python and check the box in the installer to add python.exe to the PATH variable. This is the only option in the installer that's not defaulted to yes, so I hadn't checked it the first time I installed. I'm sure there's an easier way of getting this added if you already have Python, but uninstalling and starting over was quick and easy (and makes sure you have an updated copy of Python).
  2. Open the Windows command prompt (run cmd.exe) and type "python -m pip install pyusb" to install pyusb automatically. This was an adventure in itself for me just working out how to install Python modules...
  3. Download libusb-win32 to get a very useful utility called inf-wizard.exe, which shows up in the bin folder after extracting. 
  4. Plug in the FF32 and let Windows do its automatic installation stuff - it's a generic HID so it's quick and easy
  5. Run inf-wizard as administrator (recent versions of Windows have become a real pain trying to save users from themselves...). Pick the FF32 from the list of devices. Write down the two hex values for Vendor ID and Product ID. Keep clicking through to create a .inf file and save it somewhere. On the last screen click Install Now. If it doesn't install successfully, you probably didn't run as administrator. 
  6. Use the Python examples from Flyfish as a reference only and don't even try to run them with Windows, they have to be entirely rewritten to work with pyusb. Sometime soon I'll get around to doing that and post them. 
  7. Write your script like this to get pyusb to work with the FF32. This is just a very quick example that I got working - there's lots to do to package the functions up nicely. Note the use of the Vendor and Product IDs that we wrote down earlier:


EDIT 7/31/2015: here's my library and an example application: https://github.com/tterev3/ff32

No comments:

Post a Comment