Processing Code Help Needed

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
  }

Try setting the timeold variable to current time plus about five seconds to allow the arduino to go through its reset before you try and talk to it.

What code is your arduino rumming?

It currently has the standardfirmata example running on it. The change in timeold had no effect. Any other ideas?

I am trying to read two temperature sensors using Processing.

What kind of temperature sensors? Are they really analog devices?

They are DS18B20 sensors. I looked them up and realized they are digital. However, I have tried using them as digital as well and had no luck with the same results.

http://playground.arduino.cc/Learning/OneWire
There's more to reading the DS18B20 sensor than just analogRead() or digitalRead(). Firmata doesn't understand that.

I have created code for the arduino for them to work. However, I am trying to control the arduino board solely through processing. Is it possible to use this sensor directly with processing?

Is it possible to use this sensor directly with processing?

Yes. But, NOT using Firmata. Processing can send a message to the Arduino - "Hey, what's the temperature inside?" or "Hey, what's the temperature outside?" (Or, something similar but easier to parse).

The Arduino can see the message ("" or ""), and decide whether to read the inside sensor or the outside sensor (assuming one is inside and one is outside). If not, use 1 and 2, instead of I and O. The Arduino then replies with the temperature as a string.

Thanks! I'll try it out.