我已经成功连接到 Xbees。一个通过 XbeeExplorer 连接到 CPU,另一个是 ElSequencer(一个 lilypad arduino 板)。连接效果很好,我可以毫无问题地使用串行监视器发送无线信号。波特率、泛 ID 和目标地址均正确且有效。奇怪的是,Xbee 不断向 Arduino 随机发送数据。像各种串行信号。如果我把 Arduino 打印回接收到的信号,
Serial.print(incomingByte);
我也开始看到无限信号回来了。Xbee 在没有任何命令的情况下不断发送序列是什么意思。这些值是完全随机的。Like: 126010 131005301080854 126010131005301080854 126010131005301080854 126010131005101080856 126010131005101080856 126010131005301080854 126010131005201080855
我的arduino代码如下。是一个简单的开关灯。由于 Xbee 不断发送随机信号,有时信号与编程信号匹配,并且灯会打开或关闭。
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(57600);
// The EL channels are on pins 2 through 9
// Initialize the pins as outputs
pinMode(2, OUTPUT); // channel A
pinMode(3, OUTPUT); // channel B
pinMode(4, OUTPUT); // channel C
pinMode(5, OUTPUT); // channel D
pinMode(6, OUTPUT); // channel E
pinMode(7, OUTPUT); // channel F
pinMode(8, OUTPUT); // channel G
pinMode(9, OUTPUT); // channel H
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
Serial.print(incomingByte);
//EL WIRES
if (incomingByte == 'A') {
digitalWrite(2, HIGH);
}
if (incomingByte == 'B') {
digitalWrite(3, HIGH);
}
if (incomingByte == 'C') {
digitalWrite(4, HIGH);
}
if (incomingByte == 'D') {
digitalWrite(5, HIGH);
}
if (incomingByte == 'E') {
digitalWrite(6, HIGH);
}
if (incomingByte == 'F') {
digitalWrite(7, HIGH);
}
if (incomingByte == 'G') {
digitalWrite(8, HIGH);
}
if (incomingByte == 'H') {
digitalWrite(9, HIGH);
}
//
if (incomingByte == 'I') {
digitalWrite(2, LOW);
}
if (incomingByte == 'J') {
digitalWrite(3, LOW);
}
if (incomingByte == 'L') {
digitalWrite(4, LOW);
}
if (incomingByte == 'M') {
digitalWrite(5, LOW);
}
if (incomingByte == 'N') {
digitalWrite(6, LOW);
}
if (incomingByte == 'O') {
digitalWrite(7, LOW);
}
if (incomingByte == 'P') {
digitalWrite(8, LOW);
}
if (incomingByte == 'Q') {
digitalWrite(9, LOW);
}
}
}