Jouke Visser


Device::Velleman::K8055 - Communication with the Velleman K8055 USB experiment board


Version 0.02


Currently this module is just a Win32::API wrapper around the DLL that Velleman supplies with the board. Since that will only work on Win32 systems, I intend to write something myself that will be portable to other platforms...patches for this are welcome.

    use Device::Velleman::K8055 qw(:all);

    # Trying to open device 0
    die "Can't open K8055 device" unless OpenDevice(0) == 0;
    # let us flicker the Analog output leds three times each
    for (my $i = 0; $i < 3; $i++)
        for (my $j = 1; $j < 3; $j++)
            ClearAnalogChannel($j == 1 ? 2 : ($j -1));
    # clear the analog output
    # and close the device


This module consists of the functions that the K8055D.dll provides:


This opens the device, indicated by $devicenumber, which can be any value ranging from 0 to 3. The devicenumber is determined by the jumpers you set on the board. The default setting is 0.

It returns -1 if it's unsuccessful, the devicenumber that has been opened in case of success.

This function can also be used to select the active K8055 card to read and write the data. All the communication routines after this function call are addressed to this card until the other card is selected by this function call.


This closes the device. You don't need to call CloseDevice between switching of the different devicenumbers. Just call it at the end of your application.

$value = ReadAnalogChannel($channel);

This reads the value from the analog channel indicated by $channel (1 or 2). The input voltage of the selected 8-bit Analogue to Digital converter channel is converted to a value which lies between 0 and 255.

ReadAllAnalog($data1, $data2);

This reads the values from the two analog ports into $data1 and $data2.

OutputAnalogChannel($channel, $data);

This outputs $data to the analog channel indicated by $channel. The indicated 8-bit Digital to Analogue Converter channel is altered according to the new data. This means that the data corresponds to a specific voltage. The value 0 corresponds to a minimum output voltage (0 Volt) and the value 255 corresponds to a maximum output voltage (+5V). A value of $data lying in between these extremes can be translated by the following formula : $data / 255 * 5V.

OutputAllAnalog($data1, $data2);

This outputs $data1 to the first analog channel, and $data2 to the second analog channel. See OutputAnalogChannel for more information.


This clears the analog channel indicated by $channel. The selected DA-channel is set to minimum output voltage (0 Volt).


The two DA-channels are set to the minimum output voltage (0 volt).


The selected 8-bit Digital to Analogue Converter channel is set to maximum output voltage.


The two DA-channels are set to the maximum output voltage.


The channels of the digital output port are updated with the status of the corresponding bits in the $data parameter. A high (1) level means that the microcontroller IC1 output is set, and a low (0) level means that the output is cleared. $data is a value between 0 and 255 that is sent to the output port (8 channels).


This clears the digital channel $channel, which can have a value between 1 and 8 that corresponds to the output channel that is to be cleared.


This clears (sets to 0) all digital output channels.


This sets digital channel $channel to 1.


This sets all digital output channels to 1.

$value = ReadDigitalChannel($channel);

The status of the selected input $channel is read. $channel can have a value between 1 and 5 which corresponds to the input channel whose status is to be read. The return value will be true if the channel has been set, false otherwise

$value = ReadAllDigital();

This reads all 5 digital ports at once. The 5 least significant bits correspond to the status of the input channels. A high (1) means that the channel is set, a low (0) means that the channel is cleared.

$value = ReadCounter($counternumber);

The function returns the status of the selected 16 bit pulse counter. The counter number 1 counts the pulses fed to the input I1 and the counter number 2 counts the pulses fed to the input I2. The return value is a 16 bit number.

$value = ResetCounter($counternumber);

This resets the selected pulse counter.

SetCounterDebounceTime($counternumber, $debouncetime);

The counter inputs are debounced in the software to prevent false triggering when mechanical switches or relay inputs are used. The debounce time is equal for both falling and rising edges. The default debounce time is 2ms. This means the counter input must be stable for at least 2ms before it is recognised, giving the maximum count rate of about 200 counts per second. If the debounce time is set to 0, then the maximum counting rate is about 2000 counts per second.

The $deboucetime value corresponds to the debounce time in milliseconds (ms) to be set for the pulse counter. Debounce time value may vary between 0 and 5000.


Jouke, <>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


Thanks to Yaakov and Hachi from #perl on for the idea that eventually lead to buying the K8055 USB experiment board.

Most of the documentation (if not all) was derrived from the "Software manual" that comes with the K8055 board.


For more information on this board, visit


Copyright 2005 Jouke, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.