How to change IDE port allocations for ESP32 dev module

I have the following set up:
Micromod Main Double Board with:
Processor board: Teensy
F0: ZED-F9P GNSS (on teensy Serial1)
F1: ESP32-WROOM-32E WiFi/Bluetooth (on teensy Serial2)

Running the sketch below on the ESP32 echos data received via Bluetooth Serial to the USB-C Serial port (Serial) on the ESP32, and vice versa.

It also attempts to echo all the data to the Micromod teensy processor, but I have been unab le to get this to work using Serial1 or Serial2 on the ESP32 (OUTport in my sketch),

Test setup:
Run on the MicroMod ESP32-WROOM-32 module, as follows:

  • Compile for 'ESP32 Dev Module'
  • Upload via the USB-C port on the ESP32
  • press Reset (or Boot) during dots (.....) to complete flashing

Set up "Serial Bluetooth Terminal" (SBT) App on a mobile phone and pair it with
the ESP32. Open Serial Monitor to USB-C port on ESP32. Type a short text string
into the SBT and it should be echoed on the Serial Monitor (and OUTport), and vice versa.

If needed I am prepared to butcher the esp32 cores under:
... AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.6\cores\esp32
to add /modify the definition for the second Serial port but I don't know which files in the cores to change.

Any suggestions much appreciated.

#include <Streaming.h>

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig`
#endif

BluetoothSerial BT;

#define OUTport Serial2             // ESP32 port to MM Teensy processor  

void setup() {
  Serial.begin(115200); 
  while (!Serial && millis() < 1000);
  Serial << "\n\n======== ESP32_echo_BT.G ========\n";
  Serial << " * Open OUTport to Teensy : ";
  OUTport.begin(115200); 
  while (!OUTport && millis() < 1000);
  if (OUTport)  Serial << "OK\n";
  else          Serial << "** BAD **\n"; 
  Serial << " * Init BT (on 'ESP32_MM'): ";
  BT.begin("ESP32_MM");                                               //Bluetooth device name
  if (BT) Serial << "OK\n";
  else   {Serial << "FAILED ** program HALTED **\n"; while(true){}; }
  Serial << "------ setup done ------\n";
  }

// Echo data from ESP32 Serial Monitor to Bluetooth Serial,     and teensy
// Echo data from to Bluetooth Serial  to ESP32 Serial Monitor, and teensy
void loop() {
  if (Serial.available())  {
    char c = Serial.read();
    BT.write(c); 
    OUTport.write(c);             // also copy to teensy 
    }
  if ( BT.available()) {
    char b = BT.read(); 
    Serial.write(b); 
    OUTport.write(b);             // also copy to teensy
    }
  //delay(20);
  }

which GPIO pins are you using for Serial2
I generally specify the GPIO pins when opening Serial2, e.g.

#define RXD2 18
#define TXD2 19

void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200);
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);

many thanks horace, that works.

#define RXD2 16
#define TXD2 17
.
.
OUTport.begin(115200,SERIAL_8N1,RXD2,TXD2);

I also found the UART setups in HardwareSerial.h (in the ESP32 cores directory). If I editted this as follows it also works (but I prefer your solution):

#if SOC_UART_NUM > 2
#ifndef RX2
#if CONFIG_IDF_TARGET_ESP32
#define RX2 (gpio_num_t)16			// QQQQ was 4
#elif CONFIG_IDF_TARGET_ESP32S3
#define RX2 (gpio_num_t)19
#endif
#endif

#ifndef TX2
#if CONFIG_IDF_TARGET_ESP32
#define TX2 (gpio_num_t)17			// QQQQ was 25
#elif CONFIG_IDF_TARGET_ESP32S3
#define TX2 (gpio_num_t)20
#endif
#endif
#endif /* SOC_UART_NUM > 2 */

This suggested another approach:

#define RX2 16
#define TX2 17
.
.
OUTport.begin(115200);

but I couldn't get this to work.

click the Solution button at the bottom of the reply that answered the question - this helps others with a similar question

you need to look first. I did that yesterday when I replied, along with the like heart :slightly_smiling_face: