Newbie help with arduino sensor data -> processing

I'm pretty new to working with arduino, and I'm trying to get data from a rangefinder (MaxSonar EZ0) into Processing. I'm getting the data from the sensor in the Arduino environment, but when I run my Processing code, all the readings are coming through as zero. What am I doing wrong?

Here is my code. I have an Arduino Diecemilia connected via USB. The rangefinder's analog out is connected to analog pin 0.

Arduino code. This seems to work fine.

int sonarPin = 0; //pin connected to analog out on maxsonar sensor
int inchesAway; 

void setup() {
    Serial.begin(9600);
      Serial.print("running");
}

void loop() {
  inchesAway = analogRead(sonarPin) ;
    Serial.println(inchesAway);
}

Processing code. This is returning all zero readings.

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;


void setup() {
  size(470, 280);
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  
  println(Arduino.list());
  
  arduino.pinMode(0, Arduino.INPUT);
}

void draw() {
 
 println(arduino.analogRead(0));
 
}

What am I doing wrong?

You are not understanding the nature of the Processing library.

The code on the arduino end is fine at sending serial data but you have to write the code at the Processing end to make sense of it. However to make matters simple Processing has a library that will talk to an Arduino but only if the Arduino is running the Firmata sketch. In your case it is not.

Please see:-
http://www.arduino.cc/playground/Interfacing/Processing

@pixielex
See my comment in the second thread regarding the baud rate:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254863582/1#1

Yes it is true the baud rate is different but even if it was the same it wouldn't work due to what I said. When you have the Firmata code running in the arduino you have no control over the baud rate at the arduino end.

OK, I just tried again. I have StandardFirmata running on my Arduino board. In Processing, I'm running the arduino_input example that comes with the arduino library, and I'm print out all of the analog pin readings, but they are all coming through as zero. Any idea what I'm doing wrong here?

OK, I've pretty much got it working, but still have a question.

Apparently, if I have the Serial Monitor window open in Arduino while I run the Processing sketch, everything works fine. If I have the Serial Monitor closed, it doesn't work. I thought the Serial Monitor was just to see a readout of the values, but that it didn't actually serve a functional purpose in the running of the application. Can someone explain this to me?