Arduino board to board communication via UART

Hi,
I'm developing relay array switcher. What my scope is ,
Transmitter send relay ID array and status (ON/OFF) over UART. receiver receives the data packet and switch relays according to transmitted data.
I'm a beginner and I have no idea how to use PacketSerial and Serial Packet structure that is transmitted. Can some one guide me?

Don't make things complicated

Take a look at the techniques used in Serial input basics - updated and perhaps send <relayNumber, relayState>, parse it at the other end and use the values to control the relay

if you have less than (edit) up to 8 relay you can send the status in 1 byte and that makes handling the communication simple.
if you need more bytes then consider going to ASCII as @UKHeliBob hinted

Where does the less than 8 restriction come into it ? You could send the status of 8 relays in the 8 bits of a byte

@kaushm I thought that this question sounded familiar. Have you got a second account (@Vijan) ?

I have 32 relays. My packet format is |relay Status| ----- Ids-----.
I have an idea about this type of struct

struct Packet
	{
		struct WireFormatPacket
		{
			uint8_t size;
		};

		union WireFormat
		{
			WireFormatPacket packet;
			uint8_t bytes[20];
		};

		WireFormat wireformat;
	};

that's my point. if you have less than 8 you can fit that in a byte and then there is no need for a complex Serial protocol (assuming no transmission error). You just send the byte over.

if you have more than 8, then you'll need more bytes and that's where start or end marker and a more complex protocol come into play.

PS: I see what you might have meant "less than 8 relay" does not include 8. I should have said "up to 8"...

That's better :grinning:

Of course you could have saved 1 bit for parity :slight_smile: (but not what I meant...)

@kaushm please answer my questions about your accounts or run the risk of your account being deleted

Yes I can't access that account. So I created new one

Why not ?

If you want to send 'text' via UART instead of raw data (which may include 0x00 bytes)
Then check out the examples in Arduino to Arduino via Serial
which includes a sketch for parsing CSV data.
you can change your | to , or just change the delimiter in the sketch to |

1 Like