Hi,
We are a group of 3 students. This year, our project is to connect an Android tablet and an Arduino with Bluetooth, itself equipped with LEDs. We have an Arduino Mega 2540 with a "bluetooth shield v1.1 by Seeedstudio" and a Samsung Galaxy Tab 2. The pairing between the devices is done, but the data transfer fails. The aim is to send the value 1 to the Arduino when the button "Turn the LED 1 on" is clicked on the app developped by ourselves. Same idea for the LEDs 2 and 3.
So it seems that it's the bluetooth program which contains a problem because the original one without bluetooth function passed the tests successfully.
Here is the code :
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 7
#define TxD 6
SoftwareSerial blueToothSerial(7,6); //(RxD, TxD)
const int LED0 = 0;
const int LED1 = 1;
const int LED2 = 2;
char serialA = 0;
void setup() {
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
}
void loop() {
char serialA;
if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
serialA = blueToothSerial.read();
Serial.print(serialA);
}
else{
digitalWrite(LED0, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
}
switch (serialA)
{
case 1:
digitalWrite(LED0, HIGH);
break;
case 2:
digitalWrite(LED0, LOW);
break;
case 3:
digitalWrite(LED1, HIGH);
break;
case 4:
digitalWrite(LED1, LOW);
break;
case 5:
digitalWrite(LED2, HIGH);
break;
case 6:
digitalWrite(LED2, LOW);
break;
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.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.println("2 seconds passed");
//char recstatus;
//blueToothSerial.print("\r\n+RTSTA:XX\r\n");
// recstatus = blueToothSerial.read();
//Serial.print(recstatus);
blueToothSerial.flush();
}
Sorry for our english we are French ![]()
Regards.