Links with the AT commands.
http://eclipse.clinertech.com/arduino/bluetooth/Bluetooth_AT_Commands.txt
Two key pieces of information I wish I knew when I started.
- AT commands DO NOT work when the device is paired.
- SoftwareSerial doesn't work past 9600 BAUD.
WARNING: Setting the BAUD Rate too high will essentially lock you out of the chip if you don't have hardware that can send/recieve at that baud rate...
This code above worked for me very well >.> until I changed the BAUD rate using AT+BAUD8
Now it's stopped responding to AT commands. ( I did recompile my sketch to use the new baud rate 115200)
There is a "STATE" Pin that I found on Krill Labs - Using the BT Board v1.02 JY-MCU
that says that will toggle it between AT command mode and regular work but I think maybe a 10k resistor is too much since I'm only running on 5V
I've also discovered that delay rates of tx/rx stuff changes pending on baud rate so maybe I'm failing there somehow. I was reading the SofwareSerial.cpp file and some other sources said timing is pretty important for this but unsure exactly how to calc it.
At one point I did have my snes controller -> Arduino Mega -> BlueTooth module -> custom compiled SNES9x >.> but I wanted faster response times.
Things would lock up alot and I got a reset procedure down.
Remove the pairing (ubuntu 12.04 LTS)
Reboot box
hcitool scan
rfcomm bind 0 00:12:02:28:71:34 1
screen /dev/rfcomm0 9600 #This will prompt you for the pairing password and I also noticed the LED went solid rather than blinky.
screen /dev/rfcomm0 9600
rfcomm release 00:12:02:28:71:34
UPDATE:
Got it working again, I switched to hardware tx3/rx3 then I cycled through every baud rate until I saw the right output, aparently I set it to 57600
run the following just once after boot, and note AT commands cannot be run after this is paired
hcitool scan
rfcomm bind 0 00:12:02:28:71:34 1
#Upload this test code
void setup() {
Serial3.begin(57600);
}
void loop() {
Serial3.write("test\r\n");
delay(1000);
}
command line test
screen /dev/rfcomm0 57600 #cycle through all baud rates until you see the plain text "test" string
I re uploaded the sketch every time but when I hit 57600 I just decided to re run screen without the upload and it worked >.> so maybe it doesn't matter or maybe that fixed it.
Once I saw the plain text I CTRL-A-k out of screen
rfcomm release 00:12:02:28:71:34 #If you don't release the pairing AT commands don't work!
Then upload the following code
String command = "";
void setup() {
Serial.begin(115200);
Serial3.begin(57600);
Serial.println("Type AT commands!");
}
void loop(){
if (Serial3.available()) {
while(Serial3.available()) { command += (char)Serial3.read();delay(10); }
Serial.println(command);
command = ""; // No repeats
}
if (Serial.available()){ delay(20); Serial3.write(Serial.read()); }
}
screen /dev/ttyACM0 115200 #Begin typing AT commands.