Go Down

Topic: Serial communication "protocol" with Raspberry (Read 723 times) previous topic - next topic

sotomaior

paul, thanks a lot your posts are always full of infos!

i tried to test your program but i am probably missing something in sending the command via serial:

Code: [Select]
#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(9600);
   pinMode(13, OUTPUT);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }
  if (strcmp(inData, "loo:99" ) == 0) {digitalWrite(13, HIGH);}
  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}


i typed <l00:99> and nothing happend, what's the deal?

PaulS

You need to move the code to compare the string to INTO the if(started && ended) block.

sotomaior

thanks a lot, u solved my "deal of the day", now i can continue my domotic software  XD

Go Up