Medium: Hardware/Software Serial port | Pins used: 1 or 2

With ThroughSerial strategy, PJON can run through a software or hardware Serial port working out of the box with many Arduino compatible serial transceivers, like RS485 or radio modules available on the market. Take a look at the video introduction for a brief showcase of its features.

Why PJON over Serial?

Serial communication is fast and quite reliable but it is often useless without all the features PJON contains. ThroughSerial has been developed to enable PJON to run through a serial data-link. Adding PJON on top of Serial it is possible to leverage of the PJON protocol layer features like acknowledge, addressing, multiplexing, packet handling, 8 or 32-bit CRC and traffic control.

How to use ThroughSerial

Pass the ThroughSerial type as PJON template parameter to instantiate a PJON object ready to communicate through this Strategy.

  PJON<ThroughSerial> bus; // 2 pin over-sampled data link layer

Call the begin method on the Serial or SoftwareSerial object you want to use for PJON communication and pass it to the set_serial method:

  /* Set 5 milliseconds (default) as the maximum timeframe for byte reception.
     This value depends on the latency, baud rate and computation time.
     Always set TX_MAX_RESPONSE_TIME > (byte transmission time + latency) */
  #define TS_BYTE_TIME_OUT      5000

  /* Set 10 milliseconds as the maximum timeframe between transmission and
     synchronous acknowledgement response. This value is strictly related to
     the maximum time needed by receiver to receive and compute the packet. */
  #define TS_RESPONSE_TIME_OUT 10000
  /* If it leads to unacceptable loop time duration consider to use asynchronous
     acknowledgement instead, set TS_RESPONSE_TIME_OUT to 0 and call the
     following methods in the setup:
       bus.set_asynchronous_acknowledge(true); */

  /* Set the back-off exponential degree (default 4) */
  #define TS_BACK_OFF_DEGREE 4

  /* Set the maximum sending attempts (default 20) */
  #define TS_MAX_ATTEMPTS   20

  #include <PJON.h>

  PJON<ThroughSerial> bus;

  void setup() {

For a simple use with RS485 serial modules a transmission enable pin setter has been added:


All the other necessary information is present in the general Documentation.

Known issues

  • Being PJON not an interrupt driven, its communication can be affected and potentially disrupted by long delays added in the user's sketch. Try to reduce as possible the interval between every receive call.

This document is automatically generated from the github repository. If you have noticed an error or an inconsistency, please report it opening an issue here