Using the Bluetooth module on the ArduinoBT

So my ArduinoBT arrived today :smiley: it semed like a long wait especially with Christmas holidays slowing the post.

I have it flashing LEDs (ok one LED) and sending serial data back to my PC over bluetooth. It was pretty easy to get it up and running all things considered.

Its all very well using the WT11 as a virtual serial cable, but what I'm really looking to do is use the WT11 to interface with mobile phones / PDAs.

Is it possible to keep the serial link to the PC alive and use the other bluetooth channels (there are 7 right?) to contact other devices?

What would be a great start would be code that sent a list of nearby bluetooth devices back to the PC. Is there any code available for this?

Can anyone point me in the right direction?

Thanks for your halp,

Mike

To answer my own question -- this has been discussed in the following thread:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1181825471

I am having some trouble getting this going, so maywell be back for some more help.

Regards,
Mike

OK - I need some help on this one.

Looking at the code in the thread I mentioned in my last post, the AVR swaps the WT11 between command and data modes using the escape sequence "+++" preceded and followed by a 2 second delay. This is confirmed by the iWrap manual: http://www.bluegiga.com/default.asp?file=210

Looking at the initialiasation sketch: http://www.arduino.cc/en/Main/ArduinoBTInitializationSketch

we have the following line:

Serial.println("SET CONTROL ESCAPE - 00 1");

according to the iWrap manual, this disables the escape sequence :o and sets the wt11 to command mode when the PIO0 goes low. I can't see a PIO0 on the schematic http://www.arduino.cc/en/uploads/Main/arduino_bt06.pdf and no wiring to any of the GPIO pins.

So, moving forward:

  1. is it possible to use a different SET CONTROL ESCAPE command in my sketch to enable the +++ esacpe sequence? I'm concerned that doing so will make the communication to the PC stop and I'd then have an unusable Arduino;

  2. is using a hardwired link to one of the wt-11 PIO pins preferable?

Thanks,

Mike

It is has been a while since I did something with arduinoBT. So, answers may not be accurate. If you have some patience, I plan to pick it up again in 1 or 2 weeks or so.

according to the iWrap manual, this disables the escape sequence and sets the wt11 to command mode when the PIO0 goes low. I can't see a PIO0 on the schematic http://www.arduino.cc/en/uploads/Main/arduino_bt06.pdf and no wiring to any of the GPIO pins.

You have to pick up the GPIO pins next to the WT11. There are through holes, you have solder some wires in them.

  1. is it possible to use a different SET CONTROL ESCAPE command in my sketch to enable the +++ esacpe sequence? I'm concerned that doing so will make the communication to the PC stop and I'd then have an unusable Arduino;

No, changing the escape sequence will not render the arduino useless.

  1. is using a hardwired link to one of the wt-11 PIO pins preferable?

Well, that depends on what you want to do with it. But if I am not mistaken the firmware on the WT11 is too old for this to work. You have flash it with a more recent version. If you have the escape sequence working you can query the WT11 to see what version it is. I ordered my BT board immediately when it was available, maybe the firmware on the more recent boards is uptodate.
I would advise to read the bluegiga documentation a few times, the firmware and user guide. Play around with the code from the first thread you mentioned.

Do you have a specific project in mind?

Thanks for your reply - I'll change the escape sequence so that it expects "+++" and see how I get on then.

I've been reading the documentation - its going ok, but the bit that seems vague is the Arduino interface - once I have that sorted I'll get stuck in properly.

My project? At the moment I'm just toying with some ideas relating to proximity marketing - sending vcards, text, images and MP3s. Do you have experience sending these items?

Thanks again,

Mike

The first project in line is a thermostat for my house. I want the usual stuff, programmable temperature and timing. But I also want to log the measured temperature and watertemperature of the heater. Maybe, if I have enough data I can optimize the system for efficiency and comfort. I am also thinking about using my BT phone as a proximity switch. So, when I leave home, the heater will switch off and when I enter the house it will switch on. Oh, and the thermostat is going to be wireless of course.

That seems like a decent project. What are you going to use for a temp sensor?

I was looking at using a Dallas Semi temp sensor that was aimed at battery packs. It periodically sensed the temperature and maintained a histogram type table. It had one of their 1-wire interfaces so was easy to use. I'll see if I can find a part number for it.

Mike

That seems like a decent project. What are you going to use for a temp sensor?

I was looking at using a Dallas Semi temp sensor that was aimed at battery packs. It periodically sensed the temperature and maintained a histogram type table. It had one of their 1-wire interfaces so was easy to use. I'll see if I can find a part number for it.

Mike

I have a some DS18S20. Once you have 1-wire working they very easy to use.

I searched for the code that I used. I am not 100% sure if it works, I haven't checked it. Sometimes I modify working code because the goal is just a moving target. At some point I lose interest and the code is not usable anymore. I do use svn, but sometimes I forget to commit the working versions with a decent log message. :slight_smile:

So, change your escape character to "43", that is "+". Make a copy of the BT-init program. From experience I can tell you that it is always handy to keep an original BT-init program around, in case you mess things up. Ok, escape sequence is like this:

Serial.println("SET CONTROL ESCAPE 43  08 1");

Then upload the following program. You can type in a WT11 command, this will be executed and the output is stored in the EEPROM. Afterwards this is read back and sent to your serial port. Oh, and install the textstring library.

#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
TextString incomingString = TextString(50);
int  infoSize = 0 ;
long lastTime = 0;
boolean ledon = true;
boolean commandDone = false;
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 (millis()-lastTime > 300) 
  {
    ledon = !ledon;
    lastTime = millis();
  }
  if (ledon) digitalWrite(ledPin, HIGH); 
  else digitalWrite(ledPin, LOW); 
  if(Serial.available() > 1 )
    {
      getString();
    }
    else if (commandDone)
    {
      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);
      commandDone = false;
    }
}
void getString()
{
  delay(100);
  //int stringSize = 3;
  int stringSize = Serial.available();
  char comStr[stringSize];
  for (int i=0;i<stringSize;i++)
  {
    comStr[i] = getbyte();
  }
  comStr[stringSize] = 0;
  Serial.print("stringSize: ");
  Serial.print(stringSize);
  Serial.print("   ");
  Serial.println(comStr);
  doCommand(comStr);
}
void doCommand(char *command)
{
  //Serial.print("final test: ");
  //Serial.println(command);
  
  int j=0;
  digitalWrite(ledPin, HIGH); // set led HIGH
  delay(2000);  
  digitalWrite(ledPin, LOW); 
  Serial.print("+++");
  delay(2000);
  digitalWrite(ledPin, HIGH); 
  Serial.println(command);
  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);
    digitalWrite(ledPin, LOW); 
  }
  infoSize = j;  
  delay(2000);
  digitalWrite(ledPin, HIGH); 
  Serial.print("+++");
  delay(2000);
  digitalWrite(ledPin, LOW); // set led low
  commandDone = true;
}


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

The program works slowly. You have to wait for the reset times involved with switching between modes. These values are a bit on the safe side. When arduino is waiting for a command led13 flashes. If it is going in command mode the led flashes very slow. Be patient!

That's great, thank you. I'll give it a try this evening.

Is the command/data mode change over quicker if using the hardwired mode, do you know? I haven't seen long delays mentioned in the datasheets.

Regards,

Mike

Hi guys,
I just received my arduino bt and trying to get into having it communicate with mobiles.

Looking for code to start with, I was thinking the above one.
What does it exactly do? What's the read it gets? Do I have to add a sensor/device to have a read comingback?

Whats the best way to debug apart from checking LED blinkings? Is there a way to have the arduino talk back the messages to the Arduino software for debugging/checking?

Sorry, about so many questions at once, but I am a bit new to this. :-/

I would start with something really simple. Just let the arduino write something to the serial port and flash a led. Make a simple message and add millis() or a custom counter to it. Any device with BT and a serial terminal can display the message that is sent from the arduino.

Is it possible to keep the serial link to the PC alive and use the other bluetooth channels (there are 7 right?) to contact other devices?

I'm not sure about that. I made a script in whitch I let the arduinoBT sitched between the INQUIRY command and the CALL command. Firts I led the ArduinoBT searching for other devices, save them in an array and then I make a CALL from the ArduinoBT to the computer to send the data back.

The problem is that you can't use the serial buffer for two diffrent purposes at the same time. So or you can send data from one to another and back (data mode) or you can look for other devices or do something else in the command mode. So it's possible to restore a connection when you write the script on the right way, but I don't think it's possible to keep to connections on the same time a live.

At the moment I'm just toying with some ideas relating to proximity marketing - sending vcards, text, images and MP3s. Do you have experience sending these items?

Doing the proximity is not that hard, I have used it a couple of times already. You let teh arduino search for other deveices in the area(command mode), save them in the eeprom or an array or someting. Switch back to data mode and restore your connection to a device or use the data later.

For sending data from teh arduinoBT to other devices, I have only used text and other simple data. The problem is the serial bufer from the diffrent deveices, especially when you want to send data to the arduinoBT. Another problem with mp3 and vcards is the internal memory from the arduinoBT, it's simly not big enough to hold your code and a big file that you want to send.

At this time I'm trying to get a sd card running to enlarge the memory from the arduinoBT but no luck this far.

If you get the hardwire working so that you can use more then one Bluethooth channel please let me now.

I hope this helps

Woohoo - its working :smiley:

bigengineer - your set control escape line that you gave didn't work. I changed it to:

Serial.println("SET CONTROL ESCAPE 43 00 0");

and the thing burst into life.

Sending the command INQUIRY 5 NAME returned the following:

READY.
INQUIRY 5
INQUIRY 00:0b:0d:4d:fb:f8 020104
INQUIRY 00:10:60:10:76:06 020340
INQUIRY 00:05:c9:fa:71:16 520204
INQUIRY 00:1a:75:f4:44:aaNAME 00:0b:0d:4d:fb:f8 "MWLAPTOP"
NAME 00:10:60:10:76:06 "BTAP-7606"
NAME 00:05:c9:fa:71:16 "banana LG"
NAME 00:1a:75:f4:44:aa "K550i"
NAME 00:18:13:08:c9:98 "What? "

it can be seen that there are some transmission errors somewhere in the data transfer. I wonder if the AVR can keep up with the serial data from the WT-11 when it is writing to the EEProm.

The code I used was:

#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
  
  Serial.println("SET CONTROL ESCAPE 43 00 0"); 
}

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 &
        Serial.print("Got an &  ");
      infoSize = getInfo();
        Serial.println("Done");
    }
    else if (inByte == '@' ) { // look for a 0
      digitalWrite(ledPin, LOW); // set led LOW
      Serial.print("Get string:  ");  
      for(int i=0;i<infoSize;i++) 
      {
        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("INQUIRY 5 NAME");
  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
}

There is still some work to do - finding the cause of the transmission errors and I guess some external SRAM is required as it looks like the string data back from the WT-11 could easily exceed the EEProm and ram in the AVR.

Regards,

Mike

it can be seen that there are some transmission errors somewhere in the data transfer. I wonder if the AVR can keep up with the serial data from the WT-11 when it is writing to the EEProm.

If I am right, I started using the eeprom to get all the info from the WT-11 returned. I'll load my program again to see how it works for me. And I'll try you program.

I copied the escape sequence from another program, I probably made it different for a special, and now forgotten, reason.

It would appear to not be the EEPROM. In the code I posted, I added a array of 512 bytes and wrote to that instead of the EEPROM - I still get the errors.

(I guess I'm assuming that writing to an array in internal SRAM is quicker than writing to EEProm.

Regards,

Mike

Maybe you should increase the serial buffer size a bit. I know I mentioned it somewhere on the forum. It is in wiring_serial.c.