usb-rgb-ldr firmware and rainbow.py on windows

This describes how to control your board with the usb-rgb-ldr firmware using python and libusb on Windows.

It is assumed that your board is already flashed with the usb-rgb-ldr firmware...

Software Requirements

You'll need to install this software:

  • Python 2.6.x - the Python Programming Language Interpreter, Version 2.6. Yes, use version 2.6 for now since the pyusb installer cannot find a later python install as of Feb 2011. And you need 32-bit python because the pyusb installer can't find the 64-bit version and isn't compatible with it anyhow.
  • libusb-win32 - the win32 port of the libusb library providing access USB devices
  • PyUSB - python interface to the libusb library
  • rainbow.py - the program to control our AVR32 USB board

Installation Instructions

These steps have been tested on a Windows 7 64bit installation.

Python 2.6.x

Find the latest Windows 32-bit python 2.6 release on:  http://python.org/download/releases/

Download the installer by clicking on:

  • Windows x86 MSI Installer for 32bit windows
  • Windows X86-64 MSI Installer for 64bit windows - but you can't use this one simply with pyusb.

Run the installer to set up Python.

When these instructions were written, the latest version of python 2.6 was: 2.6.6


Download the latest version of libusb-win32 from:  http://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/

You need the file called: libusb-win32-bin-a.b.c.d.zip, and not libusb-win32-devel-filter...!

When these instructions were written, the latest version of libusb-win32 was:

Now we need to install the library. It needs to be installed specifically for each USB device that you want to control with libusb.

  1. unpack the .zip archive
  2. go to the bin/ directory and run program inf-wizard.exe
  3. connect your USB board
  4. in the inf-wizard you should see your board as 0x03EB - 0x2300 - AVR32 UC3 USB DEVICE if it has already been programmed. If not, it will show up with a similar name with DFU at the end.
  5. select your board and click Next
  6. review the Device Configuration and click Next
  7. you are asked to select a location to save the .inf file being created
  8. click on Install Now... to immediately install the .inf file created for your board
  9. you probably need to select Install this driver software anyway (unless you want to pay Micro$oft to register/sign your driver)

You can review that your installation was successful by opening the Windows Device Manager (or use Windows-R "devmgmt.msc" to start it). When you connect your board it should show up as: libusb-win32 devices -> AVR32 UC3 USB DEVICE. If the device is virgin, it shows up as libusb-win32 devices -> AT32UC3B DFU. If the driver wasn't installed your board probably shows up under Other Devices...


Lets download the Python wrapper for the libusb library we just installed:

  1. open  http://sourceforge.net/projects/pyusb/files/
  2. select PyUSB 0.x, not the 1.x tree...
  3. open the latest version
  4. download the .exe file called: pyusb-a.b.c.win32-py2.6.exe
  5. run the installer. It will detect your python installation and install to the lib/site-packages/ directory of it.

When these instructions were written, the latest version of PyUSB 0.x was: 0.4.3

Test what we have done so far

Open a Python shell through: Startmenu -> Python 2.6 -> IDLE (Python GUI)

At the >>> prompt enter import usb and press return. If everything is ok, nothing is printed except a new >>> prompt.

If you get an exception Importerror: No module named usb, python cannot find any module called usb. This means that the installation of PyUSB 0.x didn't work proberly...

If you get an exception complaining about DLL issues, PyUSB was probably installed ok, but that something went wrong with the installation of libusb-win32


Download rainbow.py from the source code repository or the one attached to this page: attachment:rainbow.py Download (Click on Origignal Format at the bottom of the preview page to download the file)

To run, right-click on the file rainbow.py and select Edit with IDLE

Focus the window showing the rainbow.py code (and not the Python Shell), then press F5 or click on Run -> Run Module to execute the program.

If you get an error either your board isn't connected or the drivers aren't working properly or the board has not been programmed yet with the usb-rgb-ldr firmware. Try reconnecting your board...

If everything works the RGB LED starts cycling through the HSV color space. S (saturation) and V (value, brightness) are kept at maximum and H (hue) is slowly incremented. For further infos refer to:

In the Python Shell the rainbow.py program will visualize the brightness measured with the LDR (light dependent resistor) on the board. A bar of #### signs is printed a couple of times per second.

For best results you need to calibrate the measurement: Put your finger on the LDR to make it dark, then hold the board towards a bright spot. By doing that the program can find the minimum and maximum values measured by the ADC. The bar is then scaled to fit between these two values...

To stop the display, you can press the reset button on the board (the button nearest the USB connector). Doing this should cause an exception to be thrown from rainbow.py.

rainbow.py running in IDLE on Win7