
198 MAKING THINGS TALK
An XBee Serial Terminal
Because the GNU screen program in Mac OS X, Unix, and Linux doesn’t print newlines
when the XBees send only a return character, it can be difficult to read the results.
/*
XBee terminal
language: processing
This program is a basic serial terminal program.
It replaces newline characters from the keyboard
with return characters. It's designed for use with
Linux, Unix, and Mac OS X in combination with XBee radios,
because the XBees don't send newline characters back.
*/
import processing.serial.*;
Serial myPort; // the serial port you're using
String portnum; // name of the serial port
String outString = ""; // the string being sent out the serial port
String inString = ""; // the string coming in from the serial port
int receivedLines = 0; // how many lines have been received
int bufferedLines = 10; // number of incoming lines to keep
void setup() {
size(400, 300); // window size
// create a font with the third font available to the system:
PFont myFont = createFont(PFont.list()[2], 14);
textFont(myFont);
// list all the serial ports:
println(Serial.list());
// based on the list of serial ports printed from the
// previous command, change the 0 to your port's number:
portnum = Serial.list()[0];
// initialize the serial port:
myPort = new Serial(this, portnum, 9600);
}
void draw() {