Go Down

Topic: Connecting Processing to Arduino (Serial port) (Read 254 times) previous topic - next topic

marta99

Hello, I am beginner using arduino and I would like to know how to transfer two String arrays from Processing to Arduino or some hint to do it...

In processing, I tried:

Code: [Select]

//...
port.write(a[i]);
//...
port.write(b[i]);



And, in Arduino, I have:

Code: [Select]

//...
void setupVariable(){

  a=Serial.readString(); //concatenating arrays
  //Serial.println(a);
   
  }
//...

Robin2

I am not familiar with Processing.

For the Arduino side have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


It makes debugging much easier if you send data in human readable form. I would only send binary data if it was the only way to achieve the required performance.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

ieee488

Hello, I am beginner using arduino and I would like to know how to transfer two String arrays from Processing to Arduino or some hint to do it...

In processing, I tried:

Code: [Select]

//...
port.write(a[i]);
//...
port.write(b[i]);



And, in Arduino, I have:

Code: [Select]

//...
void setupVariable(){

  a=Serial.readString(); //concatenating arrays
  //Serial.println(a);
   
  }
//...

If you are going to send one byte at a time in Processing, then in the Arduino sketch you need to read one byte at a time.

     char aByte = Serial.Read();


.

Go Up