You cannot use SoftwareSerial.h library which is included in demo code from Seeedstudio BT shield, since SoftwareSerial.h file is not running on Due board. I don't know why. Someone told that they could use it, but I couldn't anyway.
So, to use serial communication in Due board, you should use HardwareSerial such as Serial, Serial1, Serial2, Serial3.
Now I use Serial1 instead of SoftwareSerial(Bluetooth).
Before modifying source code, you should use jumper wire to connect Bluetooth with Due board.
Connect BT_TX with RX1(Pin19), and BT_RX with TX1(Pin18). (TX<=>RX, RX<=>TX)
Please refer to attached picture.
After this, you should modify source code.
I modified some source from Slave_Temperature code from Seeedstudio.
/* Upload this sketch into Seeeduino and press reset*/
//#include <SoftwareSerial.h> //Software Serial Port // Shin modified, 2014.03.10
#if 0 // Shin modified, 2014.03.10
#define RxD 9
#define TxD 8
#endif
#define DEBUG_ENABLED 1
#define PIN_TEMP A5
//SoftwareSerial blueToothSerial(RxD,TxD);
int getTemp()
{
int a = analogRead(PIN_TEMP);
int B=3975;
float resistance = (float)(1023-a)*10000/a;
float temperature = temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
return (int)14;
}
void setup()
{
Serial.begin(9600);
#if 0 // Shin modified, 2014.03.10
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
#endif
setupBlueToothConnection();
}
void loop()
{
char recvChar;
while(1)
{
if(Serial1.available()) // Shin modified, 2014.03.10
{//check if there's any data sent from the remote bluetooth shield
recvChar = Serial1.read(); // Shin modified, 2014.03.10
Serial.println(recvChar);
if(recvChar == 't' || recvChar == 'T')
{
Serial1.print("temperature: "); // Shin modified, 2014.03.10
Serial1.println(getTemp()); // Shin modified, 2014.03.10
}
}
if(Serial.available())
{//check if there's any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
Serial1.print(recvChar); // Shin modified, 2014.03.10
}
}
}
void setupBlueToothConnection()
{
// Shin modified, 2014.03.10
Serial1.begin(38400); // Set BluetoothBee BaudRate to default baud rate 38400
Serial1.print("\r\n+STWMOD=0\r\n"); // set the bluetooth work in slave mode
Serial1.print("\r\n+STNA=SeeedBTSlave\r\n"); // set the bluetooth name as "SeeedBTSlave"
Serial1.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Serial1.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Serial1.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.
Serial1.flush();
}
Here I changed all blueToothSerial to Serial1.
That's all.
Also, Bluetooth SPP application doesn't work with iPhone. I don't know exact reason but someone told that iPhone doesn't use standard SPP. So use android phone to test Bluetooth.
It works well.
