Sending data from arduino to processing, serially.

I have an arduino duemilanove. I'm trying to send an array of positive and negative floating point numbers, stored within the arduino, to processing.
I was going one step at a time by sending a single byte by using the following code and it worked perfectly.

void setup()
{
  Serial.begin(9600);
}
byte a=43;
void loop()
{
   Serial.write(a);
 }

And this is the processing sketch.

import processing.serial.*;

Serial myPort;
void setup()
{
  String portName = "COM4";
 	 	
   myPort = new Serial(this, portName, 9600);
}
void draw()
{
  if(myPort.available()>0)
  {
  println(myPort.read());
  delay(1000);
  }
  else
  {
  println("no devices found");
  }
}

But, by using "byte" datatype i can send only values between 0-255. How can i modify the above programs so that i can send and receive negative and positive floating point numbers.

Thanks.

Sendit as a string from the arduino.
Then on the Processing side set up the serial to give you an interrupt when it sees a CR, in that call just read the whole string and then convert it.

How can i modify the above programs so that i can send and receive negative and positive floating point numbers.

As Mike says, you can send data as a string. But, where are these floating point values coming from? What is Processing going to do with them? Floating point processing is not the Arduino's strong suit. so making Processing do the conversion from string to float or from int to float would be a better idea, if that is realistic.

Thanks a lot. It worked. I sent the values as string, received them as string in processing and then converted them back to float. Actually i'm trying to simulate an inertial measurement unit, using processing. :slight_smile:

Good. :slight_smile:
As Paul says you would be better shipping over the integer values from the arduino and having any any calculation that result in a floating point number performed in processing as that saves time using the power of you main computer to do the time intensive task of floating point arithmetic.