Go Down

Topic: More MATLAB Trouble (Read 1 time) previous topic - next topic

fayadAli

I can receive the characters but its not separating them in servo, pwm and pressure I knew it received them
I am seeing
[Here look at this: characters]
I passed here
"the values should be separated here but nothing
"second value"
"third value"
I passed here 

fayadAli

Here is the output after I try it

Hey, lookee here. I got a [7]
Hey, lookee here. I got a [.]
Hey, lookee here. I got a [9]
Hey, lookee here. I got a [6]
Hey, lookee here. I got a [6]
Hey, lookee here. I got a [9]
Hey, lookee here. I got a [,]
Hey, lookee here. I got a [6]
Hey, lookee here. I got a

  • Hey, lookee here. I got a [,]
    Hey, lookee here. I got a [4]
    Hey, lookee here. I got a

  • Hey, lookee here. I got a [.]
    Hey, lookee here. I got a [6]
    Hey, lookee here. I got a [3]
    Hey, lookee here. I got a [5]
    Hey, lookee here. I got a [5]
    Hey, lookee here. I got a [
    ]
    I passed here:



    Hey, lookee here. I got a [
    ]
    I passed here:

fayadAli

I tried printing right after each variable I got this
I am here9I am here96I am here966I am here9669I am here9669«I am here9669«I am here9669««I am here9669««I am here9669««I am here9669««I am here9669««I am here9669««I am here9669««I am here9669««I am here9669««This is PWMThis is PWMThis is PWMThis is
The servo starts to save the values after the second charachter received. PWM and pressure never get assigned any values

PaulS

Quote
Here is the output after I try it

OK. So, we have learned a great deal from this. We know that data is properly being sent to the Arduino, and we know that the Arduino is properly reading the data. We can see that the input stream does contain commas and a carriage return and a line feed.

Quote
I can receive the characters but its not separating them in servo, pwm and pressure I knew it received them
I am seeing
[Here look at this: characters]
I passed here
"the values should be separated here but nothing
"second value"
"third value"
I passed here 

So, you made a code change to learn this. I can't see what the code looks like, now.

Quote
I tried printing right after each variable I got this

More changes. No code posted.

Please post the code you have now. You are very close to getting this to work.

fayadAli

#24
Mar 31, 2012, 12:28 am Last Edit: Mar 31, 2012, 12:30 am by fayadAli Reason: 1
Code: [Select]

char servo[15], pwm[15], pressure[15];
void setup ()
{
 Serial.begin(9600);
 
 servo[0] = '\0';
 pwm[0] = '\0';
 pressure[0] = '\0';



} /////////////////////////////////////////////////////////////////////////////end of setup
/////////////////////////////////////////////////// here to process incoming serial data after a terminator received



void loop()
{
 char inData[15];

 inData[0] = '/0';
 int index = 0;
 int i =0;
 
 int x = 0;


 while((Serial.available() > 0) && (x== 0))  
 {
   char aChar = Serial.read();
   Serial.print("Hey, lookee here. I got a [");
   Serial.print(aChar);
   Serial.println("]");

   if (aChar == '\n'){
     x = 1;
   }
   if(aChar == ',')
   {
     switch (index){
     case 0:
       for (int k =0; k <15; k++){ ///copy indata to servo
         servo[k] = inData[k];
         Serial.print("I am here");
         Serial.print(servo);
       }
       index =1;
       inData[0] = '\0';
       i =0;
     case 1:
       for (int k =0; k <15; k++){
         pwm[k] = inData[k];
          Serial.print("This is PWM");
         Serial.print(pwm);
       }
       index = 2;
       inData[0] = '\0';
       i =0;
     case 2:
       for (int k =0; k <15; k++){
         servo[k] = inData[k];
           Serial.print(" Pressure");
         Serial.print(pwm);
       }
       inData[0] ='\0';
       index =3;
       i = 0;
     default:  
       inData[0] = '\0';
       i = 0;        
     }

   }

   else
   {
     inData[i++] = aChar; // Add the char to the array
   }
   if(x == 1)
   {
     Serial.print("I passed here: ");
     Serial.println();
     Serial.print(servo);
     Serial.println();
     Serial.print(pwm);
     Serial.println();
     Serial.print(pressure);
     Serial.println();
   }  



 }

}
[\code]

Go Up