SoftwareSerial (w Bluetooth Mate Gold) only works if plugged into a computer

Hi guys,

I'm currently using SoftwareSerial to communicate with a Bluetooth Mate Gold from Sparkfun. Everything works fine and testing has been working great, until we battery power the unit instead of running it from the computer USB.

What we're noticing is that the SoftwareSerial communication to BT only works if the device is plugged into the computer. When we power through battery, and turn the device on SoftwareSerial stops working. Furthermore, if we power the device through USB through a charging wallwart, it still doesn't work.

Interestingly, if we power the unit with it plugged into a computer, and then remove the USB (so that it is running on battery) the unit works fine.

This user faced the same issue: http://stackoverflow.com/questions/21012371/arduino-bluetooth-works-fine-with-usb-connected-with-pc-but-does-not-work-when

However, his solution (hard reset) doesn't work for me as I don't have access to that pin when the unit is in our enclosure (plus its a weird user behavior)

I can't figure this issue out - any thoughts?

any thoughts?

Provide more details on "the battery".

Post some code.

Sure - The circuit is rather simple - it is a LiPo plugged into a Sparkfun Power Cell (https://www.sparkfun.com/products/11231) with the 5V from the breakout board feeding the 5 rail of the Arduino through an on/off switch. I then have the Arduino talking to the BT Mate Gold over Software Serial.

The code is fairly simple - what I have here is a modification of Sparkfun's echo test code for the BT Mate Gold over SoftwareSerial. The only difference is that instead of simply echoing what BT to Serial and vice versa, I spit out a counter every 3 seconds, and echo BT data back over BT.

#include <SoftwareSerial.h>  

int bluetoothTx = 1;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 0 ; // RX-I pin of bluetooth mate, Arduino D3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
long count;
void setup()
{
  bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$");  // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$");  // Enter command mode
  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
  
  count = millis();
}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    bluetooth.print((char)bluetooth.read());  
  }
  if(millis()-count > 3000)  // Send count every 3 seconds
  {
    bluetooth.print(count);
  }
}

This code works when the Arduino turns on when it is plugged into a computer, but not when the Arduino turns on through battery power.

I also don't think its the battery as if I power the Arduino through its USB port via a wallwart or external hub that is not connected to a computer and remove the battery it still doesn't work. If I plug that external hub into the computer and then plug the Arduino into the hub it works.

It sounds like marginal power in each case. Even when you power off the PC and change to battery, it could be down to that, and such a method may simply have been putting off the inevitable. It is even possible to have these problems using a PC USB port.

I note that your options don't include a 9v wall wart yet. If you take a deep breath and use one of those, it will probably solve the problem.