Skip to main content

arduino-processing Arduino processing serial comunication - loosinglosing data?

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think theredata is being data lost along the way. I simply iterate over the array in Processing and send the Values seperatlyseparately. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When When I print out the string in processing, some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is therthere something I#mI'm missing in thermsterms of implementation, or is this simply an hardwarerelateda hardware related problem (like slightly differichdifferent clock speeds)? Is there any way to improoveimprove this.?

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=Serial.read();
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}

arduino-processing serial comunication - loosing data?

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think there is being data lost along the way. I simply iterate over the array in Processing and send the Values seperatly. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When I print out the string in processing some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is ther something I#m missing in therms of implementation or is this simply an hardwarerelated problem (like slightly differich clock speeds)? Is there any way to improove this.

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=Serial.read();
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}

Arduino processing serial comunication - losing data?

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think data is being lost along the way. I simply iterate over the array in Processing and send the Values separately. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When I print out the string in processing, some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is there something I'm missing in terms of implementation, or is this simply a hardware related problem (like slightly different clock speeds)? Is there any way to improve this?

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=Serial.read();
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}

deleted 16 characters in body
Source Link
devon
  • 3
  • 1
  • 4

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think there is being data lost along the way. I simply iterate over the array in Processing and send the Values seperatly. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When I print out the string in processing some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is ther something I#m missing in therms of implementation or is this simply an hardwarerelated problem (like slightly differich clock speeds)? Is there any way to improove this.

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   Serial.read();
   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=arr[i];str+=Serial.read();
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think there is being data lost along the way. I simply iterate over the array in Processing and send the Values seperatly. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When I print out the string in processing some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is ther something I#m missing in therms of implementation or is this simply an hardwarerelated problem (like slightly differich clock speeds)? Is there any way to improove this.

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   Serial.read();
   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=arr[i];
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think there is being data lost along the way. I simply iterate over the array in Processing and send the Values seperatly. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When I print out the string in processing some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is ther something I#m missing in therms of implementation or is this simply an hardwarerelated problem (like slightly differich clock speeds)? Is there any way to improove this.

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=Serial.read();
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}

Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link
devon
  • 3
  • 1
  • 4

arduino-processing serial comunication - loosing data?

I'm trying to send an array back and forth between Processing and an Arduino UNO. But I think there is being data lost along the way. I simply iterate over the array in Processing and send the Values seperatly. A new set of data is indicated by the character <. On the Arduino the data gets added to a string and sent back for testing. When I print out the string in processing some data changed to -1.

The array contains {1,2,3,4,5,6,7,8}

The Output looks like this:

12345678
12345678
1234-1-1-1-1
12345678
12345-1-1-1

Is ther something I#m missing in therms of implementation or is this simply an hardwarerelated problem (like slightly differich clock speeds)? Is there any way to improove this.

Arduino Sketch:

int srr[8];

int content; // Data received from the serial port
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 bps
}

 void loop() {
   String str = "val:";
   int test;
   if (Serial.available()){ // If data is available to read,
     content = Serial.read();
   }

   Serial.read();
   if (content == 60){
     for(int i=0; i<=7; i++)
   {
       str+=arr[i];
   }
   Serial.println(str);
   }
}

Processing

Serial myPort;  // Create object from Serial class
int arr[]={1,2,3,4,5,6,7,8};  //The array to send

String str;
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  //write
  myPort.write("<");
  for (int i =0; i<=7;i++){
    myPort.write(arr[i]);

  }
  //read
  if ( myPort.available() > 0){  // If data is available,
    str = myPort.readStringUntil('\n');         // read it and store it in val
    println(str); //print it out in the console
  } 

}