Sending parameters to Java

Hello all,

Even though I'm kinda new to Arduino, I'm a bit ashamed to ask something simple as USB communication here. Especially because there are loads of tutorials to be found online (even on the arduino.cc homepage)

But still... I haven't been able to get it to work =/

Just for starters, I want to have my arduino to send numbers/words to the PC, and read it in Java.
Anyone have a good tutorial for that? one that does include Java example code?

Thanks in advance :wink:

With kind regards

Azziplekkus

Just for starters, I want to have my arduino to send numbers/words

Serial.print("Some words...");
int stuff = 14;
Serial.print(stuff); // Send a number

and read it in Java.

Java doesn't run on the Arduino. Can't help you there.

Yes, I know how to "send" it. But if I want to read this in Java it will say

"Some words...14"

Sometimes it even does this (if I had put it in a loop)

"Some word
s...14"

"So
me words...14"

"Some words 
...14"

"Some words...1
4"

"So
me words...14"

It reads every character seperatly, and prints it in console.
This way, I can't get the strings and integers out of the stream... =/

Got any idea on how to do this?

Got any idea on how to do this?

Of course.

Serial.print("<"); // Send a start marker
Serial.print("Some words");
Serial.print(",");
Serial.print(someVariable);
Serial.print(",");
Serial.print(anotherVariable);
Serial.print(">"); // Send an end marker

Then, the Java applications needs to append characters to the string, starting when it sees the <, and stopping when it sees the >. Use the data only after you see a >.

Mhmmm, do you know how I can write that in Java? I'm a noob programmer =/

Mhmmm, do you know how I can write that in Java?

So it runs on the Arduino? You can't.

No, I mean how do I write that in Java? So I can get the strings out again?

EDIT: nevermind, a friend of me helped me with writing the code :slight_smile:

Please write the java code

PaulS:

Mhmmm, do you know how I can write that in Java?

So it runs on the Arduino? You can't.

He meant that he wants with the Arduino via serial port using Java as the in-between-er to fetch and send the data over the serial port to the Arduino. That, sir, can be done. He does not want to run Java code on the Arduino. He says:

I want to have my arduino to send numbers/words to the PC, and read it in Java

Anyhow, here are a few links on how to start a serial connection on Java to read data from a serial port:
http://www.java-samples.com/showtutorial.php?tutorialid=11
and