Need a simple accelerometer visualization example!

I'm doing a project using the ADXL335 accelerometer from SparkFun. The actual project I'm using P5 and it's working great. I'm running workshops in parallel and want to demo the chip in real-time but am currently out of time to build something from scratch. I'm desperate for a simple processing (or something else) sketch that takes my x, y, z values being printed to the serial port from Arduino and visualizes them in some way. Can anyone point me to anything that won't need a lot of coding time and effort just now?

Thank you!

Claudia

Check the processing forum/site?

The best one I found was to get one of the Sparkfun LED ring lights and make a bubble level. That is really interactive and only a few minutes to program once you have the accelerometer working. If you don't have one of those ringlights, perhaps 4 LEDs in a square plus one in the middle can make a bubble level?

I think this is the processing code I used to experiment with my accelerometer, several years ago. I don't recall, and I don't currently have access to a computer with processing installed on it.

I had to download something called gwoptics to make it work, Dr Google might be able to help you there.

import org.gwoptics.graphics.graph3D.*;
import org.gwoptics.graphics.colourmap.*;
import org.gwoptics.graphics.graph2D.backgrounds.*;
import org.gwoptics.graphics.graph2D.traces.*;
import org.gwoptics.graphics.camera.*;
import org.gwoptics.graphics.graph2D.effects.*;
import org.gwoptics.graphics.graph2D.*;
import org.gwoptics.*;
import org.gwoptics.gaussbeams.*;
import org.gwoptics.graphicsutils.*;
import org.gwoptics.mathutils.*;
import org.gwoptics.graphics.*;
import org.gwoptics.graphics.colourmap.presets.*;

import org.gwoptics.graphics.graph2D.Graph2D;
import org.gwoptics.graphics.graph2D.traces.ILine2DEquation;
import org.gwoptics.graphics.graph2D.traces.RollingLine2DTrace;

import processing.serial.*;

/**
 * Simple Read
 * 
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */

// The values are extracted from the serial stream from the accelerometer,
// put into these three variables,  picked up by the next three eq classes
// and then put into the graph.

int accx ;  // current x acceleration
int accy ;
int accz ;

// defines three classes which represent each one of the chart traces
// these classes may not be necessary but it follows the example based

class eq implements ILine2DEquation{
 public double computePoint(double x,int pos) {
 return  accx ;
 } 
}

class eq2 implements ILine2DEquation{
 public double computePoint(double x,int pos) {
 return  accy ;
 } 
}

class eq3 implements ILine2DEquation{
 public double computePoint(double x,int pos) 
        {
          return accz ; 
 } 
}

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port
char[] buf = new char[55] ;
char ch ;
int ipos ;

RollingLine2DTrace r,r2,r3;
Graph2D g;

byte[] inbuf ;

PrintWriter ofile ;

void setup() 
{
  ofile = createWriter( "acc_out.txt" );
  
  inbuf = new byte[12] ;   // a buffer to read the serial data, after the header.
   
  size(800,400);  // size of the whole window
  
  println("Starting setup()...");
  
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String[] portNames = Serial.list();
  int len = portNames.length ;
  println("portNames has "+len+" elements");
  
  for (int i=0 ; i<len ; i++ )
  {
    println(portNames[i]);
  }
  
  String portName4 = new String( portNames[1]) ;  // usual needs to be portNames[1] for arduino
  
  myPort = new Serial(this, portName4, 115200 );
  myPort.clear() ;
  
  ipos=0 ;
  
  // this is the part which sets up the graphing window
  
        // this should create three objects for x,y,z   but the x and y seem to be the wrong way around
        // or maybe just the wrong colour.
 
 r  = new RollingLine2DTrace(new eq() ,3,0.003f);
 r.setTraceColour(255, 0, 0);   // red
 
 r2 = new RollingLine2DTrace(new eq2(),3,0.003f);
 r2.setTraceColour(0, 255, 0);  // green
 
 r3 = new RollingLine2DTrace(new eq3(),3,0.003f);
 r3.setTraceColour(0, 0, 255);  // blue
 
 g = new Graph2D(this, 200, 200, false);   // size of the graph section

 g.setYAxisMax(1040);
 g.addTrace(r);
 g.addTrace(r2);
 g.addTrace(r3);
 g.position.y = 50;   // position of the graph within the window
 g.position.x = 100;
 g.setYAxisTickSpacing(100);
 g.setXAxisMax(6f);

}

long miltime ;
int xin ;
int yin ;
int zin ;
boolean gotdata ;

void draw()
{
  accx=xin ;
  accy=yin ;
  accz=zin ;
  background(200) ;
  g.draw() ;
}



/*  Message has 13 bytes,  2 header bytes, one long, 3 ints and a final byte
 *  Note:  that is Arduino long and int  (  32 and 16 bits ?? )
 */

int C1=255 ;   // initial string is FF FE
int C2=254 ;

void serialEvent( Serial p )
{
  //long numchar=p.available() ;
  //println("numchar is "+numchar );
  
  int attempt=0 ;
  
  while ( p.available() >= 14 ) 
  {
    int i1=p.read() ;   // returns int 0 to 255 if a byte is there otherwise -1
    
    attempt++ ;
    
    if ( i1 == C1 )
    {
      if ( attempt > 1 )  println("matched first char at attempt "+attempt );
      
      int i2=p.read() ;
      if ( i2 == C2 )
      {
                                               // ten data bytes and a check byte we
                                               // don't bother to check
          int numread=p.readBytes( inbuf ) ;  
          
          if ( numread != 12 ) println("matched second char,  numread = "+numread ) ;
          
          if ( 1== 2 )   // list the hex bytes
          {
            for ( int jj=0 ; jj<numread ; jj++ )
            {
              print(hex(inbuf[jj])+" ");
            }
            println();
          }
          
          boolean trailergood=true ;
          
          if ( numread >= 11 )  // check the trailer character
          {
            if ( inbuf[10] != 0x0024 )
            { 
              println("Got bad trailer character "+hex(inbuf[10]) );
              trailergood = false ;
            }
          }
          
          // data for ints and longs comes in least significant byte first
          
          if ( numread >= 10 )
          {
            long temp=0 ;
            temp += ( inbuf[3] & 0x00FF ) ;
            temp <<= 8 ;
            temp += ( inbuf[2] & 0x00FF ) ;
            temp <<= 8 ;
            temp += ( inbuf[1] & 0x00FF ) ;
            temp <<= 8 ;
            temp += ( inbuf[0] & 0x00FF ) ;
            
            miltime = temp ;
            
            int tem=0 ;
            tem = (( inbuf[5] & 0x00FF ) << 8 ) + (inbuf[4]&0x00FF) ;
            xin = tem ;
            
            tem=0 ;
            tem = (( inbuf[7] & 0x00FF ) << 8 ) + (inbuf[6]&0x00FF) ;
            yin = tem ;
            
            tem=0 ;
            tem = (( inbuf[9] & 0x00FF ) << 8 ) + (inbuf[8]&0x00FF) ;
            zin = tem ;
            
            println("Got data time="+miltime+" "+xin+" "+yin+" "+zin) ;
            
            ofile.println(miltime+" "+xin+" "+yin+" "+zin );
            ofile.flush() ;
            
            return ;
          }
      }
      else
      {
        // didn't match the second character,  so the first character match was a dud
        // continue the while loop until we find a match or there are insufficient
        // characters for a message
        println("looking for second header char, got "+hex(i2)+"   attempt= "+attempt) ;

      }
    }
    else
    {
      //  continue the loop until we find the first key byte, 
      //  or there are less than 13 bytes so no complete message is available
      println("looking for first header char, got "+hex(i1)+"   attempt= "+attempt) ;
    }
  }
  // println("serialEvent() ending, didnt get data");
}

Accelerometer has 3 axes and RGB led has 3 colors. Does that suggest anything?