RS232 in processing

Last week I announced that I wanted to write a small terminal program in Processing.

That has turned out to be a very quick hack.

First, I wrote a number generator and loaded it into my Arduino (can you call it “wrote” if you talk about a 3-liner?)

void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello "+(String)random(0,19));
delay(50);
}

Well, then I opened processing and this example..
// Example by Tom Igoe

import processing.serial.*;
int lf = 10; // Linefeed in ASCII
String myString = null;
Serial myPort; // The serial port
void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.clear();
myString = myPort.readStringUntil(lf);
myString = null;
}
void draw() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
println(myString);
}
}
}

It can be found here.

Done. Easy!

Advertisements

One comment

  1. […] I remember saving up like half of a year for one SDK500… I wanted to use a quick and dirty RS232 terminal program in processing that controls the seven-segment and maybe the sensor. This tiny little project is pretty trivial, […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: