Go Down

Topic: Pro-Mini+XBEE Serial RX Issue (Read 610 times) previous topic - next topic

bconstructive

My goal is to be able receive and print text that is sent from a Yun, through a XBee S2 coordinator to a XBee S2 end device which is connected to a pro-mini.
So far, sending sensor values or text via serial from the pro-mini to the Yun through the XBees has worked fine. For some reason(s) my attempts to communicate in the other direction have failed.

Any suggestions or guidance would be greatly appreciated.

My configuration and what is working.

Coordinator--picture of setup below
Arduino Yun
XBee shield
Xbee S2 Coordinator AT Mode

End Device--picture below
Pro-mini(5v 16mhz) mounted to proto board
Sparkfun XBee regulated beakout board mounted to same proto board
XBee S2 End Device AT Mode
Sparkfun FTDI basic used for USB connection to PC


The XBees were setup using XCTU in following with TunnelsUP and Robert Faludi's tutorials. Basically I selected matching PAN Ids and loaded the most recent Coordinator AT and End device AT firmware.

Here is what works on the YUN side. This is thanks to PaulS from the forum.

Code: [Select]
char inData[64];
byte index;
boolean started = false;
boolean ended = false;

#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 10 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 11 (Arduino's Software TX)
SoftwareSerial XBee(10, 11); // RX, TX


void setup()
{
  Serial.begin(9600);
  XBee.begin(9600);
}


void loop()
{
  while (XBee.available() > 0)
  {
      char aChar = XBee.read();
      if(aChar == '<')
      {
        started = true;
          index = 0;
          inData[index] = '\0';
      }
      else if(aChar == '>')
      {
          ended = true;
      }
      else if(started)
      {
          inData[index] = aChar;
          index++;
          inData[index] = '\0';
      }
  }

  if(started && ended)
  {
      
        Serial.println(inData);
      // Get ready for the next time
      started = false;
      ended = false;

      index = 0;
      inData[index] = '\0';
  }
}

 

And on the Pro-mini side anything like this works.

Code: [Select]

void Setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println("<Hello World>");
    delay(1000);
}


The above example successfully sends the text to the YUN which is displayed in the COM port.

Now, what does NOT work is.

On the pro-mini side.

Code: [Select]

char inData[64];
byte index;
boolean started = false;
boolean ended = false;


void setup()
{
  Serial.begin(9600);
  
}


void loop()
{
  while (Serial.available() > 0)
  {
      char aChar = Serial.read();
      if(aChar == '<')
      {
        started = true;
          index = 0;
          inData[index] = '\0';
      }
      else if(aChar == '>')
      {
          ended = true;
      }
      else if(started)
      {
          inData[index] = aChar;
          index++;
          inData[index] = '\0';
      }
  }

  if(started && ended)
  {
      
        Serial.println(inData);
      // Get ready for the next time
      started = false;
      ended = false;

      index = 0;
      inData[index] = '\0';
  }
}


And on the YUN side.

Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial XBee(10,11);

void setup()
{
  XBee.begin(9600);                
  Serial.begin(9600);                  
}

void loop()
{
  XBee.println("<Hello World>");
  delay(1000);

}



I've tried many different approaches to solving this to no avail. I've tried wiring the xbee breakout board's DIN and DOUT directly to the mini's RX/TX and TX/RX just for good measure. I didn't think that would work, but I tried anyway. I also tried wiring DIN and DOUT to available digital pins on the mini. Then established a SoftwareSerial instance in the code for those pins. No luck.

I know I'm missing something, but not sure what.

Any thought? Thank you for reading.

bconstructive

Perhaps one important thing to note is this. When performing Serial.println("<Hello World>") from the YUN while running the below sketch on the pro mini I do get values appearing in the pro mini serial terminal.
So, I believe the data is being received. Of course this code is not correct for what I want to achieve, but though I'd pass this fact along.
Thank you

Code: [Select]

void loop() {
  // put your main code here, to run repeatedly:
    if (Serial.available() > 0)
      Serial.println(Serial.read());
}



Result in terminal. For example.

248
240
248
230
252
252
248
248
240
240
240
240
255
30
224
255
224
255
120
240
12
128
4
192
224
224
255
240
248
248
231
147
248
224
254
255
252
254
254


Go Up