Communicating Between Teensy 4.1 and Firebeetle ESP-32E Using UART

jgangano

Member
Hello,

I was following this guide between a microcontroller and an ESP 32, where its simple communication.

Teensy 4.1 Code
Code:
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println("Hello Boss");
  delay(1500);
}

Code:
#define RXp2 3
#define TXp2 1

ESP32=E Code

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXp2, TXp2);
}
void loop() {
    Serial.println("Message Received: ");
    Serial.println(Serial2.readString());
}

So what's basically happening is that Teensy is continually printing out "Hello Boss" on the serial monitor, but whenever I upload the code to my ESP32, I'm not getting

Code:
Message Recieved:
Hello Boss

and whenever I try to press reset on my ESP32 I get a bunch of garble

� % L0N �!!!��)�1�!��

If someone can help me understand why I'm getting the things I'm getting, I would really appreciate it.
 
The Teensy using the wrong port doesn't explain the junk output. You should at least be getting "Message Received:". Double check the baud rate settings on your terminal that is viewing the output.
 
The Teensy using the wrong port doesn't explain the junk output. You should at least be getting "Message Received:". Double check the baud rate settings on your terminal that is viewing the output.
I checked the baud rate for both the Teensy and on the ESP32, and they're both on 9600.
 
While @AndyA's remark is certainly valid, I would focus on the serial port connection first like @jmarsh indicated.
Your Teensy code should look like this:
C++:
void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.println("Hello Boss");
  delay(1500);
}
This assumes pins 0 & 1 of the Teensy to be wired to your ESP32 pins 1 & 3 (don't forget the ground wire between Teensy and ESP32).
See also this page for more info:
The most common issue with serial ports on Teensy is use of code designed for Arduino Uno with Serial within the code. On Teensy, Serial accesses the USB only. USB and Serial1 (pins 0 & 1) are not shared on Teensy. For hardware serial ports, Serial1, Serial2, Serial3, Serial4, Serial5, Serial6, Serial7 or Serial8 must be used.

By the way, are you using Arduino IDE V2.x.x?

Paul
 
Well, gave it a try myself.
Took me some time to find out that I had to use the HardwareSerial class to receive data by my ESP32-C3 SuperMini board...
Anyway, it's working now:

Untitled.png

Teensy 4.0 code:
C++:
void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.println("Teensy here");
  delay(1000);
}
ESP32-C3 code:
C++:
HardwareSerial MySerial(0);  //Create a new HardwareSerial class.

void setup() {
  Serial.begin(115200);
  MySerial.begin(9600);
  MySerial.setTimeout(100);
}
void loop() {
  while (MySerial.available() > 0) {
    Serial.print("Message received: ");
    Serial.print(MySerial.readString());
  }
}
And this is my setup:

IMG_20240316_120537.jpg

Only connected a green wire from Teensy TX pin to ESP32-C3 RX pin (and the obvious GND connection).

Paul
 
Took me some time to find out that I had to use the HardwareSerial class to receive data by my ESP32-C3 SuperMini board...
Actually not... Serial0.begin also works for the ESP32-C3 UART #1.
C++:
void setup() {
  Serial.begin(115200);
  Serial0.begin(9600);
  Serial0.setTimeout(100);
}
void loop() {
  while (Serial0.available() > 0) {
    Serial.print("Message received: ");
    Serial.print(Serial0.readString());
  }
}

Paul
 
Actually not... Serial0.begin also works for the ESP32-C3 UART #1.
C++:
void setup() {
  Serial.begin(115200);
  Serial0.begin(9600);
  Serial0.setTimeout(100);
}
void loop() {
  while (Serial0.available() > 0) {
    Serial.print("Message received: ");
    Serial.print(Serial0.readString());
  }
}

Paul
Hi Paul,

Thanks for helping me out

I've tried doing your Teensy code on my 4.1 and your ESP-C3 on my ESP-E, but I'm getting this super weird error.
1710637952271.png


I've searched up the specific error, but it's not really that helpful.

1710638029449.png


For my set up I've connected: Teensy TX -> ESP32 RX, Teensy RX -> ESP32 TX, GND -> GND. I've also attached a 10uF elec capacitor between GND and EN of the ESP32. But for some reason it's saying my TX path is down.

1710638344795.png
 
Actually not... Serial0.begin also works for the ESP32-C3 UART #1.
C++:
void setup() {
  Serial.begin(115200);
  Serial0.begin(9600);
  Serial0.setTimeout(100);
}
void loop() {
  while (Serial0.available() > 0) {
    Serial.print("Message received: ");
    Serial.print(Serial0.readString());
  }
}

Paul
Wait hold on, I changed the baud rate, and whenever I press the reset on my ESP32 I get this message.

1710638607824.png


I'm not getting the "Message received: Hello from teensy" that you are getting.
 
Last edited:
If I understand this section of the FireBeetle board WIKI correctly, pins 1 & 3 are used for the serial communication to the PC/Arduino IDE.
For a comm link to the Teensy, you need to use UART2 (Serial2) on pins 16 & 17.
Your code would look like this:
C++:
void setup() {
  Serial.begin(115200);
  Serial2.begin(9600);
  Serial2.setTimeout(100);
}
void loop() {
  while (Serial2.available() > 0) {
    Serial.print("Message received: ");
    Serial.print(Serial2.readString());
  }
}
Would you mind to give that a try?

Paul
 
Tried the above code on a different ESP32 module and it works.
This DOIT ESP32 DEVKIT V1 module also shares the first serial port [TX0 & RX0] with the onboard serial-to-usb converter and thus is not usable for external comms. So had to use TX2 & RX2.

1710672320736.png


1710672373237.png


Paul
 
Tried the above code on a different ESP32 module and it works.
This DOIT ESP32 DEVKIT V1 module also shares the first serial port [TX0 & RX0] with the onboard serial-to-usb converter and thus is not usable for external comms. So had to use TX2 & RX2.

View attachment 33706

View attachment 33707

Paul
Hi Paul,

I dug out a DEVKIT V4, specifically a ESP32-WROOM-32D. If I read the pinout correctly, there's only set of RX and TX. I've also tried connecting the the ESP32-D's RX and TX to the 8 separate sets RX and TX and I'm getting this for each one everytime I press RESET on my ESP32.

1710707355889.png


So I'm getting "Message received", but not "Teensy here".

Side question, is it something to the baud rate? I've set ESP32 to 115200, and I initally had my Teensy to 9600, but I went to the SERIAL version of my COM port and changed it to match my ESP32, so they are both 115200. After I changed it from 9600 to 115200, I went back to my teensy port.

Also my earlier ESP32-E is specifically a DFR Firebeetle 2 ESP32-E. Here is a link to the site.

Here is my current setup, mine a few extra wires, I connected the 3.3V to a photoresistor. While I am a conducting a separate test, I don't think it should interfere with the communication.

1710708105033.png
 
It looks like you have this board. Problem is that the TX & RX signals of the ESP32 chip connect to [1] the external TX & RX board pins and to [2] the onboard "USB-to-UART Bridge".
So you are using the same serial port for Teensy communication and for USB communication - that's not going to work.
If I read the datasheet correctly, GPIO9 and GPIO10 can be used for a second UART:

1710712959514.png


You may want to try to get that second serial port to work and connect to the Teensy at 9600 baud.

Paul
 
It looks like you have this board. Problem is that the TX & RX signals of the ESP32 chip connect to [1] the external TX & RX board pins and to [2] the onboard "USB-to-UART Bridge".
So you are using the same serial port for Teensy communication and for USB communication - that's not going to work.
If I read the datasheet correctly, GPIO9 and GPIO10 can be used for a second UART:

View attachment 33724

You may want to try to get that second serial port to work and connect to the Teensy at 9600 baud.

Paul
Hello Paul,

So I've moved the the TX and RX to 18 and 17, respectively. And their connected to the 0 (RX1) and 1(TX1) of the teensy. Whenever I look at my ESP32 Serial monitor, I'm getting this

View attachment 33726

Here is my current set up

1710715577738.png
 
That's really not a great photo but going by the red wire connected to both pin 18 on the ESP and pin 1 on the Teensy, you've connected Rx to Rx and Tx to Tx again. They have to be connected to their opposites.
 
That's really not a great photo but going by the red wire connected to both pin 18 on the ESP and pin 1 on the Teensy, you've connected Rx to Rx and Tx to Tx again. They have to be connected to their opposites.
I've switched the wires, but I'm still getting

1710739707281.png
 
Pff, too many variants of ESP32 boards around. Also chip pin numbers != board pin numbers != GPIO numbers. Look at the pinout.

Found this in the datasheet of the chip:
1710747160713.png

You would have to use board pin numbers 16 & 17 [GPIO16 & GPIO 17]. This port would be used as Serial2.begin().

To add to the confusion, also found this message. You may want to try that as well.

Google for "ESP32-DevKitC V4 uart #2" and you will see many messages from people that are struggling with the UART pins.

Paul
 
I've switched the wires, but I'm still getting

If you previously had TX - RX and RX - TX connected and swapped the wires so TX - TX and RX - RX connect, you would expect the result to change from "something" to "nothing" if the problem is something like wrong baud rate or poor quality signal.

At this point, I would double check the GND wire. It sure looks correct in your photos. Maybe use an ohm meter to check it really is connected. It's rare but we've definitely seen problems on this forum which turned out to be caused by defective "breadboard wires".

If you're really stuck, investing in a USB-Serial cable with 3.3V TTL-level signals might be worthwhile. I'd highly recommend paying a bit more for one where the signals are labeled, like this:


1710769150151.png


With this sort of cable, you can run a terminal emulator like CoolTerm. Plug a wire into its TXD and RXD and when you type in the terminal you should see the characters received back and shown on your screen. Then connect GND and use the RXD pin to listen to the signals
 
Back
Top