I'm getting some garbage with the SerialPassthrough sketch on an esp32

I have a ublox gps connected to an esp32 and I'm trying to get the serial passthrough working so I can configure it. I'm using the following sketch to do it:

void setup() {
  Serial1.begin(115200, SERIAL_8N1, 25, 27);

void loop() {
  if (Serial.available()) {      // If anything comes in Serial (USB),
    Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 0 & 1)

  if (Serial1.available()) {     // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());   // read it and send it out Serial (USB)

The problem I'm having is that I'm getting some garbage output from the serial number so when I try to configure it, it bugs out pretty badly.

Is there anything I can do to get it working properly?

Try reducing the baud rate to start with to say 9600
and check out my tutorial on Arduino Serial I/O for the Real World
Which covers reading entire line at a time and then outputting it.

Are you using the software serial, if so it is not full duplex. Showing the declarations helps a lot.

Are your wires to the GPS module too long? Is there any other things near these wires? The shorter the wires and far from other signal or power wires, the better. The UART on ESP32 is 3.3V, unlike UNO with 5V, which is better against noise.

I'll try that for testing but the GPS is running at 10hz so I need a fast baud rate.

Nope just plain hardware serial. Also that's the entirety of the code.

They're less than 4in so length isn't a problem and there's good separation between power and data but I'll keep the voltage part in mind.

I also tried this with the bluetooth serial example included with the esp32 board files and I'm still getting a really similar output so I'm thinking it might be something hardware related. I have a HC-05 on the way so I honestly probably won't look into this that much.

A char takes about 1mS at 9600 so you should still be able to get 10HZ x 80 char lines at that baud rate.
You could try connecting Serial1 TX to RX (loopback) and check that what you type in Serial comes back out.

Using a lower baud rate would give you an idea whether your issue is caused by high baud rate. I also recommend you to try different pins for Serial1. Remove other hardware and only keep the GPS.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.