我想使用Adafruit + Xbee + Xbee S2的Arduino UNO R3 +终极全球定位系统盾(内置gps)和另一个只有Xbee + Xbee模块的Arduino MEGA来制作一个项目。
下面的代码是来自adafruit的库,它使用波特率为115200在控制台中输出gps数据。我的问题是,使用这种代码,xbee变得不可再阻塞(使用XCTU),因此我无法配置它。
我的问题是,我的xbee是否仍然工作,即使它无法识别,或者我对softwareSerial引脚或其他东西有问题?
请注意,全球定位系统工作和输出数据好。
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 7);
SoftwareSerial xbeeSerial(2,3);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO false
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup()
{
Serial.begin(115200);
xbeeSerial.begin(9600);
Serial.println("Adafruit GPS library basic test!");
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
}
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v) {
if (v) {
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run over and over again
{
if (! usingInterrupt) {
char c = GPS.read();
if (GPSECHO)
if (c) Serial.print(c);
}
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if (timer > millis()) timer = millis();
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
Serial.print(GPS.hour, DEC); Serial.print(':');
Serial.print(GPS.minute, DEC); Serial.print(':');
Serial.print(GPS.seconds, DEC); Serial.print('.');
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("Location: ");
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(", ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Location (in degrees, works with Google Maps): ");
Serial.print(GPS.latitudeDegrees, 4);
Serial.print(", ");
Serial.println(GPS.longitudeDegrees, 4);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
}
}
}发布于 2015-02-04 17:58:27
XBee屏蔽的文档似乎暗示这是预期的行为:
当跳线处于USB位置(即在离板边缘最近的两个引脚上)时,DOUT引脚Xbee模块连接到FTDI芯片的RX引脚,Xbee模块上的DIN连接到FTDI芯片的TX引脚。这意味着Xbee模块可以直接与计算机通信--但是,只有当微控制器从Arduino板上被移除时,这才能工作。如果将微控制器留在Arduino板上,它将能够正常地通过USB与计算机对话,但计算机和微控制器都无法与Xbee模块对话。
如果XBee屏蔽有它的跳线在"USB“位置,以便您可以与X通信,您不能使用您运行的Arduino程序中的串行端口。
https://stackoverflow.com/questions/28283329
复制相似问题