Tuesday 27 August 2013

FTDI Board? We don't need no stinking FTDI board!

Connecting to GPS receivers to test, configure and log data seems to be a daily thing this month.  The way we have been doing it is to connect from the computer USB to the UART on the GPS using the handy Sparkfun FTDI breakout board.  


For example, we can connect to the uBlox LEA-6H using the uCenter software to set the configuration, following these instructions.

But the goal is to get the GPS working with the APM, which has plenty of UARTs.  So, how about we just talk directly to the GPS using the APM?  Easy:
1)  Install the patched version of the Arduino development environment, following the instructions here.
2)  Connect to the APM via USB.
3)  Open the Arduino IDE and enter the following code:
/*
  Mega multple serial test
  Receives from the main serial port, sends to the others. 
 Receives from serial port 1, sends to the main serial (Serial 0).
  This example works only on the Arduino Mega
  The circuit: 
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:
  created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach
  This example code is in the public domain.
  */
void setup() {
  // initialize both serial ports:
  Serial.begin(38400);
  Serial1.begin(38400);
}
void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte); 
  }
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte); 
  }
}
Note the baud rates are set to 38.4K, which is the standard for the uBlox connection to the APM.
4)  Click the 'Upload' button to compile the code and run it on the APM
5)  Now open uCenter and connect to the appropriate COM port at 38.4K baud.
6)  Do your GPS configurating.

Note that you will need to reinstall the firmware on the APM using Mission Planner when you are done.