Receiving 3 data from arduino to processing

edited September 2015 in Library Questions

Dear All,

I am new to JAVA and processing. Can you tell me that how can I receive three serial data from arduino uno.

I am sending three parameters from arduino as.

Serial.print(i);
Serial.print(",");
Serial.print(D1);
Serial.print("_");
Serial.print(D2);
Serial.print(".");  // termination.

But I do not know how to receive the three different data. Yet I am sucessful to receive TWO of them.

Please help me Sir/ Madam

Answers

  • edited September 2015

    I have tried with this.. please check

    void serialEvent (Serial myPort) { // starts reading data from the Serial Port // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data". data = myPort.readStringUntil('.'); if(data != null){ data=trim(data); int inputs[] = int(split(data, ',')); if(inputs.length == 3){ iAngle = inputs[0]; iDistance = inputs[1]; iDistance2 = inputs[2]; } } }

  • edited September 2015

    Please see the above codes and tell me is their any thing wrong. I am not getting the value of iDistance2 i.e., third value from the serial port.

  • edited September 2015

    Heee... I got the answer.

    the code should be like this

    ` void serialEvent (Serial myPort) {

    data = myPort.readStringUntil('.'); if(data != null){

    String[ ] a = split(data, ','); println(a[0]); //print Value1 (in cell 1 of Array ) println(a[1]); //print Value2 value println(a[2]);

    iAngle =int(a[0]); iDistance = int(a[1]); iDistance2 = int(a[2]);

    }
    

    } `

Sign In or Register to comment.