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);
}