/*****************************************************************
Leonardo_XBee_Serial_Passthrough.ino
Set up a serial port to pass data between an XBee Shield
and the serial monitor.
Hardware Hookup:
The XBee Shield makes all of the connections you'll need
between Arduino and XBee. If you have the shield make
sure the SWITCH IS IN THE "UART" POSITION. That will connect
the XBee's DOUT and DIN pins to Arduino pins 0 and 1.
*****************************************************************/
// Leonardo Serial
// Leonardo Serial1 is pins 0 and 1
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
Serial1.begin(9600);
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) //USB
{ // If data comes in from serial monitor, send it out to XBee
Serial1.write(Serial.read()); //XBee/UART1/pins 0 and 1
}
if (Serial1.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(Serial1.read());
}
}
Note: If you are using an Arduino Leonardo (or any ATmega32U4-based Arduino) and not a Arduino Uno,
make sure to change the switch to the hardware "UART" position. In this case, do not need to add a jumper
wire between the RST and GND pin.
is the USB port
//XBee/UART1/pins 0 and 1
//USB
//XBee/UART1/pins 0 and 1
//Serial port
Need help?
Do you have a question about the XBee Shield and is the answer not in the manual?
Questions and answers