AT-09 / HM-10 Bluetooth devices AT commands don't work

I have an issue with 3* 4.0 Bluetooth devices. One of these BT AT-09 and 1 of these AT-09 and I already had one that is supposed to be a HM-10 4.0 BLE.

Now all 3 of them connect to my iPhone app successfully and they can receive data from the phone. I'm only sending information from the phone and not reading data from the BT devices.

The issue I have is.... I want to rename the devices to alexbt2. One of them can accept the AT commands from the MacBook and rename the device (AT+NAMEalexbt2) successfully but the other two won't. I have to search the broadcasting BT devices in range and work out which device is the one powered up. When trying the AT command I don't get the OK returned, so the AT+NAMEalexbt2 will not work. I've even added it to the code to rename it on power up.

The way they are wired are as shown in this site:- Wiring diagram. I have even used a voltage divider on both the TX and RX. I've also tried wiring the BT devices directly to the UNO without resistors but the 2 devices still fail to acknowledge the AT commands.

I think that is all you need......so any ideas?

/*
 *  sketch: SerialPassThrough_SoftwareSerial_NL
 *  www.martyncurrey.com
 *   
 *  Use software serial to talk to serial/UART connected device
 *  What ever is entered in the serial monitor is sent to the connected device
 *  Anything received from the connected device is copied to the serial monitor
*  User input is echo'd to the serial monitor
 * 
 *  Pins
 *  BT VCC to Arduino 5V out. 
 *  BT GND to GND
 *  Arduino D2 (Arduino RX) 
 *  Arduino D3 (Arduino TX) 
 * 
 *  Assumes a 5V Arduino is being used
 *  If the connected device is 3.3v add a voltage divider (5v to 3.3v) between Arduino TX and device RX
 *  Arduino RX to device TX does not need a voltage divider. The Arduino will see 3.3v as high
 * 
 */

#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3); // RX, TX
 
char c=' ';
boolean NL = true;
 
void setup() 
{
    Serial.begin(9600);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);

    softSerial.begin(9600);

    sendCommand("AT+NAMEalexbt2"); //Set the name of the Bluetooth device to alexbt2. This name is hard coded into the iPhone App
    
    Serial.println("softSerial started at 9600");

    Serial.println("Set line endings to 'Both NL & CR'");
}
 
void loop()
{
    // Read from the UART module and send to the Serial Monitor
    if (softSerial.available())
    {
        c = softSerial.read();
        Serial.write(c); 
    }
    
    // Read from the Serial Monitor and send to the UART module
    if (Serial.available())
    {
        c = Serial.read();
        
        // do not send line end characters to the HM-10
        if (c!=10 & c!=13 ) {   
          softSerial.write(c); 
        }
        // Echo the user input to the main window. 
        // If there is a new line print the ">" character.
        if (NL) { 
          Serial.print("\r\n");  
          NL = false; 
        }

        Serial.write(c);

        if (c==10) { 
          NL = true; 
        }
    }
    
} // void loop() END

//**** Send commands to BT device
void sendCommand(const char * command) {
  Serial.print("Command send :");
  Serial.println(command);
  softSerial.println(command); //Send command to BT Device
  //wait some time
  delay(100);

  char reply[100];
  int i = 0;
  while (softSerial.available()) {
    reply[i] = softSerial.read();
    i += 1;
  }
  //end the string
  reply[i] = '\0';
  Serial.print(reply); //Print reply to Sketch Serial Monitor
  Serial.println("Reply end");
  delay(50);
}

I have just found something out. I have the peripheral information listed in the Debug Area of Xcode when running the app. When it picks up a device that is broadcasting, it lists all the information about the devices, including the device name. If I change the required name of the device in Xcode and rerun the app, the bluetooth device connects successfully.

While connected, if I rerun the Sketch the device name is successfully changed. All I need to do then is rename the device in Xcode and all is good. i.e.

My bluetooth device which should have been named 'alexbt2' is actually called TT:-

Periperal: <CBPeripheral: 0x283a29d40, identifier = C4EBD445-BF6A-4333-A4D4-7AFE23C050D5, name = TT, mtu = 0, state = disconnected>

When I change the name of the device in Xcode to TT then the BT device pairs successfully. I then run the Arduino Sketch again, while paired, and then refresh the connection to my phone and the pairing fails, which is good because I now know the renaming of the device was successful.

Periperal: <CBPeripheral: 0x283a29d40, identifier = C4EBD445-BF6A-4333-A4D4-7AFE23C050D5, name = alexbt2, mtu = 0, state = disconnected>

As you can see the bluetooth device has been successfully changed.

Why can I only change the name of the two failing BT devices when it is actually paired with my phone?

When the device is not paired the renaming is unsuccessful when the Sketch is run.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.