Bluetooth Shield, Arduino Uno, and Brain Wave Reader

hey guys
having some weird problems with the bluetooth shield and my arduino uno
have been using a hacked mindflex EEG reader and arduino via usb to collect parsed serial data and its been working great.
thought it’d be a great idea to try and make this thing wire free on the cheap so I picked up one of the bluetooth shields

  1. the bluetooth is connecting fine
  2. i’m able to upload via bluetooth
  3. i’m even getting my data, all be it somewhat garbled but thats not a huge problem since its all coming into Max MSP for the final data analysis and the added chars are all letters not numbers, can be easily seperated

the problem is that after 30 seconds or so my connection drops out once I turn on the mindflex
the mindflex itself connects on the ground and RX, thats it
i’ve tried swapping rx/tx and input/output and that didnt work (saw that on some forum?)
I can literally watch the flashing red/green lights get off tempo, slow down, and eventually come to a halt on the green LED
this does not happen UNTIL i turn on the mindflex and it begins sending data.
as of now I am powering this with the included arduino 9v wall wart, will be replacing that with a battery pack once I know this will actually work.

I’m including the code, which i’m sure is terrible but i’m new and this is my first real project i’m tackling
hope you guys can help me out here, i’m interested in learning and want to hear any and everything you’ve got for me.
thanks

[code]#include <SoftwareSerial.h>
#include <Brain.h>
#define RxD 6
#define TxD 7

#define DEBUG_ENABLED 1

// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);

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()){//
recvChar = Serial.read();
blueToothSerial.print(recvChar);
}

if (brain.update()) {
Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
}
}
}

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();
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);
}

[/code]

Hello ,
For what you said , if the Bluetooth Shiled can work at this moment?

Deray