Recieving Array Thru Serial

I know this has been asked before, but I still can't seem a solid answer. What's the procedure for sending a series of integers thru serial port in a way arduino can recognize and parse? Here's my code- the arduino side of it is pretty limited as I've mostly been working in processing.

Arduino Code

[code]
#include <SoftwareSerial.h>

boolean started = false;
boolean ended = true;


 int recLine;
 int recVars[12]; // Data received from the serial port
 int ledPin = 13; // Set the pin to digital I/O 13
 int serialIn;
 int incomingByte;
 boolean code = false;

 void setup() {
   pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
   Serial.begin(9600); // Start serial communication at 9600 bps
 }
 void loop() {
   while (Serial.available()) { // If data is available to read,
   
   int incomingBtye = Serial.read();
   if(incomingBtye == 9) {
     started = true;
     ended = false;
   }
   else if(incomingByte == 999) {
     code = true;
   }
   else if(incomingByte == 8) {
     ended = true;
     break;
   }
   else {
     recVars[serialIn] = incomingByte;
     serialIn++;
     recVars[serialIn] = '\0';
   }
  }
  if(code == true ){
  digitalWrite(ledPin,HIGH);
    
   }
 }

[/code]

Processing Code

int letter;
int ypos = 25;
int Step = 0;

String  input = " ";
String currentString = " ";

String distance; 
boolean distanceRec = false;
float distanceFloat; 
int distanceInt; //SV0

String timer1;
boolean timer1Rec = false;
float timer1Float;
int timer1Int; //SV2

String relayTimer;
boolean relayTimerRec = false;
float relayTimerFloat;
int relayTimerInt; //SV4

String timer2;
boolean timer2Rec = false;
float timer2Float;
int timer2Int; //SV6

String speed;
boolean speedRec = false;
float speedFloat;
int speedInt; //SV8

String confirm;
boolean confirmVal = false;

int sendVars[] = {999,distanceInt,0,timer1Int,0,relayTimerInt,0,timer2Int,0,speedInt,888};



import processing.serial.*;
Serial myPort;

void setup() {
  size(640, 900);
  // Create the font
  textFont(createFont("SourceCodePro-Regular.ttf", 36));
  
 //Serial (quote to deactive debug)
// printArray(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
  background(0);
  textSize(14);
  
  text("Click on the program to begin, enter distance", 25, 25);
  text(input, 25, ypos, 540, 800);
  
  if(distanceRec == true && Step > 0) {
    text("Distance= ", 25, 400); 
    text(distance, 100 ,400);
    text("Enter Timer 1" ,25, 50);
  
  }
  
  if(timer1Rec == true && Step > 0) {
    text("Timer 1= ", 25, 425);
    text(timer1, 100 ,425);
    text("Enter Relay Time", 25, 75);
  }
  
   if(relayTimerRec == true && Step > 0) {
    text("Relay Timer= ", 25, 450);
    text(relayTimer, 125 ,450);
    text("Enter Timer 2", 25, 100);
  }
  
   if(timer2Rec == true && Step > 0) {
    text("Timer 2= ", 25, 475);
    text(timer2, 100 ,475);
    text("Enter Speed", 25, 125);
  }
  
  if(speedRec == true && Step > 0) {
    text("Speed= ", 25, 500);
    text(speed, 100 ,500);
    text("CONFIRM THESE VALUES? Y/N", 25, 150);    
  }
  
  if(confirmVal == true && Step > 0) {
    text("Executing...", 25, 525);    
    text(distance, 0, 550);
    text(timer1, 100, 550);
    text(relayTimer, 200, 550);
    text(timer2, 300, 550);
    text(speed, 400, 550); 
    

    
   // myPort.write(distance);
   // println(distance);
   noLoop();
  }
  
}
   


void keyTyped() {
    letter = key;
    input = input + key;  
    
    
   
    
   if(letter == ENTER && Step == 0) {
      distanceFloat = Float.parseFloat(input);
      //println(distanceFloat);
      distanceInt = int(distanceFloat);
      sendVars[1]  = distanceInt;
      distance = input;
      distanceRec = true;
      Step++;
      letter = 0;
      input = " ";
      ypos+=25;
   } 
    
   if(letter == ENTER && Step == 1) {
      timer1Float = Float.parseFloat(input);
      timer1Int = int(timer1Float);
      sendVars[3] = timer1Int;
      timer1 = input;
      timer1Rec = true;
      Step++;
      letter = 0;
      input = " ";
      ypos+=25;
   }
    
   if(letter == ENTER && Step == 2) {
      relayTimerFloat = Float.parseFloat(input);
      relayTimerInt = int(relayTimerFloat);
      sendVars[5] = relayTimerInt;
      relayTimer = input;
      relayTimerRec = true;
      Step++;
      letter = 0;
      input = " ";     
     ypos+=25;
   }
   
   if(letter == ENTER && Step == 3) {
      timer2Float = Float.parseFloat(input);
      timer2Int = int(timer2Float);
      sendVars[7] = timer2Int;
      timer2 = input;
      timer2Rec = true;
      Step++;
      letter = 0;
      input = " ";
     ypos+=25;
   }
   
   if(letter == ENTER && Step == 4) {
      speedFloat = Float.parseFloat(input);
      speedInt = int(speedFloat);
      sendVars[9] = speedInt;
      speed = input;
      speedRec = true;
      Step++;
      letter = 0;
      input = " ";
     ypos+=25;
   }
   
   if(letter == 121 || letter == 89 && Step == 5) { //if Y or y
      
      
     // println(sendVars[0],sendVars[1],sendVars[2],sendVars[3],sendVars[4],sendVars[5],sendVars[6],sendVars[7],sendVars[8],sendVars[9],sendVars[10]); //send value + space + 0 + space + nextValue "..." + ArrayEnd
      
      for (int i = 0; i < 11; i++) {
      myPort.write(sendVars[i]);
      print(sendVars[i]);
     // myPort.write(sendVars[10]);
      }
      
     // println(sendVars[1]);
      confirm = input;
      confirmVal = true;
      Step = 0;
      letter = 0;
      input = " ";
      ypos = 25;
       distanceRec = false;
      timer1Rec = false;
      relayTimerRec = false;
      timer2Rec = false;
      speedRec = false;
      timer1 = " ";
      relayTimer = " ";
      timer2 = " ";
      speed = " "; 
      input = " ";
      confirmVal = false;
   }
   
   if(letter == 78 || letter == 110 && Step == 5) { //if N or n
      distanceRec = false;
      timer1Rec = false;
      relayTimerRec = false;
      timer2Rec = false;
      speedRec = false;
      distance = " ";
      timer1 = " ";
      relayTimer = " ";
      timer2 = " ";
      speed = " "; 
      input = " ";
      letter = 0;
      Step = 0;
      
    //exit();
    // redraw();
   }
      
}

The examples in Serial Input Basics should be suitable. The technique in the 3rd example will be most reliable.
Basically it's just <val1, val2, val3>

...R

Uploaded code to board, no way for me to tell if it's working with processing sketch or not. Also, as soon as I upload it, the LED on pin 13 turns on. I was going to use that to test the communication. I've looked thru all of these examples and nothing seems to work

const byte numChars = 32;
char receivedChars[numChars];

boolean newData = false;

void setup() {
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
 // if (Serial.available() > 0) {
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

EDIT: So no one can help me? is this just something the arduino can't do? I'm not asking the world here...

int incomingBtye = Serial.read();

It is stupid to use a type in the name of a variable when the type in the name does not match the type of the variable.

Try something like intParse. It will receive ASCII characters from the serial port and parse them into integers.

You could also use functions like atoi and strtok to parse a character array into integers.

Henradrie:
Try something like intParse. It will receive ASCII characters from the serial port and parse them into integers.

You could also use functions like atoi and strtok to parse a character array into integers.

Did you perhaps mean parseInt?

Amazigh:
Uploaded code to board, no way for me to tell if it's working with processing sketch or not.

... SNIP ...

EDIT: So no one can help me? is this just something the arduino can't do? I'm not asking the world here...

Gimme a break. This is the first time I have seen your reply since I wrote Reply #1

I agree it is a problem to see if the program is working if you are communicating with the Arduino using the USB connection because you would need to write some code in Processing to display the responses from the Arduino. However that is not difficult and it is a useful feature for debugging purposes.

Try sending the same data to the Arduino using the Arduino Serial Monitor so that you can assure yourself that the Arduino code works. Using a communication protocol that can be used in the Serial Monitor is also convenient for debugging.

...R

Sorry for getting excited. I'm kind of in a bind. I think I have it working now. Thanks Robin for those tutorial examples.