Read data from serial and wait for two bytes to be recieved

I am relatively new to programming the Arduino, and I've seen example programs which use Serial.available() > 0 and read the byte in the buffer, but I'm looking for some example code that waits for a pair of bytes, and sets the value of two variables, each variable for each byte received.

Since I am pretty new to programming the Arduino, so I'd be very grateful to anybody who would be willing to create some example code which does what I described above.

First of all have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

If you can, it is easiest if you receive the entire message before trying to figure anything out.

However you have not given us any information about the type or length of the data you are trying to receive.

...R

If it helps, the type of data I'm trying to receive is some unsigned 8 bit raw byte data.

Also, keep in mind that I opened this thread looking for somebody to reply with some example code that receives two bytes, not for somebody to tell me that I asked the question wrong and then refer me to some code that doesn't execute the criteria I listed. :frowning:

Well, bear in mind that this forum is for paid assistance or finding someone to work on a project with you. There are other fora for general help. That said: this should work

while (Serial.available < 2)
    delay(100);

int b1 = Serial.read();
int b2 = Serial.read();

There are "better" ways to do it but this is straightforward and easy to follow.

There are "better" ways to do it but this is straightforward and easy to follow.

So is

   if(Serial.available() > 1)
   {
      v1 = Serial.read();
      v2 = Serial.read();
   }

without the need for blocking code.