How to use xbee or other thing base on TTL?

I can ues my xbee on arduino uno very well.
but i canot use it on arduino yun for the same code.

 // Analog input pin that the potentiometer is attached to

        // value read from the pot
String val = "";     

void setup() {

  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}

void loop() {
  if(Serial.available()>0){
   
  
  val+= char(Serial.read());
  delay(100);
 
  Serial.println(val);
  Serial.flush();
  val="";
  }
}

zixzixzix:
I can ues my xbee on arduino uno very well.
but i canot use it on arduino yun for the same code

Common issue, your code uses the serial port of the Uno, that will not work on a Yun, as the serial port is used for the bridge between the two different parts (MIPS/AVR) of a Yun...

Ralf

Thank you.
So I must use soft serial?

zixzixzix:
Thank you.
So I must use soft serial?

Yup, that's the most likely alternative...

Ralf