SerialAPIOn-robot APISerial ExamplesExample Arduino GPS Checker

Example Arduino GPS Checker

Overview

This script is designed to run on an Arduino device and get the current GPS location in a loop. This script communicates over the DN/DP data port, that is also used to power the board through the USB connection.

Functions

  • Communicates over the USB connection for easy set-up

  • Handshake in an Arduino environment

  • Gets current GPS location

Example

void setup() {

  // start serial port at 115200 bps:
  // Serial is for communicating through the power/data usb port on the board
  // Serial1 is for communicating through the tx/rx pins

  Serial.begin(115200, SERIAL_8N1);
  // Serial1.begin(115200, SERIAL_8N1);

  while (!Serial) {

    ; // wait for serial port to connect. Needed for native USB port only

  }

  // send HLWD to establish contact until receiver responds
  establishContact();
}

void loop() {

  // if we get a valid byte, read analog ins:

  if (Serial.available() > 0) {

    // Publish an RGPS query to request the current GPS location
    Serial.print("?RGPS_\r");
    Serial.flush();

    delay(300);

    String response = Serial.readStringUntil('\r');
    // Do whatever you want with the response here.
  }
}

void establishContact() {

  while (Serial.available() <= 0) {

    // Send a HLWD_ as a handshake
    Serial.println("@HLWD_\r");
    Serial.flush();

    // Delay a little to give time for a response to arrive
    delay(900);

    // Read a response
    String response = Serial.readStringUntil('\r');

    // If the response is an ACK then the handshake is returned, break to the main loop
    if (response.equals("#ACK_"))
    {
      Serial.println("Hello World!");
      Serial.flush();
      break;
    }
  }
}