Search in Pinguino World !!

Thursday, March 5, 2009

Pinguino with Processing

I tried to connect Pinguino with Processing with the LibUSB java wrapper. It works without problem. This is the Processing test sketch:

// This is a simple example to communicate with Pinguino
// based on the LibusbJava wrapper
// Jean-Pierre MANDON 05/03/2009

import ch.ntb.usb.Device;
import ch.ntb.usb.USB;
import ch.ntb.usb.USBException;
import ch.ntb.usb.logger.LogUtil;

// define Pinguino Product ID and Vendor ID
int VID = 0x04D8;
int PID = 0xFEAA;
// declare public USB device
Device Pinguino;
// declare output buffer
byte[] data = new byte[] { 'W', -1 };

void setup()
LibusbJava.usb_init(); // init libusbjava
LibusbJava.usb_find_busses(); // find all usb busses
LibusbJava.usb_find_devices(); // find all devices
try {
Pinguino=USB.getDevice( (short) VID , (short) PID ); // create a new device,0,-1); // try to open it ( configuration 3, interface 0 )
println("Pinguino found"); // it's OK
catch (USBException e) // error
println("Pinguino not found"); // Pinguino is not connected !!

byte lastposition=-1;
byte position;

void draw()
rect(mouseX,40,20,20); // draw a rectangle
position=byte(mouseX/50); // position modulo 8
if (position!=lastposition)
try {
if (lastposition!=-1) data[1]=lastposition;
else data[1]='C'; // WC clear all leds
Pinguino.writeBulk(0x01,data,2,200,false); // send command to Pinguino
data[1]=position; // led to be lighted
Pinguino.writeBulk(0x01,data,2,200,false); // send command
catch (USBException e) {}

void stop()
data[1]='C'; // clear all when stop
try {
catch (USBException e) {}

Now this is the Pinguino side:

// test Pinguino with Processing
// Jean-Pierre MANDON 2009

int i;
uchar caractere,caractere1;

void setup()
for (i=0;i<8;i++)

void loop()
if (USB.available())
if (caractere=='W') if (USB.available())
if (caractere1=='C')
for (i=0;i<8;i++) digitalWrite(i,LOW);

And you can see the result here.


José Luis said...

Hello, I'm José Luis. A secondary teacher from Spain. I've made the Pinguino board to see if it is an interesting option to teach my students microcontrollers. I'm trying to run the Processing program to comunicate with the board. I've put the ch.ntb.usb-0.5.9 library but when I try to compile, I get the error: Cannot find anything named "LibusbJava" and the compiler stop at the line: LibusbJava.usb_init(); // init libusbjava. I'm very newbie in Java and Processing ( I program in C )and I dont know how to solve the error. Anybody can help me?. Thanks in advance. This year I've teach Arduino to my students but y would like starts with Pinguino to wortk with the USB. I think Pinguino will be a good project to teaching.

José Luis said...

I amswer myself. I add the line import ch.ntb.usb.LibusbJava; and the Sketch works. Now I can see "Pinguino found" in processing but nothing in the Pinguino board. I had to change the line (3,0,-1); to,0,-1); because processing didn't find Pinguino.

José Luis said...

I'm José Luis again. Now it works O.K. You have done a good work. The problem was that I must connect the board with the "run jumper" shitched on. I'll stay tuned with your project.

Jean-Pierre MANDON said...

Hi José Luis,

Congratulations, now it works. If you want to use USB without the run jumper ON. You can press Reset and Run switch, then release Reset switch and after 2 seconds release Run switch. This will be the same result.
I will modify this in a future version of the bootloader.

kristianpaul said...

hello, well i decide read old post and found this amazing one,

i wonder if this code can be used to on an arduino ide?

funlw65 said...

I think there is already a "link" between Arduino and Processing. Older than the one with Pinguino...

funlw65 said...

I think is called Firmata...

Also, look at

Also this:

Mauri said...

I have some problems with the example, if I copy-paste the java code, it does not compile.

Anyway, starting from some examples ( and ), the code is almost the same and the program compiles. At the running time, it tells that no pinguino has been found. But if I run the program on the bootloader time (before 5 seconds of running, using a 18F4550) the usb device is recognized.

What's happening =O? I'm new with usb and know the basics about java.

The pinguino code is an example of reading (with usb.available and

Thank you! Excelent work!

Mauri said...

Yeahhh!! I got the problem!

Well I don't know what origins the problem, but using the newest pinguino (the released a few days ago) doesn't work with usb.

Compiling with the previous pinguino corrected the problem. Wohoooo

Yeison.Eng said...

He comenzado con un nuevo proyecto, la verdad es que aún no hay nada publicado, solo una muestra de como pienso hacerlo, voy lento pero con muchas ganas.
El proyecto va lento, solo participo yo (por ahora), esta pensado hacerse todo en Python y WxPython.

cuenta con:
monitor serial
control de puertos

y he pensado en:
un control pinguino a través de Internet
visualizador gráfico de datos análogos

y con ganas de mas ideas

translated with google translator (sorry for mistakes)

I started with a new project, the truth is that nothing is published yet, only a sample of how I do, I'm slow but very hard.
The project is going slow, I participated only (for now), this thought about doing everything in Python and wxPython.

serial monitor
Port Control

and I thought:
Penguin control via Internet
graphical display of analog data

and wanting more ideas

sintornillos said...

Bueno, aqui dejo disponible la interfaz grafica para los microcontroladores PIC18F4550 y PIC18F2550 que son los utilizados en Pinguino a traves de Processing.
Es de creacion personal, tomando como referencia un video en youtube (
cuyo codigo he mejorado un poco:

- Permite la modificacion del valor analogico de salida con solo 1 click
- Abajo tiene unas tablas de estadisticas para los valores analogicos de entrada, sirve mucho para toma de muestras (valor minimo, valor maximo, promedio y un boton de reset).
- Se puede escoger entre el micro PIC18F2550 o PIC18F4550 con un solo click
- Incluye el programa a grabar en nuestro pinguino (tambien modificado por mi).

adjunto una captura:

el link de descarga es

(Google traductor)

Well, here I leave the GUI available for PIC18F4550 and PIC18F2550 microcontrollers are used in Pinguino through Processing.
This creation is personal, with reference to a video on youtube (
code which I have improved a bit:

- Allows modification of output analog value with just 1 click
- Below is a table of statistics for analog input values??, is very useful for sampling (minimum, maximum, average, and a reset button).
- You can choose between PIC18F2550 and PIC18F4550 micro with a single click
- Includes the program to be recorded in our penguin (also modified by me).

attached a screenshot:

the download link is

Emburak said...

Hello I'm Mehmet Burak. I tried both of codes but they didn't work. I use pic18f4550 and i have usbdrive;
libusb-Win32 devices(version )
Pinguino project
Im using pinguinobeta9.05windows, and processing 1.5.1.
I can run led blink commands and servowrite examples. But USB.available doesn't work. Also in java code it says pinguino found but leds do not light. I'm fighting to find it for 3 days. I want to communicate pinguino with PC
Can you please help me? :)

ricardo lara said...

hello, and look what the library could do with hypermedia , but I wanted to control servos and could not, I need help, thank you very much.