1

I have an HM-11 BT module that I am configuring as a Master/Central and attempting to connecting to a SH-M08 BT slave module.

I can connect to the slave successfully but I cant send data.

I found this code on line. After configuring the HM-11, scanning and printing the found BT modules to serial, it reads commands from the serial port.

From the serial monitor I can send AT+CON[ADDR] and get back OK+CONNA and OK+CONN which indicates that connection was successful.

When I attempt to send anything via the serial connection it does not get received by the slave BT. I am able to used an app on my phone to send data to the slave BT.

This is the code.

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

#define baud 9600

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(baud);
  BTserial.begin(baud);
  
  at("AT"); // check if working, always returns OK
  at("AT+RENEW"); // select master = central  
  at("AT+ROLE1"); // select master = centra
  at("AT+RESET"); // actually more a restart than a reset .. needed after ROLE
  at("AT+SHOW1"); // include Bluetooth name in response
  at("AT+SCAN5"); // set discobery time to 5 seconds
  at("AT+IMME1"); // "work immediately", not sure what this does
  //at("AT+FILT0"); // show all BLE devices, not only HM ones
  delay(1000); // wait a bit, NECESSARY!!
  BTserial.print("AT+DISC?"); // here comes the magic
 while(!BTserial.find("OK+DISCS")) Serial.print("."); 
   Serial.println("OK+DISCS");
}

void at(char* cmd) {
  BTserial.write(cmd);
  Serial.print(cmd);
  while(!BTserial.find("OK")) Serial.print(".");
  while (BTserial.available()) Serial.write(BTserial.read());
  Serial.println(" .. OK");
}


void loop() // run over and over
{
  if (BTserial.available())
    Serial.write(BTserial.read());
  if (Serial.available())
    BTserial.write(Serial.read());   
}
0

0

Your Answer

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

Browse other questions tagged or ask your own question.