Processing

Clock

Here’s a quick digital clock in Processing. It also sends the time out a serial port. I use this for testing when I need for a microcontroller or other serial device to receive a string.

/*
  Clock

 Draws a digital clock in the center of the screen
 and sends the string out the serial port.

 created 7 Oct 2008
 by Tom Igoe
 */

import processing.serial.*;

Serial myPort;    // instance of the serial library

void setup() {
  // open the applet window:
  size(300, 200);
  // initialize the font for text display:
  PFont myFont = createFont(PFont.list()[0], 24);
  textFont(myFont);
  // align all text center:
  textAlign(CENTER);
  // open a serial port:
  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw(){
  // clear the screen:
  background(0);
  // make a string of hour: minute:second.  Use nf()
  // to format the numbers in two digits each:
  String theTime = nf(hour(), 2) + ":" + nf(minute(), 2) + ":"+ nf(second(), 2);
  // draw it in the middle of the screen:
  text(theTime, width/2, height/2);
  // send it out the serial port:
  myPort.write(theTime + "\n");
  // wait one second before doing it again:
  delay(1000);
}

Processing

Permalink

Sending Mail from Processing

Here’s a piece of code to send mail from Processing. It uses the net library. Warning: your mail server may not use port 25.

/* mail_client
 by Tom Igoe

  A simple mail sender client
 Created 21 January 2006
 */

import processing.net.*;
Client myClient;
int clicks;
String reply = null;
boolean sent = false;
void setup() {
  // Connect:
  myClient = new Client(this, "echonyc.com", 25);
  delay(300);

} 

void draw() {
  if(!sent) {
    waitForReply();
    myClient.write("HELO echonyc.com\n");
    waitForReply();
    myClient.write("MAIL FROM:tigoe@echonyc.com\n");
    waitForReply();
    myClient.write("RCPT TO:tigoe@echonyc.com\n");
    waitForReply();
    myClient.write("DATA\n");
    waitForReply();
    myClient.write("Subject:Noodles\n");
    myClient.write("From:tigoe@echonyc.com\n");
    myClient.write("To:tigoe@tigoe.net\n");
    myClient.write("\rHere's the body\n.\n");
    waitForReply();
    myClient.write("QUIT\n\r");
    waitForReply();
  }
  sent = true;
} 

void waitForReply() {
  int newChar = 0;
  while (newChar != 10) {
    if(myClient.available() > 0) {
      newChar = myClient.read();
      reply += (char)newChar;
    }
  }
  println(reply);
}

Processing

Permalink

RFID Reader and Image Display

This program reads ID Innovations ID-12 RFID readers and matches the tags against a list of known tags. It’s an illustration of how to use an RFID reader to associate data with a set of tags.

/*
  RFID Reader and image display
  Language: Processing

  This program reads ID Innovations ID-12 RFID readers rom two serial ports.
  It matches the tags against a list of known tags, and uses the match to
  associate a name with the tag.  It also scans the sketch's data directory
  to load an image associated with the name.

  Created 12 Mar 2008
  by Tom Igoe and the interaction design class at AHO, Spring 2008
  directory reading and image scanning based on an example from Marius Watts

*/

Continue Reading »

Processing

Permalink

Reading Multiple Serial Ports in Processing

This program reads multiple serial ports and lets you know when data comes from one port or the other. The two ports in this example are attached to ID Innovations ID-12 RFID readers. The ID-12 readers send a string that ends with a byte whose value is 0×03.

/*
   Multiple Serial Ports
   Language: Processing

   This program reads multiple serial ports and lets you know when data comes
   from one port or the other. The two ports in this example are attached to
   ID Innovations ID-12 RFID readers. The ID-12 readers send a string that ends
   with a byte whose value is 0x03.

   Created 12 Mar 2008
   by Tom Igoe
*/

Continue Reading »


Processing

Permalink

XBee Library graphing and logging application

Here’s a program that uses Rob Faludi and Dan Shiffman’s XBee library for processing to read three analog sensors from multiple remote XBee radios and graph them. It also saves the data to a comma-delimited file. It also makes sounds when the value exceeds a given threshold. For this application, you need two or more XBee series 1 radios. One is attached to the serial port of the computer, and the other is remote, broadcasting three analog values.

This also uses the ControlP5 library by Andreas Schlegel and the Ess library by Krister Olsson.

Continue Reading »

Processing
XBee

Permalink

XBee Library graphing application

Here’s a simple program that uses Rob Faludi and Dan Shiffman’s XBee library for processing to read three analog sensors from a remote XBee radio and graph it. For this application, you need two XBee series 1 radios. One is attached to the serial port of the computer, and the other is remote, broadcasting three analog values.

Continue Reading »

Processing
XBee

Permalink

XOR calculation for NMEA checksums (GPS protocol)

If you’ve ever seen the serial output of a GPS reader, you’ve seen a mystery string at the end like this:

That’s the checksum of the whole string. NMEA data structure for Global Positioning (GPS) readers has a checksum on the end of each sentence. The checksum is the XOR of all the bytes between the $ and the * in the sentence. For example, if the sentence is this:

$GPRMC,155123.000,A,4043.8432,N,07359.7653,W,0.15,83.25,200407,,*28

then you run a checksum on this:

GPRMC,155123.000,A,4043.8432,N,07359.7653,W,0.15,83.25,200407,,

Here’s a Processing method to calculate the checksum, given the string between the $ and the *:

Technorati Tags: ,


Continue Reading »

Processing

Permalink

Peak finding in Processing

In a previous example, I showed how to detect a peak in a changing analog value on a microcontroller. This example shows how to do it in Processing, assuming the microcontroller is just sending you binary values from 0 to 255. It graphs the incoming bytes, and when a peak is detected, it draws an ellipse and prints a message in the message pane.

Thanks to Matt Young for helping me debug this.

Technorati Tags: , ,


Continue Reading »

Processing

Permalink

Data graphing program that saves to a file

This Processing sketch takes data from the serial port, graphs it, and writes it to a text file with a time stamp if there’s a significant change in any of the incoming values. It expects five values between 0-255 in ASCII, separated by tabs, and ended by a carriage return and newline.

The text file it generates is tab-delimited, and can be read easily in a spreadsheet.

A Wiring/Arduino program to send data to this sketch follows at the end.

Continue Reading »

Processing

Permalink

Net connection between Processing and Max/MSP

The following Max/MSP patch uses the netsend object to send data over a TCP socket. It sends three values. The Processing sketch further down is a server that receives the string that the Max patch sends and uses it to move a ball on the screen.

Technorati Tags: ,


Continue Reading »

Max/MSP
Processing

Permalink