Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
MultiNav FeatherWing Example Program for Feather M0
// Example Program for MultiNav FeatherWing
// For Adafruit Feather M0
// By: Dan Watson
// 1/25/2016
// This program makes use of the TinyGPS++ library to receive the GPS data from the U-Blox
// module, as well as the Sparkfun MPU-6050 library to interact with the MPU-9250 9DOF.
// TinyGPS++ Download:
// Sparkfun MPU-6050 Download:
// Credit is given to both Arduiniana and Sparkfun for the use of their excellent libraries, and portions
// of their example programs. Thank you!
#include <TinyGPS++.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
// Pinout:
// * I2C: SDA and SCL pins in the same location on all Feather boards.
// * UART: For M0, connect Option B on JP3, and use SERCOM1
// * Interrupts: This board has two possible interrupt signals:
// MPU-9250 goes to D5. Connect JP1 to use.
// GPS Pulse-per-second goes to D6. Connect JP2 to use.
// These are the I/O defines for Feather M0
#define ppsPin 6
#define mpu9250intPin 5
#define ledPin 13
// These are the defines for using SERCOM1 on Feather M0 to communicate with U-Blox GPS
#define PIN_SerialGPS_RX (34ul)
#define PIN_SerialGPS_TX (36ul)
#define PAD_SerialGPS_TX (UART_TX_PAD_2)
#define PAD_SerialGPS_RX (SERCOM_RX_PAD_3)
volatile bool periodic = false;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
TinyGPSPlus gps;
MPU6050 accelgyro;
// Using SERCOM1 on M0 to communicate with U-Blox GPS
Uart SerialGPS(&sercom1, PIN_SerialGPS_RX, PIN_SerialGPS_TX, PAD_SerialGPS_RX, PAD_SerialGPS_TX);
void setup()
Serial.println("MultiNav FeatherWing Test Program!");
Serial.println("Ensure a GPS antenna is connected and has a clear view of the sky");
Serial.println("Initializing I2C for MPIU-9250");
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
pinMode(ppsPin, INPUT);
pinMode(mpu9250intPin, INPUT);
pinMode(ledPin, OUTPUT);
// Attach interrupt for GPS PPS. Will be used to update accel data and blink the LED.
attachInterrupt(ppsPin, ppsHandler, RISING);
// Needed for Feather M0. Leave this line between setup() and loop().
// Comment this out when using 32U4 or HUZZAH
#define Serial SerialUSB
void loop()
// Put things in this statement that you want to occur once per second
// It is triggered by the GPS Pulse-per-second interrupt, so it is aligned
// to the beginning of the UTC second precisely!
if (periodic)
periodic = false;
digitalWrite(ledPin, HIGH);
// Let's use this to get updated data from the 9DOF
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
digitalWrite(ledPin, LOW);
// Data strings also arrive from the GPS once per second
// When TinyGPS gets fresh data, print out some example strings
if (gps.time.isUpdated())
if (gps.time.isValid())
char buffer[24];
sprintf(buffer, "UTC: %02d/%02d/%04d %02d:%02d:%02d",,,, gps.time.hour(), gps.time.minute(), gps.time.second());
for (int i = 0; i < sizeof(buffer); i++)
} else {
Serial.println("UTC Error: Time Not Valid");
if (gps.location.isValid())
Serial.print("Lat ");
Serial.print(, 6);
Serial.print(", Lng ");
Serial.println(gps.location.lng(), 6);
Serial.print("Altitude ");
} else {
Serial.println("Position Error: Not Valid");
if (gps.satellites.isValid())
Serial.print("SVs In Use: ");
if (gps.hdop.isValid())
Serial.print("HDOP: ");
Serial.println((float) gps.hdop.value() / 100);
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.print(gz); Serial.print("\t");
Serial.print(mx); Serial.print("\t");
Serial.print(my); Serial.print("\t");
// Ingest new serial strings from the GPS into TinyGPS as they arrive
while(SerialGPS.available() > 0)
// This handler is triggered by the GPS Pulse-per-second.
// Use it to perform actions that are precisely aligned to the UTC second!
void ppsHandler()
periodic = true;
// IRQ handler needed for SERCOM 1 on M0
void SERCOM1_Handler()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment