Search in Pinguino World !!

Showing posts with label Pinguino Processing. Show all posts
Showing posts with label Pinguino Processing. Show all posts

Wednesday, March 17, 2010

Simple example with Processing

I wrote this simple example to help users to associate Processing and Pinguino.
Communication is managed by Stephane Cousot Library and USB link.
Stephane example program is loaded in the Pinguino with the IDE.
A led is connected on PIN 0 of Pinguino.


// How to blink a led on PIN 0 with processing
// Jean-pierre Mandon 2010

import hypermedia.pinguino.*; // import library

Pinguino board; // pinguino object

void setup() {

size( 380, 180 ); // size the window application
board = new Pinguino( this ); // connect to Pinguino board

}

void draw() {

background(0);

fill(0);
if (board.digitalRead(0)==Pinguino.LOW)
board.digitalWrite(0,Pinguino.HIGH); // PIN 0 = 1
else
{ board.digitalWrite(0,Pinguino.LOW); // PIN 0 = 0
fill(255,0,0);
}
rect(170,70,40,40);
delay(100);

}

Stephane processing Library can be downloaded here.
The pinguino side program is here.

Monday, March 16, 2009

Processing library for Pinguino

Last week, Stéphane Cousot wrote a basic library for communicating between Processing and Pinguino. This the first release but it was tested and is fully functional. Stéphane made a package with a processing sketch and the Pinguino program associated. You can download this package on Stéphane website.
This library is the result of our work with Douglas Edric Stanley. The goal is to build a USB interface wich can be driven by many different software ( Processing, Python, Pure data, java ... ).
Pinguino is the hardware part of this project.
Douglas Edric Stanley Blog.

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 http://libusbjava.sourceforge.net/wp/
// 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()
{
size(400,100);
frameRate(20);
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
Pinguino.open(3,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()
{
background(204);
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
lastposition=position;
}
catch (USBException e) {}
}
}

void stop()
{
data[1]='C'; // clear all when stop
try {
Pinguino.writeBulk(0x01,data,2,200,false);
}
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++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
}

void loop()
{
if (USB.available())
{
caractere=USB.read();
if (caractere=='W') if (USB.available())
{
caractere1=USB.read();
if (caractere1=='C')
for (i=0;i<8;i++) digitalWrite(i,LOW);
else
digitalWrite(caractere1,digitalRead(caractere1)^1);
}
}
}

And you can see the result here.