Hello,
I'm using an arduino Fio, an Altimu 10, an Adafruit ultimate GPS, a Adafruit micro Sd breakout and a Xbee S2B to locally log gps, atmospheric and inertial data, as well as sending it wirelessly.
Currently I have a problem with the GPS NMEA sentences, since while reading the GGA sentence it often cuts off the end (ie. $GPGGA,172841.600,3842.2050,N,00914.7984,W,2,08,1.20,97.7,M,50.).
the code i'm using is
#include <Wire.h>
#include <LSM303.h>
#include <LPS.h>
#include <L3G.h>
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
L3G gyro;
LSM303 compass;
LPS ps;
#include <SoftwareSerial.h>
#include <Adafruit_GPS.h>
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO true
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
int byteGPS=-1;
String inputString = ""; // a string to hold incoming data
String dataString = "";
boolean stringComplete = false;
void setup()
{
Serial.begin(57600);
Wire.begin();
compass.init();
compass.enableDefault();
Wire.beginTransmission(0x3C >> 1);
Wire.write(0x01);
// see table 62 in the datasheet for other gain_setting values
Wire.write(0x60);
Wire.endTransmission();
// Calibration values. Use the Calibrate example program to get the values for
// your compass.
compass.m_min.x = -256; compass.m_min.y = -172; compass.m_min.z = -236;
compass.m_max.x = +104; compass.m_max.y = +181; compass.m_max.z = +133;
// connect at 115200 so we can read the GPS fast enuf and
// also spit it out
// 9600 NMEA is the default baud rate for MTK - some use 4800
GPS.begin(9600);
// You can adjust which sentences to have the module emit, below
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
// GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data for high update rates!
GPS.sendCommand("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
// uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
// GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
// Set the update rate
// 1 Hz update rate
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
// 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
GPS.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);
// 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
if (!gyro.init())
{
Serial.println("Fg");
while (1);
}
gyro.enableDefault();
Serial.print("I");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("f");
// don't do anything more:
return;
}
Serial.println("i");
inputString.reserve(250);
dataString.reserve(300);
}
void loop() // run over and over again
{
mySerial.listen();
while (mySerial.available()) {
// get the new byte:
char inChar = (char)mySerial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
// if (inChar == '\n') {
//
// File myFile = SD.open("datalog.txt", FILE_WRITE);
// myFile.print(inputString);
// myFile.close();
//
// Serial.print(inputString);
// inputString = "";
//
// }
}
File myFile = SD.open("datalog.txt", FILE_WRITE);
myFile.println(inputString);
myFile.close();
Serial.println(inputString);
inputString = "";
//Serial.print((char)mySerial.read()); //copy data to console
//myFile.print((char)mySerial.read());
// while (Serial.available()) { //while data available from console
// mySerial.print((char)Serial.read()); //copy data to GPS
// }
dataString = "";
float pressure = ps.readPressureMillibars();
float altitude = ps.pressureToAltitudeMeters(pressure);
float temperature = ps.readTemperatureC();
compass.read();
gyro.read();
Serial.print("p");
Serial.print(pressure);
Serial.print(",");
Serial.print(altitude);
Serial.print(",");
Serial.println(temperature);
myFile = SD.open("datalog.txt", FILE_WRITE);
myFile.print("p");
myFile.print(pressure);
myFile.print(",");
myFile.print(altitude);
myFile.print(",");
myFile.println(temperature);
myFile.close();
//
//
//
// Serial.print("A");
// Serial.print(compass.a.x);
// Serial.print(",");
// Serial.print(compass.a.y);
// Serial.print(",");
// Serial.println(compass.a.x);
//
// Serial.print("M");
// Serial.print(compass.m.x);
// Serial.print(",");
// Serial.print(compass.m.y);
// Serial.print(",");
// Serial.println(compass.m.z);
//
//
// myFile.print("A");
// myFile.print(compass.a.x);
// myFile.print(",");
// myFile.print(compass.a.y);
// myFile.print(",");
// myFile.println(compass.a.x);
//
// myFile.print("M");
// myFile.print(compass.m.x);
// myFile.print(",");
// myFile.print(compass.m.y);
// myFile.print(",");
// myFile.println(compass.m.z);
//
//
//
// Serial.print("G ");
// Serial.print("X: ");
// Serial.print((int)gyro.g.x);
// Serial.print(" Y: ");
// Serial.print((int)gyro.g.y);
// Serial.print(" Z: ");
// Serial.println((int)gyro.g.z);
//
// Serial.println('\n');
}
Currently a lot a code is commented out since I've been trying several ways of reading the NMEA sentences and also trying to optimize the logging of the other sensors.
Any input would be much appreciated, thanks in advance!