0

I have a JDY-30 bluetooth module and have it wired like this (except using an Arduino Uno): enter image description here

It is working, but I need to use it with a 115200 baud rate instead of the default one of 9600. I also got that working. Here is the code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3); // RX, TX

// state | RXD | TXD | GND | VCC | EN

void setup () {
  mySerial.begin(115200);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
}

void loop() {

  while (mySerial.available()) {
    delay(10);
    Serial.write(mySerial.read());
    delay(10);
  }

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

}

But when I type things I often get badly formatted characters.

Some examples:

16:32:33.212 -> +VERSION=Firmware V3.0.6,Bluetooth V4.0 L⸮

16:32:38.990 -> +VERSION=Firmware V3.0.6,Bluetooth V4.0 LE

more:

16:33:27.144 -> +NAME=CC61-A

16:33:30.054 -> +NAME=CC41-A

If I also use 115200 baud rate for the Arduino, then it gets really worse.

Is there a solution for this?

See more about the JDY-30 here: http://myosuploads3.banggood.com/products/20181203/20181203214419JDY-30-SPP-Bluetooth-Module.pdf

  • 1
    It is impossible to reliably receive using SoftwareSerial at 115200 baud. The UNO is just too slow for that. – Majenko Jan 21 at 15:44
  • 1
    Also the 3.3V logic of the bluetooth unit is right on the HIGH threshold of the 5V logic of the Arduino. There is little margin for error, which makes it very prone to noise. – Majenko Jan 21 at 15:45
  • @Majenko what about writing, is that reliable? I don't care so much for the reading. – clankill3r Jan 21 at 15:46
  • Writing is fine, yes. The Arduino is in control of the flow in that situation, so speed is less critical. – Majenko Jan 21 at 15:47
0

As @Majenko pointed out:

It is impossible to reliably receive using SoftwareSerial at 115200 baud. The UNO is just too slow for that.

I got results that where a lot better by first making a string when reading and then once we have a string send that. Instead of sending what we read all the time. For example, when I tried AT+VERSION now it took me 16 attempts to get a wrong one, and only one character out of 42 was wrong that time.

#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3); // RX, TX

// state | RXD | TXD | GND | VCC | EN

void setup () {
  mySerial.begin(115200);
  Serial.begin(115200);
  Serial.println("Enter AT commands:");
}

void loop() {

  String input_string = "";

  while (mySerial.available()) {
    input_string += (char)mySerial.read();
  }

  if (input_string != "") {
    Serial.write(input_string.c_str());
  }

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

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.