1

i bought the HM 10 Bluetooth controller (CC2541), i got connect on this device through Serial Bluetooth Terminal (Android App) with Serial BLE menu this method not requires any pass and "Connected" state is showed and the led on CC2541 is always HIGH now, but... any command sended from terminal or sended from serial arduino is not show and "AT+NAME" or "AT+NAME?" returns null everytimes, this is my code to run Bluetooth on Arduino Mega2560:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(26, 27); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Goodnight moon!");

  delay(500);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.print("Wake up wake up wake up wake up wake up! Wake up wake up wake up wake up wake up!");
}

void loop() // run over and over
{
  if (mySerial.available()) {
    String s = "";
    char c;
    while((c = mySerial.read()) != -1) {
      s += c;
      delay(10);
    }

    Serial.println("Received: " + s);
  }

  if (Serial.available()) {
    String s = "";
    char c;
    while((c = Serial.read()) != -1) {
      s += c;
      delay(10);
    }

    delay(10);

    Serial.println("Sent: " + s);

    mySerial.print(s);
  }
}

Example of output serial monitor:

Sent: AT+DEFAULT

Sent: AT+BAUD9600

Sent: AT+HELP

I never receive "Received" status...

5
  • Your serial code is really weird. Maybe you should instead directly use the typical Serial Passthrough Sketch, just with mySerial instead of Serial1 (and of course the initialization stuff of SoftwareSerial). Also: Are you sure, that the HM-10 module listens for AT commands at 9600 baud? Have you tried other baudrates? – chrisl Sep 10 '20 at 19:30
  • I'm not sure about my CC2541's BAUD rate, why doesn't it accept AT + BAUD? So I can't know what your BAUD RATE would be – luke cross Sep 10 '20 at 19:31
  • For just accepting that command every time, it would have to read at every baudrate simultaneously. That's a bit too much to ask. The seller, where you have bought the module, should know the baudrate, that it is configured to. Look at the documentation of it. Or (in the case, that there is no documentation) you can test yourself and go through the list of common baudrates (the ones listed in the Serial Monitor). Though I think you could start above 9600 and go up, before trying others. Also SoftwareSerial has problems with the high baudrates (for example 115200), so you can stop there – chrisl Sep 10 '20 at 19:35
  • I tried all BaudRates (But Serial Arduino is always 9600) and the response is equal... null – luke cross Sep 10 '20 at 19:38
  • I tried change mySerial.begin to 9600 19200 38400 57600 115200 4800 2400 1200 230400 – luke cross Sep 10 '20 at 19:39

Your Answer

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

Browse other questions tagged or ask your own question.