Sending packets to Arduino


i'm working on project controlling robot powered arduino uno through bluetooth shield. objective to  send 16-bit packets on serial , have no idea begin. need better understanding of how create packet , send arduino. there basic examples me started?

this sketch here can receive packet of data in format, <aaa,bbb,cccc...z>
code: [select]
int buffer[8]; // adjust size of data receiving, example receiving no more 8 ints
int counter = 0;

void setup(){
 serial.begin(115200);
}

void loop()
{
 if(serial.available() > 0)
  {
   char temp = serial.read(); // example incomming data <1,23,456,7890>
   if( temp == '<' ) // incoming char equal <, if gather rest
   {
     counter = 0; // make sure counter set zero
     while(1)
     {
       if(serial.available() > 0)
       {
         char temp = serial.read(); // read in incoming char
         
         if(temp != ',' && temp != '>')
         {
           buffer[counter] = (buffer[counter]*10) + (temp - '0');// converts temp int stores it
         }

         if(temp == ',') // split data comma
         {
           counter++; // increment buffer index
         }

         if(temp == '>') // if incoming char >, break out of loop
         {  
           break; // breaks out of while loop
         }
       }
     }
   }
   for(int num = 0; num <= counter; num++) //will output "1,23,456,7890"
    {
    serial.print(buffer[num]);
    if(num != counter) serial.print(",");
    }
    serial.println();
 }

 while(counter != -1)
 {
   buffer[counter] = 0;
   --counter;
 }
}


you can use sprintf() structure packet sent, so:
int output[10]; // create array large enough hold newly formed string.
sprintf(output, "<%d, %d, %d, %d>", data1, data2, data3, data4);

send output either serially or whatever.


Arduino Forum > Using Arduino > Project Guidance > Sending packets to Arduino


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support