TWO HM-10 ble module sending and receiving data

Hi All,

I am trying to connect 2 HM-10 ble module to send and receive the data. Although, they both are connect,however, there is an issue with sending and receiving the data to display at the console. I have attached the code chunk as information.

======
Master

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(18, 19); // RX, TX

void setup()
{
   // Open serial communications and wait for port to open:
   Serial.begin(9600);
   Serial.println("I am Master!");

   // set the data rate for the SoftwareSerial port
   bluetooth.begin(9600);
   delay(5000);
   // set master 
   bluetooth.write("AT+NAMEHUB");delay(5000);
   bluetooth.write("AT+ROLE1");delay(5000);
   bluetooth.write("AT+IMME0");delay(5000);
   bluetooth.write("AT+RESET"); delay(5000);// need to restart after chaning the role
 
   bluetooth.write("AT+NOTI1");delay(5000);
   bluetooth.write("AT+CON12344567890123"); delay(5000);
   Serial.println(Serial.read());
   Serial.println("\r\nConnecting to Slave");
   delay(1000);


}
void loop() // run over and over
{
   
   

     Serial.println("\r\nSending to slave");
     bluetooth.println("ABC");
     Serial.println("ABC");
     delay(800);
}

======
Slave

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(1, 0);

void setup()
{
   Serial.begin(9600);
   Serial.println("\r\nI am a slave");

   // set the data rate for the SoftwareSerial port
   bluetooth.begin(9600);
   delay(5000);
 
   //set slave
   bluetooth.write("AT+ROLE0");delay(5000);
   bluetooth.write("AT+IMME0");delay(5000);
   bluetooth.write("AT+RESET");delay(5000);
   bluetooth.print("AT+NOTI1");delay(5000);
   
 
}
void loop() // run over and over
{
    
    while(bluetooth.available()==0)
     {
            Serial.println("No Data");
     }
     
     while(bluetooth.available()>0)
     {
       Serial.println("Data is = ");
       Serial.println( bluetooth.read());
       
     }
}

I am only getting No Data on my console. That means, no data is received from master. I have double checked all the wiring and all good.

Really appreciate if anyone could shield any light on it. Thanks in adv.

Assuming they are wired and powered correctly, and you start them in the right order so that the pairing works (I did not verify your AT commands - some HM-10 would not take AT+CON12344567890123 but AT+CONN[color=red]x[/color] where x is the index of the slave you want to connect to when you list visible devices for pairing (note the 2 N))

Try doing bluetooth.println instead of bluetooth.write
Yout AT command interpreter might need the "\r\n" to get the command

I had written a small intro to pairing two fake HM-10 in French, may be with google translate that can help you out

Thanks for your time & reply. Yes, you are correct, I already ruled out the wiring and power issues.

I have browse thro' all the related topics regarding this matter. I have tested those commands sequence with FTDI direct cabling and it is working. I got "OK+CONN" at the console. ( Screenshot -

println and "\r\n" do not really change the values of the commands, thus I need to use "write" and removed "\r\n" instead due to some known issue.

However, at the Slave console, I am only getting number 53 which means space according to ASCII table.

This means, pairing and connection is working but there are some challenges with sending and receiving data. Any further suggestion and advise would be really appreciated. Thanks a lot !

I have browse thro' all the related topics regarding this matter. I have tested those commands sequence with FTDI direct cabling and it is working. I got "OK+CONN" at the console. ( Screenshot -

were you sending "\r\n" with FTDI at the console? I find it very surprising you don't need it

Yes, that is true. It is working without "\r\n" with both FTDI and as well as from program. By the way, I have tested another possibility in changing of bluetooth serial rate to 38400 for both master and slave. At the slave program, I used "Serial.println(bluetooth.readString());" And i am getting

"x⸮x⸮⸮xx⸮x⸮x⸮x⸮⸮x⸮x⸮x⸮⸮x⸮x⸮⸮⸮x⸮x⸮x⸮" at both master and slave instead of sending the correct data which is "ABC". it is happening really strange. Any further idea?

Don't use the wrong baud rate nor the String class ...

Can you connect to a FTDI and open a terminal at 9600 bauds and issue AT+HELP
What do you get? (Ensuring your terminal does not send \r\n just to be sure)

Please fix your first post and use code tags around your code

Thanks for your help and reminder. I have fixed with the code tags at my first post.

When I connect a master module to a FTDI, i got the "OK+LOSTOK+CONN" at the console. I believe it is due to the previous command "CONxxxxxxx" to slave. It keep getting that message and during that time I am not able to type any AT command until I power reset the module.

However, at the slave module, I restored back to default baud rate 9600. Nonetheless, when I type "AT+HELP?" I get responses with "www.jnhuamao.cn".

I double checked the module and confirm that it is not fake module. I attached the hardware image for your further information ( Image Link: http://imgur.com/a/yrBCY)