Notifications
Clear all

SoftwareSerial issue

6 Posts
2 Users
1 Likes
1,120 Views
(@jeffreyjene)
Member
Joined: 4 years ago
Posts: 56
Topic starter  

Hello,

I'm looking for some help with SoftwareSerial. I have an ESP32s hooked up to an Arduino Mega (TX-RX and RX-TX) with SoftwareSerial RX on Arduino pin 10 and TX on pin 11. I'm trying to send a simple string from the ESP to the Arduino. Here's the code for the ESP32s:

void setup()
{
  Serial.begin(115200);
  while (!Serial) {
  }

}
 
void loop(){
  Serial.println("Hello, world?");
  delay(500);
}

And here is the code for the Arduino Mega:

/*
RX is digital pin 10 (connect to TX of other device)
TX is digital pin 11 (connect to RX of other device)
*/
 
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
 
void setup()
{
  Serial.begin(9600);
  while (!Serial) {
  }
 
  mySerial.begin(115200);
}
 
void loop()
{
  if (mySerial.available())
    Serial.write(mySerial.read());
    delay(100);
}

It works in sending the data. However, some of the data is garbled, and after a while it just starts printing a long string of nonsense:

Hello, wornd?
Hello, wornd?
Hello, worlb?
Hello, worlf?
Hello, worlb?
Hello, worlf?HelloHelloHY⸮⸮Hf⸮loHf⸮loHY⸮⸮HenloH

I think that the problem has to do with the timing somehow; I've tried messing with the delay() function, making them the same for both or simply omitting it (not good) but it is a consistent issue. I'm using this to send a timestamp from the web to the Arduino each second so it has to be on the money. I have no idea what the garbage characters are about. Anyone have a solution for this?

 

 


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2528
 

@jeffreyjene

What happens if you completely remove the delay(100) in loop() ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@jeffreyjene)
Member
Joined: 4 years ago
Posts: 56
Topic starter  

@will A similar output, with weirder characters:

Hello, wornd?
Hello, worlf?
Hello, worlf?
Hello, worlf?
Hello, worlf?
Hello, worlf?
Hello, world?
Hello, worldj
Hello, world?
Hello, worldj
HY⸮⸮	⸮⸮ɱ⸮⸮j
Hf⸮lo, world?C⸮Hf⸮lo, world?Hf⸮lo,

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2528
 

@jeffreyjene 

Interesting, how about:

 

void loop() {
{
  while (mySerial.available())
    Serial.write(mySerial.read());
}

And then try with both at the same baud rate. 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@jeffreyjene)
Member
Joined: 4 years ago
Posts: 56
Topic starter  

@will I figured it out. Apparently SoftwareSerial doesn't play nice with 115200 baud setting. I changed it to 57600:

Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?
Hello, world?

   
YurkshireLad reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2528
 

@jeffreyjene 

Good, I'm glad it's resolved now.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote