SoftwareSerial gives the output strange and slow

Hi guys I'm trying to get data from software serial and print it into the serial montior
but the out has a lot of strange characters and it's so slow here is my code :

#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;

// Set up a new SoftwareSerial object
SoftwareSerial mySerial (rxPin, txPin);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  mySerial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:
  String a = mySerial.readStringUntil('=');
  Serial.println(a);

}

My primary rx tx port is taken so I cannot use them but when I use my rx tx ports the output will be nice and clean and much faster.
here is the strange output from my softwareserial :slight_smile:

vpp main surfacb@end
----------.]-------------->freq >@626000  pro⸮ram service_id 
 143 
-----.]---------.M-[adec^-[info]: [X]V뫥j⸮⸮⸮⸮j⸮⸮⸮j"⸮⸮⸮⸮⸮5
[adec]-[Z⸮֫⸮⸮Ց⸮⸮u⸮jA⸮j%9&⸮⸮r⸮r⸮⸮⸮r⸮⸮⸮j
-uc0VPU_T⸮U⸮⸮⸮Z⸮+⸮⸮⸮)I⸮‚⸮⸮⸮⸮⸮j
[aout]-Yinfo]: [HDMH : pcm] (INPUT: |pcm|) ,EDIDtBj͙⸮
[PU
vpp main sr⸮face startC⸮C!⸮⸮j⸮⸮⸮⸮⸮⸮ə⸮⸮⸮⸮*⸮⸮5
---.]----------.]-----
---.~freq 
 626000  program service_id >@143-

----.]----------.]----
----?freq 
 626000  program q⸮rvice_id

Please help me with that

You are reading from mySerial whether or not there is any data to read. readStringUntill() has a default timeout of 1 second so most of the time the code is waiting for input that is not there

Check that there are characters available to read before reading them

Software serial has serious baud rate limitations. From what I've seen, I haven't used it myself, you'll have grief using software serial at 115200. Apparently, going much beyond 9600 gets tricky. Do a quick search on this forum for uses of software serial before you go too far.
Good luck.
C

Ummm it is strange the serial device is constantly sending some texts and as you can see
we get strange characters between words! so I think that's not the case it's more like a baud rate issue. by the way, can you give some examples about checking the characters??

I have a serial device and esp8266 wifi and both of them need serial communication
what should I do?? can I use a wifi shield for Arduino???

while (mySerial.available())
{
    //code here to read bytes from mySerial
}

Garbage characters are often a baud rate mismatch. It looks like your mismatch is mild so it might be possible to tweak your rate to get a better match with your hardware. Try adjusting the mySerial.begin(115200); value up and down (no more than 10%) to see if any nearby values get you better results.

I'd start at 1% high (116352) and 1% low (114048). If one of those produces more readable text, try 0.5% on either side of that one.

Ignore the rubbish above and just read reply#3 twice. If you refuse to heed it, you deserve all the grief you get.
You might also consider then advise

  1. why you need 115200 anyway, and
  2. whether whatever ESP8266 is talking to is redundant, which often the case.

In short, what is the real project?

To clarify what I said, and reinforce what Nick said.
Garbage characters can also be created by software serial simply because other processes on the Arduino must be able to interrupt. Therefore, the lower the baud rate, the more immune Software Serial can be to this reality; as you raise the baud rate, a single interrupt event consumes more and more of a bit time, increasing the likelihood of misinterpretation.
To help you, forum members need information about your project, to assess what the real vulnerabilities are. Barring that, this is a pointless exercise.
Ciao
C

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