How do I fix HM-10 BLE module from returning odd characters?

1k views Asked by At

I am trying to send data to an Arduino via a HM-10 module(BLE) from a MacOS device and am following this guide. For my wiring, I have done the following: I have the RX pin on the HM-10 hooked to the TX on the Arduino; the TX pin on the HM-10 to the RX on the Arduino; the VCC on the HM-10 to the 3.3V on the Arduino; the GND on the HM-10 to the GND on the Arduino.

I am using the following code:

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(0, 1); //RX|TX

void setup(){
  Serial.begin(9600);
  BTSerial.begin(9600); // default baud rate
  Serial.println("AT commands: ");
}

void loop(){
  //Read from the HM-10 and print in Serial Moniter
  if(BTSerial.available()) {
      Serial.write(BTSerial.read());
  }

  //Read from the Serial Moniter and print to the HM-10
  if(Serial.available()) {
      BTSerial.write(Serial.read());
  }
}

When I send AT+NAME?, I should be receiving OK+NAME:HMSoft, but I keep on getting a string of odd characters: AV⸮5⸮. In addition, none of the commands seem to have any effect.

What am I doing wrong that I am unable to interact with the HM-10 from my computer?

2

There are 2 answers

1
gre_gor On
SoftwareSerial BTSerial(0, 1); //RX|TX

You are using hardware serial pins for software serial. And you are then using both, which corrupts the data.

Move the software serial pins to different ones, like 2 and 3.

0
vojda On

After changing the pins to 2 and 3, choose Both NL&CR option to send commands to Arduino through the IDE. Otherwise it's not going to work.