Wireless Connection between Arduino to Max (Bluetooth Bee and XBee) Not Working

Sara's icon

Hi all, I am trying to get an analog sensor's serial data to be sent from an Arduino Fio to be read in MaxMsp (using Version 6.1.8). I had my patch working with a Bluetooth Bee and Xbees, but now all of a sudden they both stopped connecting to my MaxMsp patch, and it seems like it must be a problem with the serial port. Right before it stopped working I had the Bluetooth Bee connected to the Fio and it was able to Pair with the Bluetooth, I did notice though that something weird was happening with the ports when I would connect it. When I printed the ports, the ports kept adding on to each other every time it was connected (Ex. Port D, Port E, Port F, PortG, PortF,... it went all the way up to J before it stopped connecting). It looked like the port was being duplicated, but I would still direct it to Port C and it would connect. Also, in my Bluetooth device list on my mac, I see the Bluetooth bee keeps appearing even after I remove it from the device list and it is not powered on, it says not connected but there is no pair button. It seems to keep reappearing only when I also have Max open. Is there some way to reset my ports in MaxMsp? What could be happening?

I tried resetting the PRAM on my Mac and that didn't seem to change anything. The XBees aren't connecting either, so it seems to be some kind of weird port issue. I played with the Baud rates and that didn't do anything either.
Attached is my Arduino Fio sketch and MaxMsp Patch.

Breath_opacity_liveVideo.maxpat
Max Patch
Sara's icon

Arduino Fio Sketch:
/* Upload this sketch into Seeeduino and press reset*/
int median_of_3( int a, int b, int c ){
int the_max = max( max( a, b ), c );
int the_min = min( min( a, b ), c );
// unnecessarily clever code
int the_median = the_max ^ the_min ^ a ^ b ^ c;
return( the_median );
}

int newest = 0;
int recent = 0;
int oldest = 0;

int newest2 = 0;
int recent2 = 0;
int oldest2 = 0;

void setup()
{
oldest = analogRead(0);
oldest2 = analogRead(1);
recent = oldest;
newest = recent;
recent2 = oldest2;
newest2 = recent2;
//Serial.begin(9600); //Serial port for debugging, Comment this line if not required
// pinMode(RxD, INPUT);
//pinMode(TxD, OUTPUT);
setupBlueToothConnection();

}

void loop()
{
// drop oldest value and shift in latest value
oldest = recent;
recent = newest;
newest = analogRead(0);
oldest2 = recent2;
recent2 = newest2;
newest2 = analogRead(1);

int median = median_of_3( oldest, recent, newest );
int median2 = median_of_3( oldest2, recent2, newest2 );

delay(100);
Serial.print(median);
Serial.print(" ");
Serial.println(median2);

}

void setupBlueToothConnection()
{
Serial.print("Setting up Bluetooth link"); //For debugging, Comment this line if not required
Serial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
delay(2000);
sendBlueToothCommand("\r\n+STWMOD=0\r\n");
delay(200);
sendBlueToothCommand("\r\n+STNA=modem\r\n");
delay(200);
sendBlueToothCommand("\r\n+STAUTO=0\r\n");
delay(200);
sendBlueToothCommand("\r\n+STOAUT=1\r\n");
delay(200);
sendBlueToothCommand("\r\n+STPIN=0000\r\n");
delay(3000); // This delay is required.
Serial.print("\r\n+INQ=1\r\n");
delay(3000); // This delay is required.
//Serial.print("Setup complete");

}

void sendBlueToothCommand(char command[])
{
char a;
//blueToothSerial.print(command);
Serial.print(command); //For debugging, Comment this line if not required
delay(3000);

// while(blueToothSerial.available()) //For debugging, Comment this line if not required
// { //For debugging, Comment this line if not required
// Serial.print(char(blueToothSerial.read())); //For debugging, Comment this line if not required
} //For debugging, Comment this line if not required

Sara's icon

Update: A direct USB connection works using an Arduino Uno. Perhaps something with my Arduino Fio code is wrong? Pretty sure I haven't changed anything though and it was working before.