title: Weird random data being sent from Arduino to Processing
body: <p>I'm trying to read data from a photocell resistor and my Arduino Decimila and then graph it in real-time with Processing.</p>
  
  <p>Should be painfully simple; but its growing into a little bit of a nightmare for me.</p>
  
  <p>code I'm running on my Arduino:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>int photoPin;
  
  void setup(){
  
    photoPin = 0;
    Serial.begin( 9600 );
  
  }
  
  void loop(){
  
    int val = int( map( analogRead( photoPin ), 0, 1023, 0, 254 ) );
    Serial.println( val ); //sending data over Serial
  
  }
  </code></pre>
  
  <p>code I'm running in Processing: </p>
  
  <pre class="lang-java prettyprint-override"><code>import processing.serial.*;
  
  Serial photocell;
  
  int[] yvals;
  
  void setup(){
  
    size( 300, 150 );
    photocell = new Serial( this, Serial.list()[0], 9600 );
    photocell.bufferUntil( 10 );
    yvals = new int[width];
  
  }
  
  void draw(){
  
    background( 0 );
    for( int i = 1; i &lt; width; i++ ){
      yvals[i - 1] = yvals[i];
    }
  
    if( photocell.available() &gt; 0 ){
      yvals[width - 1] = photocell.read();
    }
  
    for( int i = 1; i &lt; width; i++ ){
      stroke( #ff0000 );
      line( i, yvals[i], i, height );
    }
    println( photocell.read() ); // for debugging
  }
  </code></pre>
  
  <p>I've tested both bits of code separately and I know that they work. It's only when I try to have the input from the Arduino going to Processing that the problems start.</p>
  
  <p>When I view the data in Arduino's "Serial Monitor", I get a nice constant flow of data that seems to look valid.</p>
  
  <p>But when I read that same data through Processing, I get a repeating pattern of random values.</p>
  
  <p>Halp?</p>