Hi everyone.I was frustrated because of seedstudio BT is not connecting to my android Phone(samsung vibrant running ICS 4.0.4).after doing lot of change in code i had finaly made a simple code to work with seedstudio BT also u can connect your android phone and send commands to arduino board.
make sure that your jumper connection is as shown in picture it is default arduino serial com port.
Tx of sheild is connected to RX of arduino(Pin 0)
Rx of sheild is connected to TX of arduino(Pin 1)
Baudrate is 38400bps so no need to change baudrate of sheild its default baudrate of sheild.
char val; // variable to receive data from the serial port
int ledpin = 8; // LED connected to pin 48 (on-board LED)
#include <NewSoftSerial.h> //Software Serial Port
#define DEBUG_ENABLED 1
void setup() {
pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT
Serial.begin(38400); // start serial communication at 9600bps
setupBlueToothConnection();
}
void loop() {
if( Serial.available() ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
}
if( val == 'H' ) // if 'H' was received
{
digitalWrite(ledpin, HIGH); // turn ON the LED
} else {
digitalWrite(ledpin, LOW); // otherwise turn it OFF
}
delay(100); // wait 100ms for next reading
}
void setupBlueToothConnection()
{
Serial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
Serial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
Serial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
Serial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Serial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Serial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
Serial.flush();
}
This is a simple led toggle program make sure that to upload this program to your arduino board you need a older version of arduino softwae 0022 .you can write any other program like to control servo here we can write PWM Generation program in this sketch.you can send commands from mobile using Bluetooth SPP software.
I had found that seedstudio BT is not going to inquiry mode automatically that means every time it restart MCU need to send the commands to set it to inquirable mode and also set to slave mode.To work with BT sheild need to write this lines in to code
{
Serial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
Serial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
Serial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
Serial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Serial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Serial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
Serial.flush();
}
.