嗨,原來的Serial已經占用成Debug了,當然沒作用了,您要另外創一個Soft Serial並接線,以下是參考範例
#include <NewSoftSerial.h>
#define Rx 6 // DOUT to pin 6
#define Tx 7 // DIN to pin 7
NewSoftSerial Xbee (Rx, Tx);
void setup() {
Serial.begin(9600); // Set to No line ending;
Xbee.begin(9600); // type a char, then hit enter
delay(500);
}
void loop() {
if(Serial.available()) { // Is serial data available?
char outgoing = Serial.read(); // Read character, send to XBee
Xbee.print(outgoing);
}
if(Xbee.available()) { // Is data available from XBee?
char incoming = Xbee.read(); // Read character,
Serial.println(incoming); // send to Serial Monitor
}
delay(50);
}
以上希望對您有用