Hi everyone,
I am currently running Standard Firmata in Arduino 0022 with an Arduino Nano V3 ATmega328. I am running a simple program to display sensor values from each of the three sonars. I am using Processing 1.5.1.
My problem: The program I wrote does not run properly when I translate it to the Processing IDE. In the Arduino IDE everything works great. When in processing I am using Standard Firmata to establish the connection between Processing and my board.
I have three Maxbotix LV EZ-1 Sonars connected to the Analog inputs: 7, 6, and 5. The Sonars are chained through TX and RX connections to fire in succession. I am using Digital Pin 12 to fire the signal. Here is my code in Arduino:
// Arduino code for reading sensor values from 3 Maxbotix LV EZ-1 Sensors
int signalPinOne = 7;
int signalPinTwo = 6;
int signalPinThree = 5;
int triggerPin = 12; // output pin to start Ultrasound signals
void setup() {
Serial.begin(9600);
pinMode(triggerPin, OUTPUT); // set this pin to output
//give the sensors time to boot up
delay(250);
}
void loop()
{
digitalWrite(triggerPin, HIGH);
delayMicroseconds(30);
digitalWrite(triggerPin, LOW);
delay(50);
int valueOne = analogRead(signalPinOne); //Listen for echo
int valueTwo = analogRead(signalPinTwo);
int valueThree = analogRead(signalPinThree);
Serial.println();
Serial.print("UltraSound Value ONE");
Serial.print( "= ");
Serial.print((valueOne/1.8333));
Serial.println();
Serial.print("UltraSound Value TWO");
Serial.print( "= ");
Serial.print((valueTwo/1.8333));
Serial.println();
Serial.print("UltraSound Value THREE");
Serial.print( "= ");
Serial.print((valueThree/1.8333));
Serial.println();
Serial.println();
delay(500);
Serial.println();
Serial.println();
}
Here is the code I am using in Processing when Standard Firmata is uploaded to the Arduino:
// processing code for reading sensor values from 3 Maxbotix LV EZ-1 Sensors
import processing.serial.*; // reference the serial library
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
PFont f;
int signalPinOne = 7;
int signalPinTwo = 6;
int signalPinThree = 5;
int triggerPin = 12;
void setup() {
size(1400, 800);
f = loadFont("CourierNewPSMT-48.vlw");
smooth();
println(Serial.list()); // List all the available serial ports:
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(triggerPin, Arduino.OUTPUT);
}
void draw() {
//triggers pin to pulse on each loop through
arduino.digitalWrite(triggerPin, Arduino.HIGH);
delay(50);
arduino.digitalWrite(triggerPin, Arduino.LOW);
delay(50);
background(40);
frameRate(30);
int valueOne = arduino.analogRead(signalPinOne);
int valueTwo = arduino.analogRead(signalPinTwo);
int valueThree = arduino.analogRead(signalPinThree);
// println((valueOne/1.8333));
// println((valueTwo/1.8333));
// println((valueThree/1.8333));
// display large read out of Inch value of sensor #1
float a = (((valueOne)/1.8333));
fill(255, 255, 255);
textFont(f, width/18);
text("Sensor # 1", 0, width/7.2);
textFont(f, width/6);
text(a, width/4, width/7.2);
// display large read out of Inch value of sensor #2
float b = (((valueTwo)/1.8333));
fill(255, 255, 255);
textFont(f, width/18);
text("Sensor # 2", 0, width/3.33);
textFont(f, width/6);
text(b, width/4, width/3.33);
// display large read out of Inch value of sensor #3
float c = (((valueThree)/1.8333));
fill(255, 255, 255);
textFont(f, width/18);
text("Sensor # 3", 0, width/2.2);
textFont(f, width/6);
text(c, width/4, width/2.2);
delay(100);
}
Any help is much appreciated. Thanks!
1