Bluetooth power saving mode for ArduinoBT

I'm trying to get my ArduinoBT to be a bit more power friendly, I have it running in a sensor network and it is constantly drawing power. I want to be able to turn off or put the Bluetooth module to sleep for durations when it isn't in use.
I've tried

Serial.println("SET CONTROL CONFIG 103d");


In my setup method which should put the module into deep sleep mode but it doesn't seem to do anything in terms of power consumption (still draws about 30mA).
Am I not waiting long enough for it to kick in? Does the WT11 iWRAP version not support deep sleep? Am I putting it in the wrong spot in my code? Am I doing something else incredibly ditzy that is stopping it from working??

The code I'm running at the moment is just

setup()
{
Serial.println("SET CONTROL CONFIG 103d");
}

loop()
{
Serial.println("SLEEP");
}


but I've also tried the SLEEP command in the setup, and putting this code in the ArduinoBT bootloader. I left the Arduino with sleep enabled running for several hours and it made no difference to the consumption, also "SET CONTROL CONFIG 102d" doesn't make any change. Perhaps I'm issuing the commands in data mode? I understand that data mode is when there is a Bluetooth connection and command is when there isn't a connection but I might be mistaken.

Sorry I've taken so long had my exams and holidays.

My code eventually evolved to be something like this:

int input = 0;
int resetPin = 7;
int ledPin = 13;

void setup()
{
pinMode(resetPin, OUTPUT);
Serial.begin(115200);
Serial.println("SET CONTROL ESCAPE 43 00 0");
Serial.println("SET CONTROL CONFIG 103D");
digitalWrite(ledPin, HIGH);
}

void loop()
{
if (!input)
{
delay(2000);
Serial.print("+++");
delay(2000);
Serial.println("TEST DEEPSLEEP");
delay(10000);
Serial.print("+++");
delay(2000);
input = 1;
digitalWrite(ledPin, LOW);
}


Which doesn't work (YAY!)

I then found some code here which had successful iWRAP communication, I modified it to include the iWRAP I wanted, started with "INFO" and found out the version of iWRAP (WRAP THOR AI 2.2.0 build 60) obtained the correct datasheet found that deepsleep was feature of the module and that you could test it using the "TEST DEEPSLEEP" command. I used that command and the board slept! I think... the current sat at around 36mA which is higher than normal unconnected use but the board was incommunicable. The test returned an OK so I'm confident that I can make the board sleep now. Unfortunately issuing the "SLEEP" command doesn't seem to do anything atm, though I don't know if my initial setup commands are being issued yet.

Anyhoo here is the (barely) modified code I'm using now. Basically run it then enter "&" into the serial monitor and it goes to command mode and issues the commands you put in the code, enter "@" and it tells you the response to those commands.

#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");
Serial.println("SET CONTROL CONFIG 103D");
}

void loop()
{
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.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("SLEEP");  //THIS IS WHERE YOU ENTER THE COMMANDS
//"INFO" and "TEST DEEPSLEEP" are both successful
//"SLEEP" isn't successful yet

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
}


Yay epic edit! Thanks so much for your help, it's been invaluable to my journey :)

• You can edit your post. – Kortuk Dec 3 '09 at 3:59
• yeah except I did it anonymously and had a cookie fail :/ – Jess Dec 3 '09 at 5:04
• Thanks for posting the code and the link. Just an hour ago I got my NB1 board to pair with my android using the WT12A. I was looking for some more detailed examples of the iWRAP commands and just found your post ;) Sweet! I would press the up-arrow a couple of times but it looks like it is one to a customer ;) – jluciani Jan 7 '10 at 2:00

The spec sheet for the BlueGiga module gives an average supply current of 1.5 mA when the module is IDLE and Deep Sleep is ON. The ArduinoBT page, though a bit light on details, implies the ArduinoBT does support any configuration modes the BlueGiga is capable of, and the spec sheet on the BlueGiga site does say it is capable of the Deep Sleep mode, so that's out. I doubt the Arduino is consuming 28.5 mA when idling, so unless you have something else in the circuit it's probably somewhere in the code. Would you post your code and schematic for further review?

---EDIT---

I looked a bit further into the iWire document I linked in the comment below. Your understanding seems correct, but there's an override to force command mode: Issue the escape character three times (See Page 15). Have you tried issuing three escape characters? It also says on Page 15 that

When iWRAP enters to command mode READY event occurs (Unless masked away with “SET CONTROL ECHO” command.)

Are you listening for READY events? On Page 23, for example, it appears that READY is issued over the serial port and you could quite easily listen for it.

I'll also ask if you've reviewed your setup and connection code. For example, serial communications with the BT module need to be at 115200 bps (http://www.arduino.cc/en/Guide/ArduinoBT). I didn't see that line in your setup code, but you could try adding

Serial.begin(115200)


before the println statement in your setup() method. You said that you posted all of the code, so this is probably the first thing I'd try. If you don't set the baud rate properly, you're just sending garbage. Keep us posted!