Secret Serial Port For Arduino/ESP32

If you use the Arduino IDE to program the ESP32, you might be interested in [Andreas Spiess’] latest video (see below). In it, he shows an example of using all three ESP32 UARTs from an Arduino program. He calls the third port “secret” although that’s really a misnomer. However, it does require a quick patch to the Arduino library to make it work.

Just gaining access to the additional UARTs isn’t hard. You simply use one of the additional serial port objects available. However, enabling UART 1 causes the ESP32 to crash! The reason is that by default, UART 1 uses the same pins as the ESP32 flash memory.

Luckily, the chip has a matrix switch that can put nearly any logical I/O pin on any physical I/O pin. [Andreas] shows how to modify the code, so that UART 1 maps to unused pins, which makes everything work. it is a simple change, replacing two parameters to a call that — among other things — maps the I/O pins. You could use the technique to relocate the UARTs to other places if you choose.

If you want to learn more about the ESP32, we covered a good set of tutorials for you to check out. Or if you just want a quick overview, you can start here.

19 thoughts on “Secret Serial Port For Arduino/ESP32

    1. It’s not hidden, the guy is just didn’t RTFM. The HardwareSerial::begin function he modifies can take parameters to override default assignments (as can be seen at 3:14). Had he simply ran Serial1.begin(115200, config, 4, 2) it would work without changing any “hidden” code (although I would have to read more of that file to find value for config).

    2. Some dislike Arduino for perpetuating bad coding practices.
      However, like Visual Basic it will have a fanatical user base for years to come, and the ESP32 hardware at least has better options like the FreeRTOS SDK.

    1. Look at the real ESP-IDF, which is a lot more mature than the Arduino environment. Alternatively, if you want easy: go for Micropython. That ecosystem is maturing relatively fast, especially with the SHA2017 badge happening. It’s actually quite usable.

    2. Because this is not an Arduino.
      The fake Arduino core is just a wrapper around the ESP-IDF.
      Before getting my ESP32 I read documentation and looked in Github at both ESP-IDF and Arduino-ESP32.
      The official framework is under heavy development, and the Arduino core is a bit behind that. But if you really want to use something which is not in the Arduino core, you can always use the original C stuff.
      For example I’m now making myself a C++ wrapper class for the IR remote controller code, which is “hidden”.

  1. I suspect this is why my attempt at setting up an Iridium ROCKBlock 2 modem is failing.
    Well i am hoping that is all it is. Tried sefining Serial2 and the ESP32 just keeps crashing.

Leave a Reply to MikrySoftCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.