Open8055 - Getting started

Overview

Be warned, this is going to take a while. Also, before you start, make sure you have all the tools needed in later steps. Most importantly you will need a PIC programmer like a PICKIT3.

Converting a K8055 or K8055N card to Open8055 is best done in several smaller steps. In the first 3 step you install software on the PC that can communicate with all three card types and test it with your original, functioning card. The following steps then convert the card to Open8055 and use the functioning PC software to test if that worked.

One of the problems with a project like Open8055 is the number of moving parts. There is (eventually) a hardware modification, loading new firmware into a brand new PIC, changing libraries and finally changing application code to use those new libraries. Only if each single part works, the overall change will succeed. One single piece not working correctly, and the usual symptom (users report) is "doesn't work". Well, "doesn't work", while accurate, doesn't help much in pinpointing the problem. Therefore let us do the transition step by step so that if something goes wrong, we know immediately which part "didn't work".

If any of the steps "doesn't work", please stop and contact me on the Velleman Forum in the "Soldering kits" section. Do not assume that it will magically start working after more step(s).

  1. Installing Python
  2. Installing pylibusb (Unix only)
  3. Getting the pyopen8055 example.py to work
  4. Hardware Modification (K8055 only)
  5. Programming the bootloader into a PIC
  6. Programming the firmware with the bootloader




Installing Python

Much of the host side of Open8055 is written in the Python scripting language. Naturally, this tutorial is using it. So you need to have Python installed on your system.

All the following steps have been tested on multiple platforms using Python 2.6 and 2.7. If your system doesn't have Python installed yet, please visit http://python.org and follow the download/installation instructions there. Or use your usual package management tool to install it.




Installing the pylibusb module

This step is only needed on Unix type platforms, like FreeBSD and Linux. If you are using Windows as your host operating system, skip to the next step.

First install libusb on your system. The exact command to do that depends on the OS and package/ports management system, you are using. Some systems (like FreeBSD) have the libusb library already included in the base system. If your system does not, please use your usual package management tool to install libusb.

Next download the pylibusb module from http://github.com/strawlab/pylibusb. If you are familiar with GIT, then by all means clone the repository and work from there. If not, there is a button on the far right. Unpack that archive instead.

Change into the resulting ./pylibusb/ directory and execute the example.py script there with the command

    sudo python ./example.py
	
It should produce output similar to this:
    ('idVendor: 0x0e0f idProduct: 0x0002',)
    ('idVendor: 0x0e0f idProduct: 0x0003',)
    ('idVendor: 0x0000 idProduct: 0x0000',)
    ('idVendor: 0x0000 idProduct: 0x0000',)
    Traceback (most recent call last):
      File "./example.py", line 38, in 
        raise RuntimeError("Cannot find device.")
    RuntimeError: Cannot find device.
	
That "RuntimeError: Cannot find device."" at the end is perfectly fine because you most probably don't have that exact mouse device, the example.py script is based on. What you want to see is some idVendor, idProduct pairs of installed USB devices. They will look different on your system, but any output like that will tell you that pylibusb is going to work on your system.

To install this as a site-module on your system, run the command

    sudo python ./setup.py install
	




Getting the pyopen8055 example.py to work

The pyopen8055 module is code that enables the Python language to access and control K8055/VM110, K8055N/VM110N and OPEN8055 cards. It will automatically detect the type of the connected card and use the appropriate communication protocol.

The origin code repository for all of the Open8055 project is at
http://github.com/wieck/open8055. If you are not familiar with GIT, the button on the right side will let you download the current "master" branch with the latest code of everything.

After cloning/unpacking the Open8055 repository, cd to ./open8055/pyopen8055 and test if the example.py script in there can access your existing K8055/K8055N card with address 0. Use the command

    sudo python ./example.py
	
The output of the program should look something like this:
    DEBUG: ('pyopen8055.__init__("card0")',)
    DEBUG: ('_libusb_io.__init__("card0")',)
    DEBUG: ('  card_number = 0',)
    DEBUG: ('  idVendor: 0x10cf idProduct 0x5500',)
    DEBUG: ("  found device ''",)
    DEBUG: ('  attempting to switch to K8055N protocol',)
    DEBUG: ('    sending SET_PROTO',)
    DEBUG: ('    reading reply',)
    DEBUG: ('    reply card_id=11',)
    DEBUG: ('    reply card_id=21',)
    DEBUG: ('  successfully switched to K8055N protocol',)
    DEBUG: ('  card0: card_type = K8055N',)
    card0 of type 'K8055N' opened
    DIGITAL_OUT: 0
    ANALOG_OUT: (0, 0)
    IN_1: False
    A_1: 0
    
    ====================
    press digital input 5 to end example
    ====================
    
    DIGITAL: 0
    COUNTER_1: 0
    COUNTER_2: 0
    ANALOG_1: 0
    ANALOG_2: 0
	
The digital outputs will show a pattern where outputs 1, 3, 5 and 7 are on, the others are off. At this point, the program is in a loop. In this loop it will:
  • Print changes to the states of any digital input, counter 1/2 or analog input.
  • Reflect the setting of analog input A1 on output PWM1 and A2 -> PWM2 respectively.
  • Terminate when digital input I5 is pressed, setting all outputs back to off/0.


If that works it is time to install the module with the command
    sudo python ./setup.py install
	
You now have access to the K8055/K8055N card using Python.




Hardware Modification

If you are using a K8055N card there is nothing to modify. You can skip to the next step.

The older K8055 card needs two small and rather simple modifications.

  1. The resistor R35 needs to be removed. This resistor is the "USB Low Speed" pull-up resistor. The Open8055 communicates with "USB Full Speed", that the PIC18 devices are capable of. R35 is located under "IC3" next to the bridge marked "J".
  2. The 6 MHz crystal to be replaced with a 4 MHz one.




Programming the bootloader into a PIC

Now it is time to load firmware into a new PIC. The two PICs supported at this point are the PIC18F2550 and the PIC18F25K50. Both work on both cards, the K8055 and the K8055N. As the word "blank" suggests, they come completely empty from the factory. There is no firmware in them and plugging that chip into your card will do nothing. To get anything into one of those chips you will need a device called a PIC programmer. If you don't own one (or can borrow one from a friend), I strongly suggest that you get one that is a PICKIT3 or compatible. The PICKIT3 is itself PIC based and the PC side software automatically downloads and flashes the needed profile into the PICKIT3 depending on the actual chip, you want to program. If you already have a programmer or can borrow one, make sure it can program the chip you want to use. In the case of the Open8055 there is little to no difference between the two supported chips. So a good old JDM style serial PIC-PG2 will work with a PIC18F2550.

Be aware that PIC programmers do not necessarily come with a ZIF socket (or any socket) to put the chip into. Some come just with a cable that connects to an ICSP header. That header is available on the K8055N card, but not on the old K8055. It is easy to put together a breadboard assembly to build the ICSP setup.

All right, time to burn something into the PIC. The PIC programmer you have now came with some software. That software can for sure load a .HEX file (a text version of the binary code to load into the PIC). You'll figure out how to do that with your particular programmer. So what to load?

The "F" in PIC18F... stands for "Flash". The neat side effect of that is that they can (re)program themselves using only their regular supply voltage. My preferred method is to program a special "bootloader" firmware into the PIC once, then use that to load the actual Open8055 firmware via the USB connection over and over whenever I change the code. The Open8055 firmware is written in a way that the same .HEX file will work with and without a bootloader, so you don't have to use the bootloader. But it is a "pay me now or pay me later" option. You can use the programmer now to burn the bootloader, or you can use the programmer later to burn the actual Open8055 firmware. If you decide not to use the bootloader at this point, just burn the appropriate firmware .HEX file instead.

The K8055 and K8055N have subtle differences in the usage of input/output pins of the PIC. And the two chips need different configuration bits. So there are four different possible combinations:

PIC type PCB card label Bootloader .HEX Firmware .HEX
PIC18F2550 P8055-1 Bootloader PIC18F2550 P8055-1.hex Open8055_PIC18F2550_P8055-1.hex
PIC18F2550 P8055N-2 Bootloader PIC18F2550 P8055N-2.hex Open8055_PIC18F2550_P8055N-2.hex
PIC18F25K50 P8055-1 Bootloader PIC18F25K50 P8055-1.hex Open8055_PIC18F25K50_P8055-1.hex
PIC18F25K50 P8055N-2 Bootloader PIC18F25K50 P8055N-2.hex Open8055_PIC18F25K50_P8055N-2.hex

Since these are generated "binary" files, they are not part of the GIT source code repository. All 8 .HEX files as of December 13, 2013 are in this .ZIP archive:
http://jannicash.info/open8055/files/open8055-hex-files.zip.




Programming the firmware with the bootloader

If you decided to "burn" the actual firmware instead of the bootloader into the PIC, you can skip this part. You may come back later after you changed your mind and finally got the bootloader. You will probably do that if you are using the older K8055 board because to load new firmware, you can either use the bootloader and USB or you have to remove the PIC from the card, burn it, put it back in, for every little change you may try in the firmware.

You are still reading, so you chose to use the bootloader. Great! At this point you need to have the Microchip Application Libraries installed. Depending on your operating system, use the provided HID bootloder to load the firmware .HEX file from table in the previous step into the PIC.

The bootloader provided activates when card address 3 is selected (SK5 and SK6 open). So if you connect the card with both jumpers removed, it will connect as a "Microchip HID boot loader", instead of an Open8055 card. This is indicated by the card by constantly flashing LD1 and LD2.

The PC side bootloader program is found in the directory

    Microchip Solutions vYYYY-MM-DD/USB/Device - Bootloaders/HID
The Windows program for example would be
    HIDBootloader (Windows).exe
The program is very simple. There are 3 buttons at the top. One for opening the .HEX file with the firmware, one for uploading it into the PIC and one for resetting the PIC. You will use them in exactly that order and have the jumpers SK5 and SK6 put back (for card address 0) before doing the reset.

At this point the card should be connected as "Velleman Open8055".




Testing the Open8055

Go back to the pyopen8055 and run the example.py script again. It should work all the same, only that now it reports that it openend an Open8055 card and the ADC and PWM value range is from 0 to 1023.

At the point of this writing, the rest of the software in the Open8055 project is not compatible with the latest firmware and protocol changes. I will try to update everything and get it back into working order as soon as possible.