Hardware Serial ESP32 arduino

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Cubyte
 
Posts: 1
Joined: Wed Jan 18, 2017 10:35 am

Hardware Serial ESP32 arduino

Post by Cubyte »

I been trying without much success to get another serial port working on the esp32. My idea is to get the hardwareSerial(1) to run dmx and use the wifi for setup etc but i camn't seem to get the extra serial port working at all.
I've included my serial to serial test sketch but the esp32 just stops working straight away



Backtrace: 0x40080a84:0x3ffc7210 0x400d05a7:0x3ffc7230 0x400d66f2:0x3ffc7270

CPU halted.


code:

Code: Select all




void setup() {
  pinMode (9, FUNCTION_4); // U1RXD 
  pinMode (10, FUNCTION_4); // U1TXD
  HardwareSerial Serial1(1);
  Serial1.begin(9600,SERIAL_8N1,10,9);
  Serial.begin(9600);
}

void loop() {
Serial.println("coms test");


if (HardwareSerial(1).available()) {
    int inByte = HardwareSerial(1).read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    HardwareSerial(1).write(inByte);
  }
}

what am i doing wrong
Last edited by Franklin97355 on Sun May 21, 2017 4:15 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the </> button above the reply box and past your code between the [code] [/code] tags created.

User avatar
willko1107
 
Posts: 1
Joined: Tue May 16, 2017 10:28 pm

Re: Hardware Serial ESP32 arduino

Post by willko1107 »

Code: Select all

void setup() {
pinMode (9, FUNCTION_4); // U1RXD 
pinMode (10, FUNCTION_4); // U1TXD
HardwareSerial Serial1(1);
Serial1.begin(9600,SERIAL_8N1,10,9);
Serial.begin(9600);
};
Pins 9 & 10 are used by ESP32's flash, so you'll need to pick other pins. Also, DMX baud rate is 250000, 8N2 while sending the data, 88000 bps/8E1 during break. Post the rest of your code if you can.

Good luck,
WK.

User avatar
bbx10node
 
Posts: 147
Joined: Sun Feb 22, 2015 4:14 pm

Re: Hardware Serial ESP32 arduino

Post by bbx10node »

The GPS FeatherWing works on the ESP32 Feather like this.

EDIT: Add working passthru pogram.

Code: Select all

// test a passthru between USB and hardware serial

#if defined(ESP32)
HardwareSerial Serial1(2);
#endif

void setup() {
  Serial.begin(9600);
  Serial.println("GPS echo test");
  Serial1.begin(9600);      // default NMEA GPS baud
}

     
void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    Serial1.write(c);
  }
  if (Serial1.available()) {
    char c = Serial1.read();
    Serial.write(c);
  }
}

User avatar
uvaccus
 
Posts: 2
Joined: Wed Jun 13, 2018 3:22 pm

Re: Hardware Serial ESP32 arduino

Post by uvaccus »

This does not work every time and really unstable for me. Most of the times, It looks like the program just stuck at some point. I had to keep hitting the reset button, and sometimes I can get it to read things from GPS. Any idea about what is going on?
bbx10node wrote:The GPS FeatherWing works on the ESP32 Feather like this.

EDIT: Add working passthru pogram.

Code: Select all

// test a passthru between USB and hardware serial

#if defined(ESP32)
HardwareSerial Serial1(2);
#endif

void setup() {
  Serial.begin(9600);
  Serial.println("GPS echo test");
  Serial1.begin(9600);      // default NMEA GPS baud
}

     
void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    Serial1.write(c);
  }
  if (Serial1.available()) {
    char c = Serial1.read();
    Serial.write(c);
  }
}

User avatar
jlboygenius
 
Posts: 2
Joined: Wed Mar 06, 2019 7:45 pm

Re: Hardware Serial ESP32 arduino

Post by jlboygenius »

were you able to get this to work?

I've gone round and round on this same problem. I haven't had any luck with Hardware serial on an esp32 feather, or a arduino Uno. The uno works with software serial.
Using arduino IDE and platformIO w/VSCode.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Hardware Serial ESP32 arduino

Post by adafruit_support_mike »

This code has worked in the past:

Code: Select all

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

#define SERIAL2_RX 13
#define SERIAL2_TX 12

void setup() {
    Serial2.begin(9600,SERIAL_8N1,SERIAL2_RX,SERIAL2_TX);
    Serial1.begin(9600);
    Serial.begin(9600);
}

void loop() {
    Serial2.println("testXbee");
    Serial1.println("testFTDI");
    Serial.println("testusb");
  
  delay(500);
}

User avatar
jlboygenius
 
Posts: 2
Joined: Wed Mar 06, 2019 7:45 pm

Re: Hardware Serial ESP32 arduino

Post by jlboygenius »

I figured it out, my wiring was bad, and I had to use Serial2.

Thanks!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Hardware Serial ESP32 arduino

Post by adafruit_support_mike »

Glad to hear you got it working. Happy hacking!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”