NSLU2-Linux
view · edit · print · history

How to Connect a Velleman K8055 USB Experimenter's/Breakout Board to an NSLU2 running SlugOS/BE

A Velleman k8055 USB Experimenter's Board allows you to control up to eight digital outputs plus two pulse-width modulated digital outputs. It allows you to read two digital counter inputs, two analog inputs.

There are two steps to being able to work with a Velleman k8055:

  1. Having the operating system recognise the board and give you access to it
  2. Having an executable or library that lets you or user-applications manipulate the board

Dealing with recognising the k8055 board first, plugging in the k8055's USB cable should produce a response in the SlugOS/BE's udev control system.

You can see the physical plug-in by watching the 'dmesg' command.

We need the SlugOS/BE to modify its response to plug-in to enable us to have write permissions to the k8055. To do that, we need to write a udev rule that tells udev what to do on connection. To do that, we first need to find the k8055's VendorID? and its ProductID?.

Find these parameters by running 'udevmonitor' and noting which 'usbdev#.#' number-set appears when the k8055 is plugged in. On my NSLU2, the k8055 shows up as usbdev3.2.

Once you have the usbdevice number, you can find the VendorID? and ProductID? by feeding the usbdevice number to udevinfo. Eg:

udevinfo -a -p /sys/class/usb_device/usbdev3.2/dev

shows the k8055 as 'Bus 3 Device 2: ID 10cf:5500'. That's vendorID '10cf 'and ProductID? '5500'. You can also acquire this information by manually working through the output of 'cat /proc/bus/usb/devices'.

With that VendorID? and ProductID? information, we can move on to the next step: writing a udev rule to set up access to the device on connection.

Create the following udev rule and added it to a new file: /etc/udev/rules.d/10-local.rules

SUBSYSTEM=="usb_device", SUBSYSTEMS=="usb", ATTRS{idProduct}=="5500", ATTRS{idVendor}=="10cf", \\
MODE="0666", SYMLINK+="k8055", RUN+="/usr/bin/k8055.sh"

On detection of the USB device by udev, this rule uniquely identifies the device using the idProduct and idVendor numbers. It then sets the access mode to 0666 (read and write access for everyone), it also creates a symbolic link /dev/k8055 (which will be usable). Finally the rule runs my 'beep' script located at /usr/bin/k8055.sh

Contents of /usr/bin/k8055.sh

@@#!/bin/sh \# Based on: \# http://www.nslu2-linux.org/wiki/Applications/DigitalCameraBackup

\# Called from /etc/udev/rules.d/10-local.rules /bin/beep -f 392.0 -n -f 493.9

exit 0; @@

To reload this new udev rule run:

udevcontrol reload_rules

Now run 'udevtrigger' to simulate a reconnect so that the k8055 is picked up by the new udev rule. I found I do also need to physically reconnect the k8055 to be able to write to the board.

After these steps, you should be able to hear the NSLU2 beep when the k8055 is connected.

We can now turn to being able to operate the board.

There appear to be two ways to do this. One is via a user-space executable and the other is via a library+user-space executable written by Sven Lindberg. I haven't played with Sven's library approach and I would appreciate it if anyone who has to update this how-to with information about how that went. The code for that is available at: http://libk8055.sourceforge.net/(approve sites)

For my first bite at this, I took the easy way out and used Robin Mulloy's pre-compiled k8055 executable from his blog at:

http://robin.mulloy.ca/index.php?blog=4&c=1&more=1&p=34&pb=1&tb=1(approve sites)

The pre-compiled binary is in a zip within the zip at:

http://robin.mulloy.ca/media/blogs/a/k8055-NSLU2.zip(approve sites)

Simply placing this executable in the executables path on the NSLU2 makes it available. Once it is made available, simply running the command 'k8055' will display the k8055's output. It should look something like this:

@@ k8055

499;0;128;230;9;8 @@

That output breaks down like this:

timestamp;digital;analog 1;analog 2;counter 1;counter 2

Timestamp is the number of milliseconds taken to report back the output (not the number of milliseconds between data being read and program start).

You can quickly test the effect of changing the input by pressing either of the two 'Inp1' or 'Inp2' buttons on the left of the board. Doing so should increment the final two counters by one for each press.

Now let's test writing to the k8055 board. Here it is from the horse's mouth:

@@Syntax : k8055 [-P:(number)] [-D:(value)] [-A1:(value)] [-A2:(value)] [-NUM:(number) [-DELAY:(number)]] [-DBT1?:(value)] [-BDT2?:(value)] [-reset1] [-reset2] [-debug]

    * -P:(number) Set board number 

    * -D:(value) Set digital output value (8 bits in decimal) 

    * -A1:(value) Set analog output 1 value (0-255) 

    * -A2:(value) Set analog output 2 value (0-255) 

    * -NUM:(number) Set number of measures 

    * -DELAY:(number) Set delay between two measure (in msec) 

    * -DBT1?:(value) Set debounce time for counter 1 (in msec) 

    * -DBT2?:(value) Set debounce time for counter 2 (in msec) 

    * -reset1 Reset counter 1 

    * -reset2 Reset counter 2 

    * -debug Activate debug mode@@

Let's reset the counters first by issuing:

k8055 -reset1 -reset2

which should bring both back to zero.

Now for a more exciting example:

k8055 -P:0 -D:147 -A1:25 -A2:203

The board number 'P' is set by SK5? and SK6? on the board. Both closed equals a board number of 0 - as indicated on the board itself.

Feeding decimal numbers to -D such as -D:147 - will display the binary equivalent in the column of LEDs? on the right of the board. Obviously, you can take these outputs out to MOSFETs? or relays (presumably via transistor drivers) to turn appliances on and off.

The -A1 and -A2 parameters will set a simulated analog voltage at PWM1? and PWM2?. So, if you run:

k8055 -A1:10

followed by:

k8055 -A1:128

followed by:

k8055 -A1:255

you should see the PWM1? LED glow at three levels of brightness.

Thanks to the various people who have been involved with writing Linux-usable, and NSLU2-usable, code for the k8055.

I'm interested to hear from people who have interfaced the k8055's output with switches and who have used 'Inp3', 'Inp4', and 'Inp5'. I plan to experiment with adding MOSFETs? to the output of my k8055 and will document that once I have some results.

view · edit · print · history · Last edited by Lee Kimber.
Originally by Lee Kimber.
Page last modified on June 18, 2009, at 10:02 AM