Skip to content

Instantly share code, notes, and snippets.

@SyncChannel
Created January 27, 2016 03:17
Show Gist options
  • Save SyncChannel/4afffa2586612d11d1c8 to your computer and use it in GitHub Desktop.
Save SyncChannel/4afffa2586612d11d1c8 to your computer and use it in GitHub Desktop.
MultiNav FeatherWing Example Program for Feather 32U4
// Example Program for MultiNav FeatherWing
// For Adafruit Feather 32U4
//
// By: Dan Watson
// syncchannel.blogspot.com
// 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: http://arduiniana.org/libraries/tinygpsplus/
// Sparkfun MPU-6050 Download: https://github.com/sparkfun/MPU-9150_Breakout/tree/master/firmware
// Credit is given to both Arduiniana and Sparkfun for the use of their excellent libraries, and portions
// of their example programs. Thank you!
// The built-in SoftwareSerial library is also used.
#include <TinyGPS++.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "SoftwareSerial.h"
// Pinout:
// * I2C: SDA and SCL pins in the same location on all Feather boards.
// * UART: For 32U4, connect Option A on JP3 and use SoftwareSerial (D11 Rx, D10 Tx)
// * Interrupts:
// MPU-9250 goes to D5. Connect JP1 to use.
// GPS Pulse-per-second goes to D6. Connect JP2 to use.
// HOWEVER, neither pin is usable as a hardware interrupt on 32U4
// You could check their levels with a while() loop if you really need
// to, but that is not a true interrupt.
// These are the I/O defines for Feather 32U4
#define ledPin 13
#define rxPin 11
#define txPin 10
volatile bool periodic = false;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
TinyGPSPlus gps;
SoftwareSerial SerialGPS(rxPin, txPin);
MPU6050 accelgyro;
void setup()
{
Serial.begin(9600);
SerialGPS.begin(9600);
Serial.println("MultiNav FeatherWing Test Program!");
Serial.println("Ensure a GPS antenna is connected and has a clear view of the sky");
Serial.println("");
Wire.begin();
Serial.println("Initializing I2C for MPIU-9250");
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
Serial.println("");
pinMode(ledPin, OUTPUT);
}
void loop()
{
// 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())
{
// Update 9DOF data
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
char buffer[24];
sprintf(buffer, "UTC: %02d/%02d/%04d %02d:%02d:%02d", gps.date.month(), gps.date.day(),
gps.date.year(), gps.time.hour(), gps.time.minute(), gps.time.second());
for (int i = 0; i < sizeof(buffer); i++)
{
Serial.print(buffer[i]);
}
Serial.println("");
} else {
Serial.println("UTC Error: Time Not Valid");
}
if (gps.location.isValid())
{
Serial.print("Lat ");
Serial.print(gps.location.lat(), 6);
Serial.print(", Lng ");
Serial.println(gps.location.lng(), 6);
Serial.print("Altitude ");
Serial.print(gps.altitude.meters());
Serial.println("m");
} else {
Serial.println("Position Error: Not Valid");
}
if (gps.satellites.isValid())
{
Serial.print("SVs In Use: ");
Serial.println(gps.satellites.value());
}
if (gps.hdop.isValid())
{
Serial.print("HDOP: ");
Serial.println((float) gps.hdop.value() / 100);
}
Serial.print("a/g/m:\t");
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");
Serial.println(mz);
Serial.println("");
}
// Ingest new serial strings from the GPS into TinyGPS as they arrive
while(SerialGPS.available() > 0)
{
gps.encode(SerialGPS.read());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment