Fio 2 way communication xbee

Thanks for your help, PaulS.

"Do you think the Serial Monitor can really tell when you are looking at it?" haha, pretty funny. Like a Schrödinger's Fio serial port. I guess I've always used serial to send command to an arduino (and to view its receipt with the monitor) so I was concerned that viewing from the Arduino serial port might be eating the output.

Now it seems I've got it almost working, but what I am observing is that the 2 devices are constantly resetting each other. I suppose it has something to do with the way the serial is used for loading new software.

Right now I have to remove the xbee in order to load updated code to each Fio.

The AREF pin is jumped to 3.3V because the PulseSensor I'm using needs 3.3V.

I'm using adafruit's FTDI Friend and I lifted CTS pin because that's where the AREF (3.3V) pin is on the FTDI Friend. Perhaps I should connect the AREF directly to CTS?

Anyone have any tips on subduing the resets on the Fio?

Thanks in advance,
Chris.

Here's my simple 2 way code (buttons instead of pulse sensors)

// twowaytest.ino
// testing 2-way communications with the Fio

int buttonPin = 2; // button with 10k to gnd
int localHbLed = 13; //led to gnd
int remoteHbLed = 12; // led to gnd

int buttonState = 0;
int lastState = 0;
const int terminatingChar = 13; //Terminate lines with CR

void setup(){

  pinMode(localHbLed,OUTPUT);    
  pinMode(remoteHbLed,OUTPUT);
  pinMode(buttonPin, INPUT);  

  Serial.begin(57600);
  Serial.print(255);
  delay(2000);
  
  analogReference(EXTERNAL); 
  blink(3); // show we're on...
}


void loop(){

  buttonState = digitalRead(buttonPin);

  if (lastState != buttonState) {
    if (buttonState == HIGH) {     
      // turn LED on:    
      digitalWrite(localHbLed, HIGH);
      sendDataToOther("pulseUp");
      lastState = HIGH;
    } 
    else {
      // turn LED off:
      digitalWrite(localHbLed, LOW); 
      sendDataToOther("pulseDn");  
      lastState = LOW;
    }
  }

  getDataFromOther();
  delay(20);                          //  take a break
}

void sendDataToOther(String pulseVal){
  // send info to the other xbee
  if (pulseVal == "pulseUp"){
    Serial.print("pulseUp\r");
  }
  else {
    Serial.print("pulseDn\r");
  }
}

void getDataFromOther() {

  char* theOtherPulse = serialReader();
  // Serial.print("Other is: ");
  // Serial.println(theOtherPulse);

  // if (theOtherPulse == theOtherTest[0]){
  if (strstr(theOtherPulse, "PulseUp") != 0) {
    digitalWrite(remoteHbLed,HIGH);
    // Serial.print("recd... HIGH ");
    // Serial.println(theOtherPulse);
  }
  else {
    digitalWrite(remoteHbLed,LOW);
    // Serial.print("recd... LOW ");
    // Serial.println(theOtherPulse);
  }
}

// read serial port
char* serialReader(){
  int makeSerialStringPosition;
  int inByte;
  char serialReadString[50] = "";
  

  inByte = Serial.read();
  makeSerialStringPosition=0;

  if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
    delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)

    while (inByte != terminatingChar && Serial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
      serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
      makeSerialStringPosition++; //Increment position in array
      //if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
      inByte = Serial.read(); // Read next byte
    }

    if (inByte == terminatingChar) //If we terminated properly
    {
      serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
      // Serial.print("from method: ");
      // Serial.println(serialReadString);
      // if (strcmp(serialReadString, "LEDOn") == 0) digitalWrite(13, HIGH);
      // if (strcmp(serialReadString, "LEDOff") == 0) digitalWrite(13, LOW);

      return serialReadString;
    }
  }
  return "x"; // return this when nothing is recieved...
}

int stringToInt(String thisString) {
  int i, value, length;
  length = thisString.length();
  char blah[(length+1)];
  for(i=0; i<length; i++) {
    blah[i] = thisString.charAt(i);
  }
  blah[i]=0;
  value = atoi(blah);
  return value;
}

// blink n times 
void blink(int howManyTimes){
  digitalWrite(localHbLed, LOW);
  digitalWrite(remoteHbLed, LOW);
  delay(200);
  for (int i=0; i< howManyTimes; i++){
    digitalWrite(localHbLed, HIGH);
    digitalWrite(remoteHbLed, LOW);
    delay(200);
    digitalWrite(localHbLed, LOW);
    digitalWrite(remoteHbLed, HIGH);
    delay(200);
  }
  digitalWrite(remoteHbLed, LOW);
}