ArduinoBt searching for other BT devices

Hi all,

I've a quistion; has somebody used the INQUIRY command that is in the IWRAP manual?
I'm trying to use it to search for other devices in teh area and save the Bluetooth adresses in a array, but I don't get the information back to the arduino or to processing. Could somebody give me a lead were to search for more information or a good example how to use the commands from the manual on the way that I could use the information that I get back from the bluetooth module.

Thanks in advance.

Gr... Arjen

i've done it
the only thing is that the data comes back to arduino when it's not connected to the computer... if the computer is
connected the arduino "Serial" port is busy talking to it.

there are two ways...
1 send the escape code to switch to command mode... send inquiry... collect the data.. send the escape again
(now you're back in contact with the comp) and send the data back to the computer.

2 display the data on an lcd display on the arduino.

Thanks for your response!

I'm trying to get the first option working. Sending the escape command has worked. But then I get a problem with saving all the incoming data. I think the problem is that I never know how much data is comming back, so that I can save it in a sting and send it later back to the computer. I'm also not sure about when the INQUIRY has ended so that I can send again the escape command and send the data back.

Could you help me with those problems?

Thanks!

Is it possible to use the multiplexing mode to control the IWRAP module and the computer at the same time?

One of the problems with saving your data in an array is memory usage. You have only 1k of memory available so you can't make a huge array. I tried increasing the serial buffer but it didn't work either. I don't get the complete response from the WT11 and after the initial output of the WT11 it always sends 14 characters at a time. I don't have a clue what is going on.

Multiplexing would be interesting. BUT, if you set the WT11 to multiplexing and you want to change something of the WT11 parameters you have a problem, unless multiplexing is working flawless right away. Because in multiplexing the ASCII commands don't work anymore. You might try to escape this with the SET CONTROL BIND for a command issued by a signal on a pin of the WT11. But, I have had no luck yet with the hardware control on the WT11 pio's.

So multiplexing will not work.
Can somebody help me with the right settings for the control echo.
I think that I don't do it on the right way.

So multiplexing will not work.
Can somebody help me with the right settings for the control echo.
I think that I don't do it on the right way.

NO NO NO NO don't touch the control echo!

If you do that then the WT11 will mess up programming the arduino. Not only are sending the program but there will also be events from the WT11 on the TX line to the atmega.
NO NO NO NO don't touch the control echo!
NO NO NO NO don't touch the control echo!
NO NO NO NO don't touch the control echo!

(I learned from experience >:( )

Could somebody help me with example code for switching from data to command mode.
Preforming a command like the call or inquiry command and then switching back to the data mode?

Could somebody help me with example code for switching from data to command mode.
Preforming a command like the call or inquiry command and then switching back to the data mode?

Yeah, I would to see a piece of code for that.

But sondag, you already had the escape sequence working you said. Did you try an inquiry with little output, store it in a string and then switch back to datamode with the escape sequence? Let's say LIST, with only 1 connection there will be a "LIST 1" line and a "LIST 0 xxxxx" from your currenct connection.

At least I've got it working, here is the code:

#include <TextString.h>

int ledPin = 13; // LED connected to digital pin 13
int resetPin = 7; // BT module uses pin 7 for reset
char inByte = 0; // incoming serial byte
TextString incomingString = TextString(100);

void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(resetPin, OUTPUT);
Serial.begin(115200); // start serial at 115200 kbs
}

void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
inByte = getbyte(); // get incoming byte
if (inByte == '&' ) { // look for a &
getInfo();
}else if (inByte == '@' ) { // look for a 0
digitalWrite(ledPin, LOW); // set led LOW
Serial.print("Get string: ");
Serial.println(incomingString.getArray()); //print string
Serial.println("Cleared string");
incomingString.clear(); // empty string
}else{
saveCharToString(inByte); // no right char then save it to sting
}
}
}

void getInfo()
{
digitalWrite(ledPin, HIGH); // set led HIGH
delay(2000);
Serial.print("+++");
delay(2000);
Serial.println("INQUIRY 5");
for (int i=0; i <= 10; i++){
delay(1000);
while (Serial.available() > 0) {
inByte = getbyte(); // get incoming byte
saveCharToString(inByte); // no right char then save it to sting
}
delay(1000);
}
delay(2000);
Serial.print("+++");
delay(2000);
digitalWrite(ledPin, LOW); // set led low
}

char saveCharToString(char inByte)
{
incomingString.setCharAt(incomingString.length(), inByte); // save char to string at last position
}

char getbyte()
{
while (Serial.available() == 0) { //look for aviable data
// do nothing, wait for incoming data
}
return Serial.read(); //return data if aviable
}

When you send in the serial monitor from arduino the symbol "&", the Arduino BT will start an INQUIRY.
A led will blink that is connected on port 13. When the led go's off the INQUIRY is ready.
You can send then a "@" to get the data back in the serial monitor.

Thanks all for your help!

Very nice. I changed the inquiry to SET so I could see the parameters of the module. I tried to get the interruts on the pio's working but did not succeed. Thanks to your program I could see that I didn't have these bind commands. I already got the parameters from the WT11 before but I couldn't believe that there were so little settings. Your programs shows the same, so, for some reason my set control bind commands don't stick.

When you get it working please let me now.
Thanks in advance!

I am still struggling with the SET CONTROL BIND. Your code was helpfull but I still haven't figured out why the BIND doesn't work.
I changed your code a bit because I had the feeling that the output is not always complete. I store the output in the eeprom and read it back afterwards.

#include <TextString.h>  
#include <EEPROM.h>

int ledPin = 13;                // LED connected to digital pin 13
int resetPin = 7;                  // BT module uses pin 7 for reset
char inByte = 0;                // incoming serial byte
int  infoSize = 0 ;
void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(resetPin, OUTPUT);  
  Serial.begin(115200);        // start serial at 115200 kbs
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {    
    inByte = getbyte();  // get incoming byte
    if (inByte == '&' ) { // look for a &
      infoSize = getInfo();
    }
    else if (inByte == '@' ) { // look for a 0
      digitalWrite(ledPin, LOW); // set led LOW
      Serial.print("Get string:  ");  
      for(int i=0;i<infoSize;i++) //eeprom print lus
      {
        Serial.print(EEPROM.read(i));
      }
      Serial.println();
      Serial.print("Cleared string  size: ");
      Serial.println(infoSize);
    }        
  }
}

int getInfo()
{
  int j=0;
  digitalWrite(ledPin, HIGH); // set led HIGH
  delay(2000);  
  Serial.print("+++");
  delay(2000);

  Serial.println("SET");
  //Serial.println("SET CONTROL BIND 0 8 FALL INFO");  
  //Serial.println("SET BT PAGEMODE");
  //Serial.println("SET BT ROLE");
  //Serial.println("INFO");
  for (int i=0; i <= 10; i++){
    delay(1000);
    while (Serial.available() > 0 && j <512) {    
      inByte = getbyte();  // get incoming byte    
      EEPROM.write(j, inByte); 
      j++;
    }
    delay(1000);
  }  
  delay(2000);
  Serial.print("+++");
  delay(2000);
  digitalWrite(ledPin, LOW); // set led low
  return j;
}


char getbyte()
{
  while (Serial.available() == 0) { //look for aviable data
    // do nothing, wait for incoming data
  }
  return Serial.read(); //return data if aviable
}

I think that the problem is the serial buffer. I found out that the serial buffer is 128 characters big. I'm not sure of the ArduinoBT in command mode can save characters out off the serial buffer in the mermory of the chip. If that's not a problem then it should not matter if you save the data in the eeprom like you do or in a string like I did. Hopes this will help.

Has somebody tried to get the serial buffer bigger and how does this go?

I forgot, I change the serial buffer constantly. It is i wiring_analog.c. But the serial buffer is in RAM if I am not mistaken, so increasing the buffer decreases space for your variables. Since you only have 1k there is a limit to what you can do.

Try changing it. At some point I also printed out the returned size of the string. If that equals the serial buffer you know that you are missing info. I also increased the textstring size. Eventually I tried the eeprom.

Nice script so far I say.
I tried it as well in order to do an INQUIRY.

it seems to execute it ok, yet I am not seeing any found devices.

If I check on my mac bluetooth discover, I found 6 devices.

I set the INQUIRY to 10 (seconds right?) and it still doesnt print any device info after I sent "@" to the module.

any ideas?

is there a way to catch and display the response of the INQUIRY process?
so far its not printing any of any found objects, which mans i dont even know if it finds anything

For the INQUIRY you need to change from data to command mode. Are you sure you are changing on the right way from data to command mode and back? Before you can do that on the way I did that, you need to change some code in the BT ini sketch. You only need to do this once. Somewere in this forum stays how you need to do that.

All the data that you get when you are doing the INQUIRY you need to save in a string or in the EEPROM. After switching back from command mode to data mode you can send them back to PC. The other way is to hook up a LCD screen or something to show directly what you found.

Another important thing is the timing in the code between switching between data and comand mode and viceversa. Check the manual from th WT11 for details.

Hopes this helps.

okay that makes sense.

I will try the code that writes the result to the EEPROM

one thing for my understanding : Serial.println("SET CONTROL ESCAPE 43 00 0");

switches to COMMAND mode,
yet some users commented that I have to get back to data mode at the end of the process otherwise my arduinobt would be rendered useless

is that included in the working code that scans on INQUIRY 5 NAME?

I guess you guys know which sample from the forum I am talking about.

Just to be on the safe side of things.

anyone know the difference between using SELECT or ESCAPE to switch to data mode?

anyone checked the MUX mode, which actually seems to be a combined mode without the necessity of switching back and forth all the time.