On linux, we have some problems to use the Serial object to communicate with Pinguino CDC.
Unfortunately, the RXTXbin module of JAVA don't recognize the /dev/ttyACM0 port.
I found a solution to fix this problem, and a simple working example is detailed here.
Create a symbolic link from /dev/ttyACM0 to a more popular name for a serial device ( i chose /dev/ttyS20 )
sudo ln -s /dev/ttyACM0 /dev/ttyS20
Now the Pinguino side of my fantastic application !!
// Pinguino cdc with processing
// Jean-Pierre Mandon 2010
unsigned char i;
void setup()
{
for (i=0;i<4;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
}
unsigned char receivedbyte;
unsigned char rxstr[64];
void loop()
{
// Use the run led to check if a terminal is connected
if (CONTROL_LINE) PORTAbits.RA4=1;
else PORTAbits.RA4=0;
// receive a string from the USB uart and send it on the uart
receivedbyte=CDC.read(rxstr);
if (receivedbyte>0)
{
rxstr[receivedbyte]=0; // to make received character(s) a string
switch (rxstr[0])
{
case 'S':switch(rxstr[1]) // SET
{
case '0': digitalWrite(0,HIGH); // Pin 0 ON
break;
case '1': digitalWrite(1,HIGH); // Pin 1 ON
break;
case '2': digitalWrite(2,HIGH); // Pin 2 ON
break;
case '3': digitalWrite(3,HIGH); // Pin 3 ON
break;
}
break;
case 'R':switch(rxstr[1]) // RESET
{
case '0': digitalWrite(0,LOW); // Pin 0 OFF
break;
case '1': digitalWrite(1,LOW); // Pin 1 OFF
break;
case '2': digitalWrite(2,LOW); // Pin 2 OFF
break;
case '3': digitalWrite(3,LOW); // Pin 3 OFF
break;
}
break;
}
}
}
The processing side assume that /dev/ttyS20 is used as the first serial port:import processing.serial.*;
Serial myPort;
String port[];
int i;
void setup()
{
port=Serial.list();
println(port[0]);
myPort=new Serial(this,port[0],115200);
}
void draw()
{
for (i=0;i<4;i++)
{
myPort.write("S"+str(i));
delay(50);
myPort.write("R"+str(i));
delay(50);
}
}
void stop()
{
myPort.stop();
}
And now the schematic:
Have fun
Jean-Pierre
4 comments:
Excelente, cuando vuelva a casa estaré dándole una prueba. Gracias por ese ejemplo. Salud!
Was having the same problem, the solution was so simple :)
It works!!!, but I have the same problem in Windows, does anyone knows how to resolve it ?
hello, and look what the library could do with hypermedia http://www.youtube.com/watch?v=fDDPt6Aa1Q4 , but I wanted to control servos and could not, I need help, thank you very much.
Post a Comment