Use CmdMessenger Over UART?

I need to send commands and data bidirectionally between two Arduinos over TTL a serial link. i.e. RX and TX with RTS, CTS flow control.

I'd like to be able to send commands (preferably human readable) and data in either direction. When commands are received they should be parsed and dispatched as callbacks.

I see that CmdMessenger does this between an Arduino and a host computer.

Can it be configured to communicate over a UART instead of the USB port?

Or is there another library that than do this?

The regular Arduinos (Uno, Mega etc) don’t support hardware flow control. I guess it is not too difficult to implement it in software. But do you really need it?

For my communication between Arduinos I use the code in the 3rd example in Serial Input Basics

You can send data in a compatible format with code like this

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R

chrisgr99:
I see that CmdMessenger does this between an Arduino and a host computer.

Life would have been easier if you posted a link :wink: This one ?

If so, I quickly glanced over it and can't see any references to the use of cts or rts; can you point them out?

between two Arduinos over TTL a serial link

That's not quite clear to me; is it just ttl-to-ttl? Or is there something in between?

RTS, CTS flow control

It probably isn't too complicated to code that. Two additional pins.

If the device wants to send, 'assert' RTS, wait for the other side to 'assert' CTS and next send using standard serial writes (!); not sure when signals need to be 'de-asserted'. This is the original spec for comms between DTE and DCE (uni-directional handshake)

The 'newer' RS232 standard defines the RTS and CTS signals differently. You can now connect RTS at the one end to CTS at the other and vice versa. RTS now means ready-to-receive (RTR) and when the sender sees it, it can send data; again using serial writes. This allows bi-directional handshake.

It's important to use Serial.write() and send a single byte and check the status of the lines after each write to see if the other side has not 'de-asserted' the RTS line.

Sorry for the confusion. The question wasn't about about flow control. I'm using a Teensy 3.2 which supports hardware flow control and I have flow control working. The detail about RX, TX and flow control was just to describe the type of serial connection I'm using. I'm using flow control because the data will come in bursts that I want to be able to transfer in as short a time as possible for low latency and I don't want to have to worry about buffer overflows.

My real question was in the title of the post: "Use CmdMessenger over a UART?".

Normally CmdMessenger is used over the serial USB link to a host computer but I would like to use it between two Arduinos (Teensy 3.2's).

Or is there some other library that supports sending commands and data between Arduinos, preferably with callbacks when commands are received?

What you're looking for is a protocol. You can design (and code) your own one quite easily or base it on the CmdMessenger code.

Robin already gave you a link for the receiving side and an example how to send. What is missing (if I recall CmdMessenger correctly) is an acknowledge when a message is received.

Thanks. I'll probably use CmdMessenger and modify it as necessary.

I know I could have developed my own protocol but given the huge number of Arduino libraries I thought there might have been an existing one that does exactly I need. i.e. A higher level wrapper around bidirectional Arduino-Arduino communication/data transfer. It seems like that would be a useful thing.

chrisgr99:
A higher level wrapper around bidirectional Arduino-Arduino communication/data transfer. It seems like that would be a useful thing.

You could always write one and share it with us.

The code I referred to in Reply #1 works well for me.

…R

You mention wanting to transmit/receive readable data which makes creating a protocol a little easier.

Fortunately the methods required are already available in the Arduino environment. Robins tutorial describes a way to "frame" the data and there is an Arduino library that will calculate the CRC32 checksum (CRC32.h).

A pretty good start to your protocol might begin as the following

[SOH] [Len of Data] [DATA] [Checksum] [EOT]

The data can contain for example the device address followed by the device command/query

If the data is valid you return [ACK] else you return [NAK]

Using the length of data and the checksum should catch any data errors should they occur. The library file has a couple of really simple examples to get you started.

I don't believe any of this would be too difficult and it would surely be a self gratifying project.