Emergency -->Arduino & Java

Hello guys firstly id like to thank you in advance for your reply . My problem sounds like this :

I have few sensors doesnt matter how many doesnt matter the pin i need an code example for taking the value from arduino sensor into my java gui and save it as an int . The problem is that i need it to be in a loop so it needs to have an constant update and i get to many datas and i do not know how to take each one and make it into a diffrent string . The connection works i get the numbers for example i get the temp x C and Humidity y % the problem is that the all come in the same line and i dont know how to extract x to temp and y to humidity .

I attached the code here . I need to finish this by tomorrow so i got only few hours left this would help me alot , thank you !! It doesnt have to be the same code it just need to save that variables into an int so i could use them as an label . Again i dont have any code problems is just that i am out of ideeas .

Test.ino (757 Bytes)

SerialClass.java (3.07 KB)

The problem is that i need it to be in a loop so it needs to have an constant update and i get to many datas and i do not know how to take each one and make it into a diffrent string .

Why is looping in the Java code a problem? Actually, the reading of reading of serial data happens asynchronously, as there is data, so the program already handles that part for you.

The fact that you can't parse H=xxx and T=xxx to determine which is which is not an emergency.

the emergency is that i need to get this done in a few hours and i dont know how i am new to arduino so an actualy code would help me more

Homework?

Asking for code here is never a good idea. Asking for java code in a C/C++ forum is just plain sill!

Mark

That doesnt help m8 and nope is not homework is an project im doing for an automated greenhouse via POE and i am using an arduino as an presentation i will use an PLC for the real one . I got the presentation tomorrow and i am not familiard with arduino .

the emergency is that i need to get this done in a few hours

The emergency is that poor planning happened, on your part.

and i dont know how

You don't know how to do what? Java does not run on the Arduino, so asking for Java help on the Arduino forum is like going to the Ford dealer and asking for advice on fixing your washing machine.

i am new to arduino

But, you don't appear to be having an Arduino coding problem.

so an actualy code would help me more

I'm sure that having some one else write the code for you would help your grade, but it won't do a thing for your goal of learning. That IS your goal, isn't it?

Please keep it civil.
OP, please don’t use txt; not everyone speaks teenager

I want to get those variables and show them into a label also to get an update on it . I am not used to get data from arduino so that is my problem . I allready addapted the soft to give commands when you press button all is left to do is to save the data from the arduino into variables and show them . I attached the source code if you run the program you get an infinit number of 2 variables in java tried to use a for and get them 2 by 2 , tryed with string tokenizer , tried to save them 2 by to in notepad then read from that notepad . If you could help me save them into diffrent variables and update i could easly continue from there.

This is not a java on a PC forum!

Mark

You need to decide how you're going to encode your messages from the Arduino to the Java application. I suggest that a textual encoding scheme would be the simplest to develop and debug and that Comma Separated Variable (CSV) would be the most obvious way to send a sequence of records each containing a fixed number of values.

On the Arduino side, you would just print your values separated by commas, and send a "\r\n" line terminator after the last value to tell the Java application where this line ends and the next ones starts.

On the Java side would read and buffer received characters until you reach the "\r\n" terminator, split the input line at the comma characters, and parse the resulting fields into integers. The Java to do that is trivial. I would be very surprised if Google didn't turn up working examples for you.

Found a way to get arrownd it thanks for the help , actualy i had searched on google only found video with gui just showing me that is possible . Worked with a strink tokenizer finaly after i used your advice .