1

I have an Arduino Mega 2560 and a HM10 Bluetooth module (this one)

I have connected the Bluetooth according to the manufacturer's specifications: VCC -> 5v GND -> GND

TXD and RXD of the Bluetooth, I have tried to put them in pins of Arduino, in Serial1, in Serial2, in Serial3, with the same result.

The code I use for my tests is this:

#define BTserial Serial1

int LED_BOARD = 13;
int LED_RED = 2;
int LED_GREEN = 3;

void setup() {
    BTserial.begin(9600);
    Serial.begin(9600);
  
    pinMode(LED_BOARD,OUTPUT);
    pinMode(LED_RED,OUTPUT);
    pinMode(LED_GREEN,OUTPUT);
}

void loop() {
    if (Serial1.available()) {
        dato = Serial1.readStringUntil('\n');

        Serial.println("DATA RECEIVED: [" + String(dato) + "]");

        if (dato.equals("1")) {
            digitalWrite(LED_BOARD, HIGH);
        }
        if (dato.equals("0")) {
            digitalWrite(LED_BOARD, LOW);
        }
        
        if (dato.equals("RED_ON")) {
            digitalWrite(LED_RED, HIGH);
        }
        if (dato.equals("RED_OFF")) {
            digitalWrite(LED_RED, LOW);
        }

        if (dato.equals("GREEN_ON")) {
            digitalWrite(LED_GREEN, HIGH);
        }
        if (dato.equals("GREEN_OFF")) {
            digitalWrite(LED_GREEN, LOW);
        }
    }
}

I have an Android phone, and I use the Arduino Bluetooth Controller (HM-10 Module) app.

  • I send the text 1, and the led of the Arduino board (pin 13) turns on.
  • I send the text 0, and the led of the Arduino board (pin 13) turns off.
  • I send RED_ON, and the led of my breadboard, connected to pin 2, turns on
  • I send RED_OFF, and the led of my breadboard, connected to pin 2, turns off
  • I send GREEN_ON, and the led of my breadboard, connected to pin 3, turns on
  • I send GREEN_OFF, and the led of my breadboard, connected to pin 3, turns off

So the Bluetooth works.

My problem is trying to see the list of Bluetooth commands (AT+HELP command).

I have a method that is responsible for sending AT+HELP to bluetooth, but I have no response.

This is the method, which I run in the main:

String str_ii = "";
int ii_0 = 0;
void ble_help(){
    Serial.println("ble_help");

    BTserial.println("AT+HELP"); // list all AT+ commands
    while (true){ // loop to print all AT+ commands
        char in_char = BTserial.read();
        if (int(in_char)==-1 or int(in_char)==42){
            continue;
        }
        str_ii+=in_char;
        if (in_char=='\n'){
            if (str_ii==String('\r')+String('\n')){
                if (ii_0 == 0){
                    ii_0 = 1;
                    continue;
                }
                break; // break after more than 1 empty carriage return and newline
            }
            Serial.print(str_ii);
            str_ii = "";
        }
    }
}

When executing this method, in application Arduino Bluetooth Controller (HM-10 Module) app i see the text AT+HELP, but there is no reaction / response from the bluetooh. Neither in the Arduino Bluetooth Controller (HM-10 Module) application nor in the Arduino serial monitor

What am I doing wrong?

Thank you.

1 Answer 1

1

First thing first you can see all AT commands available from the data sheet available from datasheet

Second to get strings from Serial to BTserial you can just use c = Serial.readStringUntil('\n'); like here

#define BT_RX           0
#define BT_TX           1
#define BT_Serial       Serial1
#define BT_Timeout      100

String c, c2;

void setup() {
  BT_Serial.setTX(BT_TX);
  BT_Serial.setRX(BT_RX);
  BT_Serial.begin(9600);//baudrate
  BT_Serial.setTimeout(BT_Timeout); //set bluetooth read/write timeout

  Serial.begin(9600);
  Serial.setTimeout(100);
  delay(100);
}

void loop()                     
{
  if (Serial.available()) {
    c = Serial.readStringUntil('\n');
    Serial.println(c);
    BT_Transmit_AT(c);
  }
  if (BT_Serial.available()) {
    c2 = BT_Serial.readStringUntil('\n');
    Serial.println(c2);  
  }
  delay(20);
}

void BT_Transmit_AT(String data) { //send AT commands
  unsigned long current_time = millis();
  while (BT_Serial.available() > 0) {
    if (millis() - current_time > 100){ //timer to get out incase not receiving anything
      Serial.println("Timeout");
      break;
    }
  }
  BT_Serial.print(data);
}

And lastly you need to make sure your HM-10 is genuine/has genuine firmware installed or it's a clone. Check if it respond to "AT" with "OK" at all. If it does then it's genuine and you can continue. If it doesn't then you need to flash genuine firmware onto it, then upgrade from there if you. Here is a good tutorial on flashing the genuine firmware onto the module.

After that you can follow a tutorial here on upgrading the firmware from an older genuine firmware. You can get the latest genuine firmware from the Manufacture's website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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