Which serial ports can I safely map to GPIO on the X4?

Hi,

Which serial ports can I safely map to GPIO on the X4?

Perhaps a short example on the wiki would be useful :wink:

Thanks!

You need to use Serial1 object to map with GPIO pins. Any of pins (A, B, C, D) are available.
There is also Serial2, but it can’t be used.

void setup() {
  // Begin UART over GPIO pins (config: 8bit data, 1 stop bit, no parity)
  Serial1.begin(115200, SERIAL_8N1, GPIOA, GPIOB); // baud, config, rx, tx
}
int counter;
void loop() {
  // Use "Serial1" to print over GPIO pins
  Serial1.print("Test ");
  Serial1.println(counter++);
  delay(100);
}

Use standard Serial API to send and receive over UART. Using Serial1 will print to GPIO pins. Serial will print to Serial Monitor (over USB).
You can also remap Serial to GPIO pins if 2 UART streams are required.

Keep in mind, that this is only available in board v1.1. Older one’s (v1.0) GPIO pins aren’t connected to ESP32 directly.

Currently working on X4 improvements, so will add more information about it :wink:

Thanks for fast response :blush:

OK, that is clear so “Serial” are used for USB communication and “Serial2” for something directly on X4 board - right?

Correct. ESP32 processor has 3 UART peripherals, and you can choose how to utilize them. Inside Arduino they are defined as:

HardwareSerial Serial(0);
HardwareSerial Serial1(1);
HardwareSerial Serial2(2);

Serial - by default used for USB communication (but can be remapped).
Serial1 - free to use.
Serial2 - used by X4 itself internally (can’t use).

1 Like