Hello,
I am trying to read two temperature sensors using Processing. The sensors work, but only output 0.0 when I run the code. I have tried everything I can think of and I would greatly appreciate any help. Thanks!
import cc.arduino.*;
import processing.serial.*;
Arduino arduino;
PrintWriter output;
DateFormat fnameFormat= new SimpleDateFormat("yyMMdd_HHmm");
DateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
String fileName;
int serialCount = 3;
int sensorPin2 = 2;
int sensorPin3 = 3;
//int sensorPin4 = 4;
float temp1;
float temp2;
float rpm;
char DELIM = ',';
long timeold = 0;
int interval = 500;
int length;
int BAUDRATE = 9600;
String serialString;
void setup() {
Date now = new Date();
fileName = fnameFormat.format(now);
output = createWriter(fileName + ".csv"); // save the file in the sketch folder
arduino = new Arduino(this, Arduino.list()[0], 9600);
}
void draw() {
long currentTime = millis();
if(currentTime - timeold >= interval){
temp1 = arduino.analogRead(sensorPin2);
temp1 = (temp1 * 5.0) / 1024.0;
temp2 = arduino.analogRead(sensorPin3);
temp2 = (temp2 * 5.0) / 1024.0;
//rpm = arduino.analogRead(sensorPin4);
print(timeold);
print(", ");
print(temp1);
print(", ");
println(temp2);
//print(", ");
//println(rpm);
output.print(timeold);
output.print(", ");
output.print(temp1);
output.print(", ");
output.println(temp2);
//output.print(", ");
//output.println(rpm);
timeold = millis();
}
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}