Category Archives: Processing

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…. Created 20 April 2005 Updated 15 October 2007 */import processing.serial.*;Serial myPort; // The serial portint arrayLength = 5; // number of values to expectint[] sensorValues = new int[arrayLength]; // array to hold the incoming valuesint hPosition = 0; // horizontal position on the graphint displayChannel = 0; // which of the five readings is being displayedString dataSet; // string holding the incoming data int threshold = 50; // threshold for whether or not to write // data to a filevoid setup () { size(400, 300); // window size // List all the available serial ports println(Serial.list()); // I know that the third port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[2]. Continue reading

Posted in Processing | Comments Off on Data graphing program that saves to a file

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.
Continue reading

Posted in Max/MSP, Processing | Comments Off on Net connection between Processing and Max/MSP

XBee Radio Received Signal Strength Graphing Program

This Processing program takes a string of values in the serial port. It assumes the string is the API string from a Maxstream XBee radio.
Continue reading

Posted in Processing, XBee | Comments Off on XBee Radio Received Signal Strength Graphing Program

Xbee Radio Received Signal Strength and Data Graphing Program

The packet should be 22 bytes long. It should be made up of the following: byte 1: 0x7E, the start byte value byte 2-3: packet size, a 2-byte value (not used here) byte 4: API identifier value, a code that says what this response is (not used here) byte 5-6: Sender’s address byte 7: RSSI, Received Signal Strength Indicator (not used here) byte 8: Broadcast options (not used here) byte 9: Number of samples to follow byte 10-11: Active channels indicator (not used here) byte 12-21: 5 10-bit values, each ADC samples from the sender Created 20 Mar. 2007 by Tom Igoe */ import processing.serial.*; Serial xbee; // input serial port from the Xbee Radio int[] packet = new int[22]; // with 5 samples, the Xbee packet is 22 bytes long int byteCounter; // keeps track of where you are in the packet int fontSize = 18; // size of the text on the screen int lastReading = 0; // value of the previous incoming byte int rssi = 0; // received signal strength int address = 0; // sender’s address int average = 0; // average of the sensor data int firstRectPos = 25; // horizontal pos of the first graph bar void setup () { size(400, 300); // window size // create a font with the second font available to the system: PFont myFont = createFont(PFont.list()[2], fontSize); textFont(myFont); // get a list of the serial ports: println(Serial.list()); // open the serial port attached to your Xbee radio: xbee = new Serial(this, Serial.list()[0], 9600); } void draw() { // set the background: background(0); // if you have new data and it’s valid (>0), graph it: // write the numbers: text(“Xbee Radio Signal Strength test”, 10, 20); text(“From: ” + hex(address), 10, 40); text (“RSSI: -” + rssi + ” dB”, 10, 60); text(“Sensor avg:” + average, 10, 80); // note that these graph bars aren’t proportional, they just show change. // RSSI should range from 0 to -92 dBm drawBar(92 – rssi, 50, 0); // average should range from 0 – 1023, so divide by 4 to keep it // in the vertical space of the window: drawBar(average/4, 50, 1); } void drawBar(int rectHeight, int rectWidth, int rectNum ) { if (rectHeight > 0 ) { // draw the rect: stroke(23, 127, 255); fill (23, 127, 255); int rectPos = firstRectPos + (rectNum * 75); text(rectNum, rectPos, 30); rect(rectPos, height-rectHeight, rectWidth, height); } } void serialEvent(Serial xbee) { // read a byte from the port: int thisByte = xbee.read(); // if the byte = 0x7E, the value of a start byte, you have a new packet: if (thisByte == 0x7E) { // start byte // parse the previous packet if there’s data: if (packet[2] > 0) { parseData(packet); } // reset the byte counter: byteCounter = 0; } // put the current byte into the packet at the current position: packet[byteCounter] = thisByte; // increment the byte counter: byteCounter++; } /* Once you’ve got a packet, you need to extract the useful data.
Continue reading

Posted in Processing, XBee | Comments Off on Xbee Radio Received Signal Strength and Data Graphing Program

Serial Server for Flash, etc.

I got tired of the problems with the various serial server solutions for Flash, so I wrote this Processing sketch to do the job…. But it will allow you to connect a Flash movie to a serial port by making an XML socket to localhost in order to access the serial port. Continue reading

Posted in Processing | Comments Off on Serial Server for Flash, etc.

Xbee Radio terminal program

Working with the Maxstream Xbee radios on OSX can be annoying because the screen program doesn’t print a linefeed automatically when it receives a carriage return…. Created 2 Feb. 2007 by Tom Igoe */ import processing.serial.*; Serial myPort; // the serial port you’re using void setup() { // 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: String portnum = Serial.list()[0]; // initialize the serial port: myPort = new Serial(this, portnum, 9600); } void draw() { // not much happens on screen: background(0); } // This method responds to key presses when the // program window is active: void keyPressed() { switch (key) { // in OSX, if the user types return, // a linefeed is returned.
Continue reading

Posted in Processing, XBee | Comments Off on Xbee Radio terminal program

Fullscreen Support for Processing

The fullscreen library for processing allows you to set the screen resolution to match your Processing sketch’s size so that it can take over the full screen. It also includes key bindings so that you can enter and exit fullscreen mode while the application is running. Continue reading

Posted in Processing | Comments Off on Fullscreen Support for Processing

Sudden Motion Sensor on the Macbook

Dan Shiffman’s written a nice library to access the sudden motion sensor on the macbook and macbook pro…. Below is a code sample for it that draws a plane on the screen and moves it as you tilt the computer. Continue reading

Posted in Processing | Comments Off on Sudden Motion Sensor on the Macbook

Bluetooth-to-Bluetooth connection using blueSMiRF

by Tom Igoe created 17 Oct. 2006 */ import processing.serial.*; Serial myPort; // the serial connection String responseString = “”; // response from the blueSMiRF String[] responses = new String[20]; // array of strings in case you get a multi-line response int nextLine = 0; // counter for the multi-line response String targetAddress; // BT address of another device to connect to boolean connected = false; // whether you’re connected to another BT device or not void setup() { // set the window size: size(100,100); // print the list of serial ports, to find the one you need: println(Serial.list()); // open the appropriate serial port…. // send any keystrokes through to the remote radio: println(key); myPort.write(key); } } /* btConnect method runs through all the commands necessary to make a connection: */ void btConnect() { // send an AT command, wait for an OK: sendCommand(“AT”, “OK”); // send a clear command, wait for an OK: sendCommand(“ATUCL”, “OK”); // sent an inquiry command for up to 3 devices, wait for a DONE: sendCommand(“ATDI,3,00000000”, “DONE”); // search the array of returned strings for a target address and connect: findTarget(); } /* sendCommand method sends a command and waits for a response: */ void sendCommand(String command, String whatResponse) { // send the command: myPort.write(command+ “\r”); // wait for the appropriate response: while (!responseString.equals(whatResponse)) { delay(10); } } /* findTarget looks through the array of received responses for a BT device type of 00000000. Continue reading

Posted in Processing | Comments Off on Bluetooth-to-Bluetooth connection using blueSMiRF

Serial Quicktime Movie Controller

by Tom Igoe Created 8 Oct. 2006 Modified: */ import processing.serial.*; import processing.video.*; Serial myPort; // The serial port int sensorValue; // value of the byte received Movie myMovie; // variable to store an instance of the movie library float movieDuration; // duration of the movie you’re using void setup() { // set the window size: size(200,200); // 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 Arduino module, so I open Serial.list()[0]…. Place it in a folder called “Data” // inside your sketch folder: myMovie = new Movie(this, “station.mov”); myMovie.loop(); // get the movie duration: movieDuration = myMovie.duration(); } void draw() { background(0); // if there’s a movie to read, read it: if(myMovie.available()) { myMovie.read(); } // calculate the movie position based on the value from the sensor. Continue reading

Posted in arduino/wiring, Processing | Comments Off on Serial Quicktime Movie Controller