Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Input 从Arduino的输入引脚读取串行数据_Input_Arduino_Xbee - Fatal编程技术网

Input 从Arduino的输入引脚读取串行数据

Input 从Arduino的输入引脚读取串行数据,input,arduino,xbee,Input,Arduino,Xbee,我有来自Xbee的GPS串行信号。我用示波器检查,信号存在。 我的问题: 我怎么能用arduino读取串行信号呢?我想我应该把它输入一个输入引脚 然后将其打印到串行监视器。 谢谢我找到了读取发送到RX的GPS信号的解决方案。 它在阿尔杜伊诺 示例->通信->串行事件 String inputString = ""; // a string to hold incoming data boolean stringComplete = false; // whether the s

我有来自Xbee的GPS串行信号。我用示波器检查,信号存在。 我的问题:

我怎么能用arduino读取串行信号呢?我想我应该把它输入一个输入引脚

然后将其打印到串行监视器。
谢谢

我找到了读取发送到RX的GPS信号的解决方案。 它在阿尔杜伊诺 示例->通信->串行事件

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}
现在,将具有串行信号的导线连接到RX引脚0,然后运行串行监视器,您将看到如下内容:

$GPGLL,5652.36437,N,08901.52702,W,225356.00,A,D*73
$GPGSV,4,1,15,07,42,306,33,08,16,110,33,09,53,253,37,10,05,281,23*72
$GPRMC,225357.00,A,5652.36445,N,08901.52698,W,0.145,,180315,,,D*62