Hello,
I am having difficulties for many days to connect correctly BT shield with Arduino. This is the procedure that I am following, firstly I am putting jumpers in in my shield in BT_RX ->7 and in BT_TX->6 than I am moving switch of the shield in A1 direction, than I am uploading the code (I have tried with many codes, but this is the one that I need to use). After uploading D1 and D2 LED’s in shield are flushing and I am pairing BT with Mac (in Mavericks pairing is simplified so I do not change Baud rate or anything) after in Bluetooth preferences it is showing that the shield and computer are connected also in terminal after I type ls /dev/tty.*; . But when I am switching Serial port of Arduino to the new one with BT nothing is shown in serial monitor no meter which Baud rate I choose. Another problem that I am facing is that approximately 4 min after I pair BT with Mac in Bluetooth preferences is showing “No Connection” between computer and BT, but I can see the connection in terminal, also I can always just remove the old connection and computer will give me option to pair again because D1 and D2 LED’s are still flushing. I tried another method, after I upload the code I am connecting Arduino in another computer and I am pairing with Mac but I am having same effect.
I really hope that I have been clear in my explanation. Any idea would be very helpful.
#include <Encoder.h>
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
SoftwareSerial blueToothSerial(RxD,TxD);
Encoder knob(2, 3);
long positionShaft = -999;
long newVal;
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
}
void loop() {
newVal = knob.read()/11.3777778;
if (newVal != positionShaft ) {
if(newVal>=360 || newVal<=-360){
knob.write(0);
}
Serial.print(1,DEC);
Serial.println(newVal,DEC);
Serial.println();
positionShaft = newVal;
}
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knob.write(0);
}
}
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+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.
blueToothSerial.flush();
}
Best,
Ilir