Tuesday, February 26, 2008
processing - serialport - microcontroller [cm:sd]
this week we wanted to set up a communication to the microcontroller from Processing. with this communication we will be able to import excel files (or any number data) into the microcontroller. currently the pbasic and processing scripts are only telling the LED to turn on, not flash or blink or anything too exciting.
Processing Code:
import processing.serial.*;
Serial myPort; // The serial port
PFont myFont; // The display font
String inString; // Input string from serial port
int lf = 10; // ASCII linefeed
void setup() {
size(400,200);
// Make your own font. It's fun!
myFont = loadFont("ArialMT-48.vlw");
textFont(myFont, 48);
// List all the available serial ports:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, "COM3", 9600);
//noLoop();
}
void draw() {
// Twiddle your thumbs
background(0);
int i=65;
for(i=65; i<75;>
if(i<70){
myPort.write(i);
text("Received: " + inString, 10, 50);
}
else {
myPort.write(i-1);
text("Received: " + inString, 10, 90);
}
}
}
void serialEvent(Serial myPort) {
inString = myPort.readString();
}
PBasic Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
check VAR Byte
proIn VAR Byte
Main:
DO
check = IN3
proIn = IN10
SERIN 16, 65535, [proIn]
IF proIn <> 13 THEN
HIGH 2
ENDIF
LOOP
END
Processing Code:
import processing.serial.*;
Serial myPort; // The serial port
PFont myFont; // The display font
String inString; // Input string from serial port
int lf = 10; // ASCII linefeed
void setup() {
size(400,200);
// Make your own font. It's fun!
myFont = loadFont("ArialMT-48.vlw");
textFont(myFont, 48);
// List all the available serial ports:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, "COM3", 9600);
//noLoop();
}
void draw() {
// Twiddle your thumbs
background(0);
int i=65;
for(i=65; i<75;>
if(i<70){
myPort.write(i);
text("Received: " + inString, 10, 50);
}
else {
myPort.write(i-1);
text("Received: " + inString, 10, 90);
}
}
}
void serialEvent(Serial myPort) {
inString = myPort.readString();
}
PBasic Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
check VAR Byte
proIn VAR Byte
Main:
DO
check = IN3
proIn = IN10
SERIN 16, 65535, [proIn]
IF proIn <> 13 THEN
HIGH 2
ENDIF
LOOP
END