Serial1.available()=0 if Xbee adapter attached

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
lriche
 
Posts: 2
Joined: Fri Aug 05, 2016 10:55 pm

Serial1.available()=0 if Xbee adapter attached

Post by lriche »

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

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

User avatar
Franklin97355
 
Posts: 23903
Joined: Mon Apr 21, 2008 2:33 pm

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

Post by Franklin97355 »

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

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

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

Post by lriche »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”