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));
}