Arduino Uno + BluetoothShield (SLD63030P)

Hey everyone!

I’ve got a problem with the BT Shield (SLD63030P)

I try to connect my Uno Board with a Mega2560 Board. Both of them got a BT Shield. I’m able to configure the Shield so it is in Inquireing Mode, but that’s all.

I changed my Code so that I’m able to read, what the BT Shield reads and print it out on Serial.
I get this: ▒▒▒▒▒’▒▒6)▒▒▒▒▒Cፄ▒▒**U▒▒J▒6)▒

But it should be more readable i guess.
I tried several BAUD rates, but nothing changed. I also tried several Pins.

Maybe you’re able to help me.

Background:
Arduino V1.0 Library

Code:

/*
BluetoothShield Demo Code Master.pde.This sketch could be used with
Slave.pde to establish connection between two Arduino.
2011 Copyright (c) Seeed Technology Inc.  All right reserved.
 
Author: Steve Chang
 
This demo code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
For more details about the product please check http://www.seeedstudio.com/depot/
 
*/
 
 
/* Upload this sketch into Seeeduino and press reset*/
#include <SoftwareSerial.h>   //Software Serial Port

#define RxD 3
#define TxD 5
 
#define DEBUG_ENABLED  1

String retSymb = "+RTINQ=";//start symble when there's any return
String slaveName = ";SeeedBTSlave";// caution that ';'must be included, and make sure the slave name is right.
int nameIndex = 0;
int addrIndex = 0;

String recvBuf;
String slaveAddr;

String connectCmd = "\r\n+CONN=";

SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup() 
{ 
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
  //wait 1s and flush the serial buffer
  delay(1000);
  Serial.flush();
  blueToothSerial.flush();
} 
 
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);
    }
    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 setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=1\r\n");//set the bluetooth work in master mode
  blueToothSerial.print("\r\n+STNA=SeeedBTMaster\r\n");//set the bluetooth name as "SeeedBTMaster"
  blueToothSerial.print("\r\n+STAUTO=0\r\n");// Auto-connection is forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.flush();
  blueToothSerial.print("\r\n+INQ=1\r\n");//make the master inquire
  Serial.println("Master is inquiring!");
  delay(2000); // This delay is required.
    
  //find the target slave
  char recvChar;
  while(1){
    if(blueToothSerial.available()){
      recvChar = blueToothSerial.read();

Serial.print(recvChar);

      recvBuf += recvChar;
      nameIndex = recvBuf.indexOf(slaveName);//get the position of slave name
      //nameIndex -= 1;//decrease the ';' in front of the slave name, to get the position of the end of the slave address
      if ( nameIndex != -1 ){
        //Serial.print(recvBuf);
 	addrIndex = (recvBuf.indexOf(retSymb,(nameIndex - retSymb.length()- 18) ) + retSymb.length());//get the start position of slave address	 		
 	slaveAddr = recvBuf.substring(addrIndex, nameIndex);//get the string of slave address 			
 	break;
      }
    }
  }
  //form the full connection command
  connectCmd += slaveAddr;
  connectCmd += "\r\n";
  int connectOK = 0;
  Serial.print("Connecting to slave:");
  Serial.print(slaveAddr);
  Serial.println(slaveName);
  //connecting the slave till they are connected
  do{
    blueToothSerial.print(connectCmd);//send connection command
    recvBuf = "";
    while(1){
      if(blueToothSerial.available()){
        recvChar = blueToothSerial.read();
 	recvBuf += recvChar;
 	if(recvBuf.indexOf("CONNECT:OK") != -1){
          connectOK = 1;
 	  Serial.println("Connected!");
 	  blueToothSerial.print("Connected!");
 	  break;
 	}else if(recvBuf.indexOf("CONNECT:FAIL") != -1){
 	  Serial.println("Connect again!");
 	  break;
 	}
      }
    }
  }while(0 == connectOK);
}
 

Hi,there
As you said,you use the Mega2560 Board,for that,we upload the new Firmware of the Bluetoothshield,you can download it from:
http://www.seeedstudio.com/wiki/Bluetooth_Shield
There have the code for mega using the hardware serial or software serial,so depanding on the hardware to choice the demo code.
Because for the mega,Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69[via:http://arduino.cc/en/Reference/SoftwareSerial]
So if you want to use the software serial to contral the BluetoothShield,you have to make a jump wire to one of the Pin can be used for RX:10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
you can see it in the WIKI page.

Thx 4 the reply…

I actually read that, but it dont work on the Uno.

The Mega is used as Slave, it is in inquiring mode (SeeedStudio DemoCode Mega-Slave)
The Uno uses the Master code, but as I’ve written before, the output of search is just weird char’s.

And if I understand the Code right, it triggers the Slavename which is defined at top of the code…

Should the “output” be readable?

Thx in advanced!

Hi,
Can you take a picture for me,so i can see the hardware and check if it is right.

Hey. Sure u can.

View

On the Uno, all Pins are used, and yes I’ve put it in the correct way (one side 5V/GND and other side Digitalpins) xD

Please show the raw (HEX) output (and the string you send) of your comunication.

All messages that are sended are listed in my first comment!

The code is 1:1 the demo code provided from Seeed Studio.
I just added one Serial.println() which is printing:

recvChar… And this Sting is the same as you’ve recived.

Please show the raw (HEX) output (and the string you send) of your comunication.

schmron, meinst du das .hex file?

hex-file ist im anhang…

Keine ahnung was du mit string in der comm. meinst. Ich send (per hand) garnichts.
Alles andere ist aus dem Demo-Code (Anhang)

Hex: Bluetooth_Uno.hex.zip (7.28 KB)
Demo:Code: Bluetooth_Uno.pde.zip (1.78 KB)

lg. Danke!

Nein.

Sendest du ein Zeichen übe die serielle Schnittstelle wird nicht das Zeichen gesendet sondern das dazugehörige Byte.
Beispiel:
Serial.println(“Hello World!”);
würden also am Empfänger so aussehen:
0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64

Maschinen können eben nur Bits und Bytes lesen :wink:

Die Symbole die du gepostet hast sind alle nicht aus dem normalen Zeichenbereich (0x20-0x7F). Jetzt wäre interessant ob es da ein Muster gibt das darauf hinweißt ob es sich nur um einen Programmierfehler handelt oder ob das zufällig passiert. Das kann man aber nur sehen wenn du die Daten im richtigen Format hergibst.

edit
Achso: du kannst dein Terminal so einstellen das es dir die übertragenen Bytes anzeigt statt der fertigen Zeichen.

Aha ok…

Wie mach ich das?
Bzw. Mi ist aufgefallen wenn man die Bautrate ändert, kann man mal mehr/mal weniger lesen.
Weis jetzt nicht mehr genau, was ich getestet habe aber irgendwas zwischen 9600 und 38400 glaub ich.

Aber wenn du den Code ausprobiert, der oben gepostet ist, bekommst du das dann ans laufen?

lg. Danke

Sorry für die lange Pause.

Hab das Ganze mal wieder angetestet.
Hab jetzt auch mal einen Raw output zusammen gebracht:

#include <SoftwareSerial.h>
SoftwareSerial GPRS(6,7);
void setup()
{
  GPRS.begin(38400);               // the GPRS baud rate   
  Serial.begin(38400);             // the Serial port of Arduino baud rate.
 
}
 
void loop()
{
  if (GPRS.available())
    Serial.println(GPRS.read());
  if (Serial.available())
    GPRS.println(Serial.read()); 
}

Wenn ich nun auf der Tastatur auf “a” drücke, wird folgendes ausgegeben:

Bzw. in HEX:

ICh weis, dass das DEFINITIV der falsche Wertebereich ist, nur weis ich nicht woran es liegt…
Wenn ich die Baudrate runter setze werden die Werte drastisch kleiner bzw umgekehrt wenn ich sie vergrößere…

Habe auch die Ports 2,3 schonmal versucht bzw auch 5,6… BITTE um hilfe…

DANKE