Create a gist now

Instantly share code, notes, and snippets.

MultiNav FeatherWing Example Program for Feather HUZZAH
// Example Program for MultiNav FeatherWing
// This example is specifically for use with Adafruit Feather HUZZAH (ESP8266)
//
// 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.
// Additionally, the EspSoftSerial library is used to communicate with the U-Blox.
// TinyGPS++ Download: http://arduiniana.org/libraries/tinygpsplus/
// Sparkfun MPU-6050 Download: https://github.com/sparkfun/MPU-9150_Breakout/tree/master/firmware
// EspSoftSerial: https://github.com/scottwday/EspSoftSerial
// Credit is given to Arduiniana, Sparkfun and scottwday 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"
#include <CircularBuffer.h>
#include <EspSoftSerialRx.h>
// *************************** NOTE *************************** //
// You must go into the library folder (Arduino - libraries - MPU6050), open MPU6050.h,
// and edit the line "#include <avr/pgmspace.h>" to read "#include <pgmspace.h>"
// This is a fix required for ESP8266 modules using this library.
// *************************** NOTE *************************** //
// Pinout:
// * I2C: SDA and SCL pins in the same location on all Feather boards.
// * UART: For HUZZAH, connect Option A on JP3 and use SoftwareSerial (#13 Rx, #15 Tx)
// * Interrupts: The 9DOF and GPS PPS interrupt signals are not usable on the HUZZAH.
// The pins are not usable with attachInterrupt(), and connecting JP1
// or JP2 will interfere with bootloading. Leave them disconnected.
// These are the I/O defines for Feather HUZZAH
#define mpu9250intPin 2
#define ledPin 14
#define rxPin 13
volatile bool periodic = false;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
TinyGPSPlus gps;
EspSoftSerialRx SerialGPS;
MPU6050 accelgyro;
void setup()
{
Serial.begin(9600);
SerialGPS.begin(9600, rxPin); // Library is currently Rx only
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 arrive from the GPS once per second
// When TinyGPS gets fresh data, print out some example strings and 9DOF data
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
unsigned char b;
while(SerialGPS.read(b))
{
gps.encode(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment