0

Serial1.available()=0 if Xbee adapter attached
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Serial1.available()=0 if Xbee adapter attached

by lriche on Fri Aug 05, 2016 11:08 pm

I have a Leonardo with a Xbee adapter connected to the serial Rx an Tx ports. The code below seems to work at random at times. Particularly, if I remove the Rx Tx connections first. When I print the value of Serial1.available it is 0;

I read somewhere that the Rx Tx pin must be disconnected before uploading the code. If this is true my question is why? How can I make a reliable system if I constantly have to remove the pins to get my code to run? There has to be a workaround.

Code: Select all | TOGGLE FULL SIZE
int led = 13;

void setup() {
  Serial1.begin(9600);
  Serial.begin(9600);
  while(!Serial1 && millis()<5000) {
    //wait for serial monitor to connect
  }
 
}

void loop() {
  Serial.print(Serial1.available()); // Equals 0 all the time

  while(Serial1.available()){
    digitalWrite(led, HIGH);
    Serial1.print('H');
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
  }
}

lriche
 
Posts: 2
Joined: Fri Aug 05, 2016 10:55 pm

Re: Serial1.available()=0 if Xbee adapter attached

by franklin97355 on Sat Aug 06, 2016 12:22 am

How do you have things connected and what are you sending to the xbee?

franklin97355
 
Posts: 16867
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Serial1.available()=0 if Xbee adapter attached

by lriche on Sat Aug 06, 2016 1:18 am

I have the xbee is connected to arduino via xbee adapter. I have Rx -> Tx, Tx -> Rx, 5v -> 5v GRN -> GRN. I am just sending test text to the Xbee.

lriche
 
Posts: 2
Joined: Fri Aug 05, 2016 10:55 pm

Please be positive and constructive with your questions and comments.