Exchanging messages

This tutorial describes how to send and receive data frames between two nodes using the DecaDuino library.

Library installation

Download the DecaDuino library from the official repository.

As usual with Arduino, the DecaDuino library comes with some example sketches. These sketches are available in the Arduino IDE menu:

File > Examples > DecaDuino

Make a data sender

The sketch DecaDuinoSender illustrates the use of the DecaDuino library to send messages over the UWB radio.

After initializing the transceiver, the sketch periodically:

  • creates a frame of MAX_FRAME_LEN bytes (120 bytes),
  • sends it by calling decaduino.pdDataRequest(),
  • waits until the frame has been sent by the transceiver with while (!decaduino.hasTxSucceeded());,
  • waits for 1 second.

Flash a first DecaWiNo board with this sketch and prepare another DecaWiNo with a receiver (see next paragraph).

Make a data receiver/frame sniffer

The sketch DecaDuinoReceiverSniffer shows the use of the DecaDuino library to receive messages over the UWB radio.

After initializing the transceiver, the sketch enables the receiver then waits for a new frame. When a frame is received:

  • The local sequence number of the frame is printed,
  • The size of the frame is printed,
  • The bytes of the frame are printed in hex,
  • The receiver is re-enabled. In future home-made sketches, do not forget to re-enable the receiver after each reception!

This sketch can be used as a frame sniffer to dump received messages. Used with the DecaDuinoSender sketch, the results is:

Make a chat application between several DecaWiNos

The sketch DecaDuinoChat illustrates the use of the DecaDuino library to send and receive ASCII messages submitted through the Serial port over the UWB radio.

The sketch is implemented as 3 non-blocking “processes”:

  • A getchar process that gets characters from the Serial and prepares a buffer with incoming chars,
  • A sender process that sends the buffer when a NL (New Line) or CR (Carriage Return) character is received,
  • A receiver process that prints the received frame as an ASCII string.

On the sniffer, the ASCII code of each char is printed in hex.