Hi, I'm trying to write a sketch in order to estabilish a bluetooth connection between Arduino and Android.
I have an Arduino Uno R3 + Libelium Xbee Shield + BluetoothBee V2.
In AT mode, I can smoothly do it with the following commands:
AT+INIT
AT+IAC=9E8B33
AT+CLASS=0
AT+INQM=1,9,48
AT+INQ
AT+PAIR=MAC_ADDRESS,20
AT+LINK=MAC_ADDRESS
So what I want is to make it a sketch.
Searching on the forum and reading various tutorials (written for different boards and bluetooth bee versions), I came up with this:
#include <SoftwareSerial.h>
const int bluetoothTx = 2;
const int bluetoothRx = 3;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(bluetoothTx, OUTPUT);
pinMode(bluetoothRx, INPUT);
Serial.begin(38400);
bluetooth.begin(9600);
delay(1000);
bluetooth.print("\r\nAT+INIT\r\n"); // inizializzazione SPP
bluetooth.print("\r\nAT+ROLE=0\r\n"); // imposta come slave
bluetooth.print("\r\nAT+IAC=9E8B33\r\n"); // impostazione Inquire Access Code di default
bluetooth.print("\r\nAT+CLASS=0\r\n"); // accetta in connessione tutte le tipologie di dispositivo
bluetooth.print("\r\nAT+INQM=1,9,48\r\n"); // inquire mode: RSSI, max 9, timeout 48
bluetooth.print("\r\nAT+INQ\r\n"); // avvio
delay(1000);
Serial.print("Bluetooth should be initialized now");
}
void loop()
{
if( bluetooth.available() )
Serial.print(bluetooth.read());
if( Serial.available() )
bluetooth.write(Serial.read());
}
But the module is not initialized and I can't proceed further.
Note that AT commands in Serial.print() are not the same set I use for AT mode: I added AT+ROLE=0 to set the module as Slave, and removed AT+PAIR and AT+LINK because after doing AT+INQ my phone is able to pair and connect to bluetooth module.
What am I doing wrong?
TIA