Trouble whith reading data

guys save me
processing code:

import processing.serial.*;
import controlP5.*;
Serial port;
ControlP5 cp5;
int start = 1;
void setup() {
   cp5 = new ControlP5(this);
   port = new Serial(this, "COM5", 9600);
}
void draw() {
   if (start == 1) {
     port.write("1\n");
     println(port.read());
     start++;
   }
}

arduino code:

void setup() {
   Serial.begin(9600);
}
void loop() {
   if(Serial.available()){
     char ss = Serial.read();
     Serial.println(ss);
   }
}

Why does it return -1 to the processing port?

See a difference? One sends a character and a line ending, the other receives a character and prints it. Next time around, the character read is the line ending character.

I tried whithout \n, result the same

Ok. I don't work with Processing, so I think you'll have to wait for someone conversant to happen along.

1 Like

Your topic has been moved. Please do not post in “Uncategorized”; see the sticky topics in Uncategorized - Arduino Forum.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an “About the _____ category” topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the “How to get the best out of this forum” guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.


Do you think the answer is ready to read nanoseconds after you sent something?

-1 means nothing to read

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.