Tuesday, November 13, 2007

Interface the Velleman K8055 USB board with Matlab

After much time spent struggling to find some kind of tutorial to interface Matlab with a Velleman K8055 USB I/O board, I finally gave in and tried it myself. It actually wasn't all that hard. All that was required was the initial connection using the boards DLL. Here are the source files to download .

Included in this RAR file are the following:
  • K8055 User Manual containing all the commands that can be used
  • The M-File for Matlab
  • The Dll and header file needed to access the board
For those of you who don't know much about this really useful I/O board, check out the Velleman site.

Basically what I did was write a short M-File to connect to the board, and display, in a separate window, all the commands present in the DLL. Once the function 'K8055_Connect' is called in Matlab, the user is prompted to supply the address of the board. This is selected by placing jumpers on the board, but check the manual to see how this is done. Then, Matlab tries to connect to the board. If it is a success, a separate window will pop up giving the user a list of all the functions that can be called to access the board's many digital and analog inputs and outputs.

These functions can be called by using calllib in Matlab:

Eg: calllib('K8055D', 'SetDigitalChannel',0);

This sets the first digital output high.

The nice thing about having such a board is you can now get data live from the real world and interface it directly to Matlab. You can get your program to sense, do some calculations, plot some graphs etc, then react. The perfect toy for all your Mechatronics projects involving matlab.

If you have any problems with the code or have any improvements to the code, just let me know. Oh, and please let me know about your project using this info.



DanielDK said...

Here is a code for pearl for the Velleman board, for MAC users..


My said...

Thanks for making this. Can it work with the K8061 extended usb interface board also?

Jarrydb said...

Glad to help!

I don't think it will work as is, however, if you substituted the K8061 Dll and header file in place of the K8055 Dll, and just edited the entries in the matlab M-File pointing to the those files, it should work. I'd suspect that Velleman has kept much of their commands similar.

Let me know how it goes though.

oli said...

Hi Jarrydb,

i have another USB-Board from www.braintechnology.de Right now, i'm trying to get it work on Matlab too.

The developer provide a DLL and a header-File for including the dll in C++.

Whatever. it doesnt work with this C-Header-File.

loadlibrary('usb2.dll', 'usb2.h')
libfunctionsview usb2.dll

i get following error.
No library usb2 can be located or no functions for library usb2

So i guess it doesnt work with this Header-File. Do you have any Help for my Problem?

Best Regards

Jarrydb said...

Hi Oli

I'm not really sure. Are there possibly other DLLs out there written by third party users? I know I had problems finding a DLL and header that worked correctly.

I'll give it some thought and get back to you though.



oli said...

Hi Jarrydb,

i dont found any other DLLs for this Board. It seems nobody used this Board with Matlab till now.

Right now i'm about to install another Matlab-Version. I read in another Forum, thats this could be the Problem.

The developer himself didnt used the Board with Matlab.

Best Regards

D-Day said...

Hey jarrydb.

What you have done is awesome. Great idea.

I've just tryed this myself but i get this problem:
Channel (0-3): 0
Status: Connected to board 0
>> calllib('K8055D', 'SetAllAnalog')

Segmentation violation detected at Sun Apr 06 16:39:06 2008

The function still works it does set all analog but with that error message.

This error only occurs when I use a function that has a lib.pointer return type. this error does not occur for any other function..

Your help would be really great.


oregon intel interns said...

Do you know how to use GUI in Matlab to control this board?

grammar_tourist said...


I am working with the braintechnology usb dll in MATLAB as well. You need to create a new C header file because the one provided does not actually link to DLL files but rather uses some fancy Visual C++ function to expose them.

In your header you should declare functions like so:

__declspec(dllexport) bool __stdcall UsbInit(char DevNum);

Then you can load the library in MATLAB with loadlibrary.

This isn't working 100% for me yet, I can't figure out how to pass pointers to functions such as UsbParInitUsingArray.

Robert said...


I run the m-file, but I get an error that I don't know what to do about it:

Channel (0-3): 0
Status:Warning: The library class 'K8055D' already exists. Use a classname alias.
> In loadlibrary at 246
In K8055_Connect at 8
??? Error using ==> calllib
method was not found.

Error in ==> K8055_Connect at 9
tmp = calllib('K8055D', 'OpenDevice',ChannelAdress); % Connects to board at given address

Can anyone give me some help about this please?

Nitz76 said...

Wow! works great for me with MatLab 7.1 and my K8055. I will be able to test my code at home before going to the lab!!! Great work guys!!!

Nitz76 said...
This comment has been removed by the author.
LePapat said...

Very very interesting. Thank's a lot

ivai-cri said...


I managed to make the DLL work with the K8061 I will post to you the package soon but I have an error that I cannot solve and because of it my commands dont work:
my code line is :
and i get :
??? Attempt to reference field of non-structure arrayIf someone know what it could be ?

Thanks in advance


ch4 said...

I am a new user of the K8055
I have tried your code
the K8055_Connect.m run perfectly
but once I try calllib('K8055D', 'SetDigitalChannel',0);
I have Segmentation violation detected
Which does occur for calllib('K8055D', 'ReadAnalogChannel',2)
Could ypou help ?
Thanks and best regards

ch4 said...

I have a good answer
check this link


breban75 said...


Thank you for your contribution,but i have a problem using Matlab 2010a
when i run the .m Matlab return the following error 'K8055D.dll is not a valid win32 application'

Could somebody explain that?

Michael said...

is there a good way of how to used the K8055 in Matlab when using a MAC?

i quite don't know how to use the pearl script posted above. i would highly appreciate help on this.


eAdDYy said...

Hola soy addy, soy estudiante de mecatrónica y estoy trabajando con matlab pero aún no puedo hacer la in terfaz. Me podrías enviar tus archivos? esque el link ya no me deja descargarlos :( mi correo es : adilene.buap@gmail.com
en verdad agradecería tu apoyo
muchas gracias

ch4 said...

it's done
a bit late
hope it help

kenny said...

The file is death on rapidshare...

Can you re-upload the files?

Thank You!!


ch4 said...

As a has been IS tech, I have no idea how to up load the file
But I know how to send a mail
You can choose one of the options
best regards

ch4 said...

As an has been IS tech , I don't knwo how to up load the file. Either you tell me how to do or I can send by mail
Best regards

Carles Calafell García said...

I'm a new user of the k8055 board and I would like to start doing some projects with it. Could you send me the files? my e-mail adress is carles.calafell.garcia@gmail.com

Best Regards!

coffeeCup9NZ said...

can i please have source code too?

ch4 said...

Hi coffeeCup9NZ
just done
I have add ".com" to your mail address
Best regards

Dhanshree Kulkarni said...

hi Jarrydb,

I know its been a long time, any comment is posted on this blog, but I have got a problem somewhere related.
In place of the boards you are using above, I have a device named, Olympus EPOCH XT. It is a USB device. I connected it to MATLAB using the DLLs, the problem is I am trying to extract the data from it, but all the commands are giving blank response. There is no any error but the response is blank. The DLLs are written in c#. It is a flaw detector. Thanku for ur help in advance.