Serial Comms Arduino-Arduino

Hi there,

I have two Arduinos, connected to each other via a serial link (xbee point to point, but its transparent and already set to 9600 baud)

The first arduino reads 8 one-byte values in from a function, which i’m then outputting over serial preceded by a “<<” and capped with a “>>”.

void action() {
  
  xbee.print("<<");
  xbee.print(dmxvalue[0]);

  xbee.print(dmxvalue[1]);

  xbee.print(dmxvalue[2]);

  xbee.print(dmxvalue[3]);

  xbee.print(dmxvalue[4]);

  xbee.print(dmxvalue[5]);

  xbee.print(dmxvalue[6]);

  xbee.print(dmxvalue[7]);
  xbee.print(">>");
  
}

(xbee is my softwareserial node, running 9600baud)

I need to shift this out into 8 byte variables again at the other end - the idea being that if the first two bytes aren’t “<<” the data is treated as corrupt and dumped, waiting for the next cycle.

I’m at a loss as to how to do this. I’ve tried various different methods that all didn’t seem to work. The most important thing is making sure that the incoming data is valid, as this is for a lighting controller.

Help? I’ve never managed to do particularly well with serial comms for anything but debugging…

One thing i did consider is switching the xbees to API/packet mode, and sending the data in packets, but i’ve no clue how to do that.

If dmxvalue is declared like so:

byte dmxvalue[8];

Then, you should be using either Serial.write(dmxvalue_); or Serial.print(dmxvalue*, BYTE); to prevent converting the numbers to strings prior to sending.*_
On the receiving end, you should receive all 12 values (the 2 <, the 8 bytes, and the 2 >), and confirm that the first 2 are < and that the last 2 are > before concluding that you got good data.
The middle 8 bytes, then, are the values that are of interest.