Skip to content

Serial Ports

Rhomb.IoT uses Arduino in the background to handle with some important parts, like Serial ports management.

Serial/UART port availability depends on the microcontroller being used. Rhomb.IoT defines by default up to 3 UART ports with different purposes:

  • SERIAL_DEBUG: Used to print debug output to the terminal
  • SERIAL_S1: Used to communicate the MCU with a Slave Module on Socket 1
  • SERIAL_S2: Used to communicate the MCU with a Slave Module on Socket 2

Default macros used to configure each port:

#define USE_SERIAL_SOFTWARE false   // Load Arduino SoftwareSerial Library
#define SERIAL_DEBUG RH_UART_DEBUG  // Serial object for debug monitor
#define SERIAL_DEBUG_BAUDS 115200   // Speed
#define SERIAL_DEBUG_RX 0           // If software serial enabled, tx pin
#define SERIAL_DEBUG_TX 0           // If software serial enabled, rx pin
#define SERIAL_DEBUG_WAIT false     // wait after begin() for leonardo and zero
#define SERIAL_S1 RH_UART_A         // Serial for Slave Module on socket 1
#define SERIAL_S1_BAUDS 115200      // Speed
#define SERIAL_S1_RX 0              // If software serial enabled, tx pin
#define SERIAL_S1_TX 0              // If software serial enabled, rx pin
#define SERIAL_S1_WAIT false        // wait after begin() for leonardo and zero
#define SERIAL_S2 RH_UART_B         // Serial for Slave Module on socket 1
#define SERIAL_S2_BAUDS 115200      // Speed
#define SERIAL_S2_RX 0              // If software serial enabled, tx pin
#define SERIAL_S2_TX 0              // If software serial enabled, rx pin
#define SERIAL_S2_WAIT false        // wait after begin() for leonardo and zero

These macros are internally defined by Rhomb.IoT on the file serial/serial-arduino.h. To overwrite the default values you can re-define them in the conf-user.h file.

For example, the serial port on the socket 1 (SERIAL_S1) has a default baud speed of 115200, to change this value to 9600 re-define this macro in file conf-user.h

// File conf-user.h
#define SERIAL_S1_BAUDS 9600

Don't Touch My Ports!

Usually you will not need to make any changes to the serial port configuration, Rhomb.IoT includes a default configuration to suit the microcontroller you are using.

This is done using the rhio-pinmap.h library, which includes the serial port definitions for each MCU. These are RH_UART_DEBUG, RH_UART_A and RH_UART_B. These macros are assigned an Arduino HardwareSerial object depending on the availability of the microcontroller. See this table:

MCU SERIAL_DEBUG SERIAL_S1 SERIAL_S2
ESP32 Serial Serial Serial2
ESP8266 Serial Serial1 -
SAMD21 SerialUSB Serial1 Serial
ATMEGA2560 Serial1 Serial Serial2
ATMEGA32U4 Serial Serial1 -
ATMEGA328P SOFTWARE_SERIAL (not available on USB port) Serial (USB PORT and Socket 1) -

For this reason by default you will not find any configuration macro for the serial ports in the file conf-user.h, these macros are already defined by default in the file serial/serial-arduino.h, however you can re-define any of these macros in the conf-user.h to overwrite it

Physical Access to Ports

The image shows where the Serial ports reside on a Deimos PCB, you can use the rhomb.io Wizard to get information for other PCBs such as Halley.

Serial Ports on Deimos

Hardware Serial Limitations

As already mentioned, not all microcontrollers have all the necessary UART ports. This is a summary of the limitations that we can find:

MCU Limitations
ESP32 It only has 2 serial hardware, SERIAL_DEBUG and SERIAL_S1 are the same port, both working on Socket 1 and USB port. SERIAL_S2 is connected to Socket 2
ESP8266 SERIAL_S2 is not available. SERIAL_DEBUG is Serial and SERIAL_S1 is Serial1 (they are not linked linke in ESP32).
SAMD21 It has 3 serial ports, SerialUSB on SERIAL_DEBUG, Serial1 on SERIAL_S1, and Serial on SERIAL_S2
ATMEGA2560 Has enough ports: SERIAL_DEBUG=Serial, SERIAL_S1=Serial1, SERIAL_S2=Serial2
ATMEGA32U4 SERIAL_S2 is not available.
ATMEGA328P SERIAL_S2 is not available. SERIAL_DEBUG and SERIAL_S1 are the same port but SERIAL_DEBUG is configured with Software Serial and linked to two custom TX/RX pins, according to the PCB in use

Comments