Bluetooth Shield input scrambled

Hi All,

I am using Arduino 1.0 with my Arduino Uno rev.3 and the SeeedStudio Bluetooth Shield v1.1

I am having problems with my data being scrambled when sending commands via Bluetooth on my Android phone. I modified the program provided by SeeedStudio for setting up the Slave feature. I am trying to send a single character i.e. ‘a’ or ‘l’ to make pin 13 turn on or off. The code is not functioning, not because of my code, but because the data seems to be getting scrambled.

The reason I began the test is because when I tried the code and setup the BT device with my Android, all serial input being entered on the PC terminal displays perfectly on the Android, but when I send from the Android, all I see on the PC is foreign and unknown characters.

Something seems to be wrong in my settings somewhere, but I am using the SoftwareSerial library built into Arduino IDE. I have also tried to use the NewSoftSerial library from SeeedStudio but that wouldn’t even work because of errors when compiling.

Someone please help me find the reason behind the scrambled data!

OS: Ubuntu 12.04

#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
 
#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);


 
void setup() 
{ 
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
  pin13Setup();
} 
 
void loop() 
{ 
  char recvChar;
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      changeLEDstatus(recvChar);
    }
    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();
      blueToothSerial.print(recvChar);
    }
  }
} 
 
void changeLEDstatus(char x)
{ 
  if(x==(char)'a'){
      digitalWrite(13, HIGH);
   }
   else if(x==(char)'l'){
      digitalWrite(13, LOW);
   }
  
}

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=Arduino\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect to 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("Bluetooh ready to connect!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

void pin13Setup()
{
  pinMode(13, OUTPUT); 
  digitalWrite(13, LOW);
}

If you make a instance of SoftwareSerial, the pinMode already is set.
The two lines above are useless.

Why do you loop in a loop?!

‘a’ is already a char. You don’t need to convert a char in a char.

The bluetooth module dont work with this speed if you use SoftwareSerial. If you want to use it with this speed use the hardware uart (D0, D1) or set the baudrate to 9600.

I’m having the same issue. Ubuntu 12.04, Arduino 1.01. I’ve tried switching to different TX/RX pins as suggested in other threads from people who have complained about this, with no luck.

schmron, most of the things you brought up were the way they were in the example code for the product. Setting pinmode, the loop inside of loop, the 38400 baud rate, they are what Seeed posted in their examples. When I read the documentation for SoftwareSerial, it says it can be used at 38400 baud. Do you have example code for setting the module to 9600? I tried what seemed reasonable, based on the wiki, and I currently can’t communicate with that module :slight_smile: I have a spare, but I still have this scrambled data in one direction, but not the other!

Adam Wolf

Connect bt uart to arduinos hardware uart… init serial with baud 38400.
Send AT command +STBD=9600 to bt module: seeedstudio.com/wiki/Serial_ … ster/Slave#Commands_to_change_default_settings
(Only one time!)
Connect bt uart to arduinos software uart ports… init softwareserial with baud 9600.
ready :wink: