SoftwareSerial + Bluetooth communication too slow

Hallo everyone :slight_smile:

For Bluetooth communication, I set up a SoftwareSerial port at 38400 Baud. With help of micros(), I measure about 30ms for only 1 byte, which I find extremly slow.

I don't see anything in my code, which could slow it down...

Client:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(13, 10); // RX, TX

long sendtime = 0;
long receivetime = 0;

void setup() {
  Serial.begin(38400);
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
  mySerial.begin(38400);
}

void loop() {
  sendtime = micros();
  mySerial.print("A");
  while ((char)mySerial.read() != 'A') {}
  receivetime = micros();
  Serial.println(String((receivetime - sendtime) / 1000.0) + "ms");
  delay(500);
}

Server:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(A5, A4);//rx tx
void setup() {
  mySerial.begin(38400);
}

void loop() {

  while ((char)mySerial.read() != 'A') {}
  mySerial.print("A1E");

}

Serial monitor:

...
32.60ms
29.80ms
31.15ms
30.98ms
32.61ms
28.70ms
31.01ms
31.22ms
32.59ms
29.93ms
34.96ms
28.54ms
28.84ms
34.96ms
29.77ms
31.18ms
28.84ms
28.52ms
...

lg, couka

Baud rate is bits per second.

SoftwareSerial does not work well at higher baud rates. Start with 9600 baud and if that works properly then you can try higher rates step by step.

If you need higher performance you will need to use an Arduino with more than one HardwareSerial port.

...R

Oh, it works properly. Everything is sent and received just fine, no losses, no scrambled data.
My only problem is, that it takes so long and I don't understand why.
A bluetooth connection with these HC-05 and HC-06 modules should be completely transparent, just as if you used wire.
But serial communication over wire does not take 30ms :smiley:

lg, couka

couka:
A bluetooth connection with these HC-05 and HC-06 modules should be completely transparent, just as if you used wire.
But serial communication over wire does not take 30ms :smiley:

I think this is nonsense. Software serial is not the same as hardware serial. You are specifically complaining about bluetooth connection with software serial and implying the bleeding obvious - that communication over wire with hardware serial is fine. This seems to be an apples and oranges situation. Have you actually tested the wire connection with software serial?

couka:
Oh, it works properly. Everything is sent and received just fine, no losses, no scrambled data.
My only problem is, that it takes so long and I don't understand why.

I find it hard to reconcile the phrases I have highlighted.

...R

Robin2:
I find it hard to reconcile the phrases I have highlighted.

Maybe I should not say "properly" but "reliably".

Reliability: Great.
Latency: Bad.

lg, couka

couka:
Reliability: Great.
Latency: Bad.

Have you tried using 9600 baud to see if it gives the expected latency - even if the overall throughput is not what you require?

It is easier to debug something with settings that are known to work.

...R