Ultimate GPS shield can't run on more than 1hz with MEGA

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

Hmm. Weird.
But as long as you got it working with the flush, I'm happy.

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

not as happy as me ;)

Now I am looking for way to start/stop logging with push button with no much luck :(

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

Shouldn't be difficult. Do you know how to make a push button digital input work?

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

Yes, but can not figure out hot to start and stop logging /each start new file/

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

Try the attached. You will have to integrate it into your sketch, but get it working first before you start changing things. Try to understand how it works.

Code: Select all

#include <SPI.h>
#include <SD.h>

// Set the pins used
#define chipSelect 10

#define buttonPin 7
#define loggingLED 6

uint32_t buttonTimeout;
File logfile;
bool buttonEnabled;
bool loggingEnabled;

void setup()
{

  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(loggingLED, OUTPUT);

  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(53, OUTPUT); 

  // see if the card is present and can be initialized:
  //if (!SD.begin(chipSelect, 11, 12, 13)) {
  if (!SD.begin(chipSelect)) {      // Use hardware SPI
    Serial.println("Failed to initialize SD!");
  }

  loggingEnabled = OpenLogFile();
  buttonEnabled = true;
  digitalWrite(loggingLED, (loggingEnabled?HIGH:LOW));

  //GPS setup stuff goes here
}


void loop()
{
  if ((!buttonEnabled) && (buttonTimeout < millis())) {    //we disable the button for 5 seconds after toggling logging on or off
    buttonEnabled = true;
    Serial.println("button enabled");
  }

  if ((buttonEnabled) && (LOW == debounceRead(buttonPin)))  //if the button is enabled and the button has been pressed
  {
    if (loggingEnabled)    //if we're currently logging, stop logging
    {
      logfile.close();      //close the file
      loggingEnabled = false;
      Serial.println("logging disabled");
    }
    else        //we're not currently logging, so start logging
    {
      loggingEnabled = OpenLogFile();
      if (loggingEnabled)
        Serial.println("logging enabled");
    }

    digitalWrite(loggingLED, (loggingEnabled?HIGH:LOW));

    buttonEnabled = false;    //disable the button for 5 seconds
    buttonTimeout = millis() + 5000;
    Serial.println("button disabled");
  }

  // gps stuff goes here

  if (loggingEnabled)
  {
    //write data to log file 
  }
}



bool OpenLogFile()
{
  bool openedOK = false;
  char filename[15];
  strcpy(filename, "GPSLOG00.CSV");
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = '0' + i/10;
    filename[7] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }

  logfile = SD.open(filename, FILE_WRITE);
  if(logfile ) {
    Serial.print("Writing to ");     
    Serial.println(filename);
    openedOK = true;
  }
  else {
    Serial.print("Couldnt create ");     
    Serial.println(filename);
  }

  return openedOK;
}

//does a debounced read of an input pin
uint8_t debounceRead(int pin)
{
  uint8_t pinState = digitalRead(pin);
  uint32_t timeout = millis();
  while (millis() < timeout+10)
  {
    if (digitalRead(pin) != pinState)
    {
      pinState = digitalRead(pin);
      timeout = millis();
    }
  }

  return pinState;
}

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

Hi Rick,

Thanks for the help

I think I understand the code and implemented it in my scetch.

There are only one problem I can find.

if the board is restarted without SD card inserted it can not start logging with button press and card in

I moved

Code: Select all

if (!SD.begin(chipSelect)) {      // Use hardware SPI
        Serial.println("Failed to initialize SD!");
      }
from void setup() to bool OpenLogFile() and it works fine but it shows "Failed to initialize SD!" every time after the first time but the log file looks ok.

Is this the correct way to do it?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

Call SD.end() before you call SD.begin(chipSelect)

Code: Select all

 SD.end();
if (!SD.begin(chipSelect)) {      // Use hardware SPI
        Serial.println("Failed to initialize SD!");
      }
SD.end() is in the latest version of the Adafruit SD library

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

Hi Rick,

Thanks for the help


Is there a way to sence if th card is out and to set loggingEnabled to LOW in case the card was disconnected

thanks

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

There's the card detect signal. That's brought out to the 6-pin pad, and is labeled 'CD'. You can wire a jumper to an unused GPIO pin and detect when the card is inserted.

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

Thanks Rick,

I will try it.

now i have very strange problem - with my cketch all the analog inputs from A8 to A15 reads high even if they are unpugged. if pluged with any foltage it reads 5v and can not find out what takes them :(

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

When unplugged and floating, they will read around 2.5V (analogRead will return around 500). Are you saying that analogRead is returning 1023 all the time?

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

Yes, 1023 all the time but only with this scetch. I made separate scetch only to read the analog inputs and there everything is perfect

there is simple example:

Code: Select all

    // Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
    //
    // This code shows how to listen to the GPS module in an interrupt
    // which allows the program to have more 'freedom' - just parse
    // when a new NMEA sentence is available! Then access data when
    // desired.
    //
    // Tested and works great with the Adafruit Ultimate GPS module
    // using MTK33x9 chipset
    //    ------> http://www.adafruit.com/products/746
    // Pick one up today at the Adafruit electronics shop
    // and help support open source hardware & software! -ada

    #include <Adafruit_GPS.h>
    #include <SoftwareSerial.h>
    #include <SD.h>
    #include <SPI.h>
    #include <math.h>
    #include <Wire.h>
    #include <LSM303.h>
    #include <LiquidCrystal.h>
    #include <floatToString.h>

int sensorPin = A15;    // select the input pin for the potentiometer
int sensorValue = 0; 


    int zeroSixtyState = 0;
    boolean zeroSixtyDone = false;
    long timerBegin = 0;
    float time = 0.0;
    float maxspeed = 0.0;
    float maxspeedold = 0.0;

    LiquidCrystal lcd(3, 2, 4);

    uint8_t lcdLine = 0;
    uint8_t clock[8] = {
      0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
    uint8_t fix[8] = {
      0x0,0xe,0x11,0x15,0x11,0xe,0x0};
    uint8_t nofix[8] = {
      0x0,0x0,0x0,0x0,0x0,0x0,0x0};

    long blink_previousMillis = 0;
    long blink_interval = 500;
    int blink_state = 0;


    LSM303 compass;
    // these are my values, they most likely will not work for you
    // run the calibrate sketch from the LSM303 library to get your
    // maximum and minimum values for x, y, z
    int xRawMin = -16240;
    int xRawMax = 16000;
    int yRawMin = -17216;
    int yRawMax = 17250;
    int zRawMin = -14560;
    int zRawMax = 16481;
    //by increasing alphaAccel the response will become faster
    //but the noise will increae [alpha must be between 0 and 1]
    //values for digital lowpass
    float alphaAccel = 0.4;
    float alphaMagnet = 0.4;
    unsigned int xOffset=0;
    unsigned int yOffset=0;
    unsigned int zOffset=0;                     
    float Pitch=0;
    float Roll=0;
    float Yaw=0;
    int xRaw=0;
    int yRaw=0;
    int zRaw=0;
    float xFiltered=0;
    float yFiltered=0;
    float zFiltered=0;
    float xFilteredOld=0;
    float yFilteredOld=0;
    float zFilteredOld=0;
    float xAccel=0;
    float yAccel=0;
    float zAccel=0;


    // If you're using a GPS module:
    // Connect the GPS Power pin to 5V
    // Connect the GPS Ground pin to ground
    // If using software serial (sketch example default):
    //   Connect the GPS TX (transmit) pin to Digital 3
    //   Connect the GPS RX (receive) pin to Digital 2
    // If using hardware serial (e.g. Arduino Mega):
    //   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
    //   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

    // If you're using the Adafruit GPS shield, change
    // SoftwareSerial mySerial(3, 2); -> SoftwareSerial mySerial(8, 7);
    // and make sure the switch is set to SoftSerial

    // If using software serial, keep these lines enabled
    // (you can change the pin numbers to match your wiring):
    //SoftwareSerial mySerial(8, 7);

    #define mySerial Serial1

    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  false
    #define LOG_FIXONLY 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
    // Set the pins used
    #define chipSelect 10
    #define ledPin 13

    File logfile;

    // read a Hex value and return the decimal equivalent
    uint8_t parseHex(char c) {
      if (c < '0')
        return 0;
      if (c <= '9')
        return c - '0';
      if (c < 'A')
        return 0;
      if (c <= 'F')
        return (c - 'A')+10;
    }

    // blink out an error code
    void error(uint8_t errno) {
      /*
      if (SD.errorCode()) {
       putstring("SD error: ");
       //    Serial.print(card.errorCode(), HEX);
       //    Serial.print(',');
       //    Serial.println(card.errorData(), HEX);
       }
       */

      /* Show on display only is logging
       while(1) {
       uint8_t i;
       for (i=0; i<errno; i++) {
       digitalWrite(ledPin, HIGH);
       delay(100);
       digitalWrite(ledPin, LOW);
       delay(100);
       }
       for (i=errno; i<10; i++) {
       delay(200);
       }
       }
       */
    }

    void setup(){
      {
        lcd.begin(20, 4);
        lcd.createChar(0, clock);
        lcd.createChar(1, fix);
        lcd.createChar(2, nofix);

      }


      {
        Serial.begin(115200);       //initialize serial port
        analogReference(EXTERNAL);  //use external reference voltage (3,3V)
        delay(2000);  //calibrate sensor after a short delay
        Wire.begin();
        compass.init();
        compass.enableDefault();
        // getAccelOffset();           //keep it flat and non moving on the table
        //there are other ways to calibrate the offset, each has some advantes
        //and disadvantes..
        //compare application note AN3447
        //http://www.freescale.com/files/sensors/doc/app_note/AN3447.pdf
      }


      {

        // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
        // also spit it out
        Serial.begin(115200);
        Serial.println("Adafruit GPS library basic test!");
        pinMode(ledPin, OUTPUT);

        // make sure that the default chip select pin is set to
        // output, even if you don't use it:
        pinMode(53, OUTPUT);

        // see if the card is present and can be initialized:
        //if (!SD.begin(chipSelect, 11, 12, 13)) {
        if (!SD.begin(chipSelect)) {      // Use hardware SPI

          error(2);
        }
        char filename[15];
        strcpy(filename, "GPSLOG00.CSV");
        for (uint8_t i = 0; i < 100; i++) {
          filename[6] = '0' + i/10;
          filename[7] = '0' + i%10;
          // create if does not exist, do not open existing, write, sync after write
          if (! SD.exists(filename)) {
            break;
          }
        }

        logfile = SD.open(filename, FILE_WRITE);
        if( ! logfile ) {
          //    Serial.print("Couldnt create "); //    Serial.println(filename);
          error(3);
        }
        Serial.print("Writing to ");     
        Serial.println(filename);

        logfile.println("Time,Date,Latitude,Longitude, Elevation,Speed (MPH), Angle,Sat,G x,G y,G z,Total G's,Pitch,Roll,Heading,Compass");
        logfile.flush();
      }

      // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
      GPS.begin(19200);
      //      GPS.sendCommand("$PMTK251,38400*27");  //set baud rate to 19200
      //    //  GPS.sendCommand("$PMTK251,9600*17");  //set baud rate to 9600
      //      mySerial.end();
      //      GPS.begin(38400);

      // 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
      //   GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
      // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
      // the parser doesn't care about other sentences at this time

      // Set the update rate
      GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
      // For the parsing code to work nicely and have time to sort thru the data, and
      // print it out we don't suggest using anything higher than 1 Hz

      // Request updates on antenna status, comment out to keep quiet
      GPS.sendCommand(PGCMD_NOANTENNA);

      lcd.setCursor(0, 0);
      lcd.print("S");

      lcd.setCursor(13, 0);
      lcd.print("C");

      lcd.setCursor(0, 1);
      lcd.print("A");

      lcd.setCursor(13, 1);
      lcd.print("P");

      lcd.setCursor(0, 2);
      lcd.print("H");

      lcd.setCursor(13, 2);
      lcd.print("R");

      lcd.setCursor(0, 3);
      lcd.print("S");

      lcd.setCursor(13, 3);
      lcd.print("G");


      // the nice thing about this code is you can have a timer0 interrupt go off
      // every 1 millisecond, and read data from the GPS for you. that makes the
      // loop code a heck of a lot easier!
      useInterrupt(true);

      // delay(1000);
      // Ask for firmware version
      // GPS.sendCommand(PMTK_Q_RELEASE);
    }


    // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
    SIGNAL(TIMER0_COMPA_vect) {
      char c;

      while (mySerial.available())
      {
        c = GPS.read();
        // if you want to debug, this is a good time to do it!
        if (GPSECHO)
    #ifdef UDR0
          if (c) UDR0 = c;
        // writing direct to UDR0 is much much faster than Serial.print
        // but only one character can be written at a time.
    #else
        if (c) Serial.write(c);
    #endif
      }
    }

    void useInterrupt(boolean v) {
      if (v) {
        // Timer0 is already used for millis() - we'll just interrupt somewhere
        // in the middle and call the "Compare A" function above
        OCR0A = 0xAF;
        TIMSK0 |= _BV(OCIE0A);
        usingInterrupt = true;
      }
      else {
        // do not call the interrupt function COMPA anymore
        TIMSK0 &= ~_BV(OCIE0A);
        usingInterrupt = false;
      }
    }

    uint32_t timer = millis();


    void FilterAD()
    {
      // read from AD and subtract the offset
      xRaw=compass.a.x-xOffset;
      yRaw=compass.a.y-yOffset;
      zRaw=compass.a.z-zOffset;
      //Digital Low Pass - compare: (for accelerometer)
      //http://en.wikipedia.org/wiki/Low-pass_filter
      xFiltered= xFilteredOld + alphaAccel * (xRaw - xFilteredOld);
      yFiltered= yFilteredOld + alphaAccel * (yRaw - yFilteredOld);
      zFiltered= zFilteredOld + alphaAccel * (zRaw - zFilteredOld);
      xFilteredOld = xFiltered;
      yFilteredOld = yFiltered;
      zFilteredOld = zFiltered;   
    }


    void AD2Degree()
    {
      // 3.3 = Vref; 1023 = 10Bit AD; 0.8 = Sensivity Accelerometer
      // (compare datasheet of your accelerometer)
      // the *Accel must be between -1 and 1; you may have to
      // to add/subtract +1 depending on the orientation of the accelerometer
      // (like me on the zAccel)
      // they are not necessary, but are useful for debugging
      xAccel=xFiltered *3.3 / (1023.0*0.8);     
      yAccel=yFiltered *3.3 / (1023.0*0.8);     
      zAccel=zFiltered *3.3 / (1023.0*0.8)+1.0;

      // Calculate Pitch and Roll (compare Application Note AN3461 from Freescale
      // http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf
      // Microsoft Excel switches the values for atan2
      // -> this info can make your life easier :-D
      //angled are radian, for degree (* 180/3.14159)
      Roll   = atan2(  yAccel ,  sqrt(sq(xAccel)+sq(zAccel)));
      Pitch  = atan2(  xAccel ,   sqrt(sq(yAccel)+sq(zAccel))); 
    }

    String degToCardinal(int header)
    {

      if (header > 337.5)
        return "N";
      if (header > 292.5)
        return "NW";
      if (header > 247.5)
        return "W";
      if (header > 202.5)
        return "SW";
      if (header > 157.5)
        return "S";
      if (header > 112.5)
        return "SE";
      if (header > 67.5)
        return "E";
      if (header > 22.5)
        return "NE";
      if (header >= 0)
        return "N";
      return "?"; //If, somehow, we didn't find a valid heading (less than zero, perhaps)

    }

    void loop()   {                  // run over and over again
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
      int test= millis();

      compass.read();
      FilterAD();
      AD2Degree();
      long xRaw = compass.a.x;
      long yRaw = compass.a.y;
      long zRaw = compass.a.z;
      int mx = compass.m.x;
      int my = compass.m.y;

      // Convert raw values to 'milli-Gs"
      long xScaled = map(xRaw, xRawMin, xRawMax, -1000, 1000);
      long yScaled = map(yRaw, yRawMin, yRawMax, -1000, 1000);
      long zScaled = map(zRaw, zRawMin, zRawMax, -1000, 1000);

      // re-scale to fractional Gs
      float xAccel = xScaled / 1000.0;
      float yAccel = yScaled / 1000.0;
      float zAccel = zScaled / 1000.0;

      float Pi = 3.14159;
      float heading = (atan2(my,mx) * 180) / Pi;
      // Normalize to 0-360
      if (heading < 0)
      {
        heading = 360 + heading;
      }




      float totalG = (sqrt(sq(xAccel)+sq(yAccel)+sq(zAccel)));





      {
        // in case you are not using the interrupt above, you'll
        // need to 'hand query' the GPS, not suggested :(
        if (! usingInterrupt) {
          // read data from the GPS in the 'main loop'
          while (mySerial.available())
          {
            char c = GPS.read();
            // if you want to debug, this is a good time to do it!
            if (GPSECHO)
              if (c) Serial.write(c);
          }
        }

        // if a sentence is received, we can check the checksum, parse it...
        if (GPS.newNMEAreceived()) {
          // a tricky thing here is if we print the NMEA sentence, or data
          // we end up not listening and catching other sentences!
          // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
          //        Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

          if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
            return;  // we can fail to parse a sentence in which case we should just wait for another

          if (strstr(GPS.lastNMEA(), "RMC"))      //if we just got an RMC string
          {
            compass.read();
            FilterAD();
            AD2Degree();
            long xRaw = compass.a.x;
            long yRaw = compass.a.y;
            long zRaw = compass.a.z;
            int mx = compass.m.x;
            int my = compass.m.y;

            // Convert raw values to 'milli-Gs"
            long xScaled = map(xRaw, xRawMin, xRawMax, -1000, 1000);
            long yScaled = map(yRaw, yRawMin, yRawMax, -1000, 1000);
            long zScaled = map(zRaw, zRawMin, zRawMax, -1000, 1000);

            // re-scale to fractional Gs
            float xAccel = xScaled / 1000.0;
            float yAccel = yScaled / 1000.0;
            float zAccel = zScaled / 1000.0;

            float Pi = 3.14159;
            float heading = (atan2(my,mx) * 180) / Pi;
            // Normalize to 0-360
            if (heading < 0)
            {
              heading = 360 + heading;
            }




            float totalG = (sqrt(sq(xAccel)+sq(yAccel)+sq(zAccel)));




            //       Serial.println(GPS.parse(GPS.lastNMEA())); //debug////////////
            if(zeroSixtyState == 0){//stop state
              //digitalWrite(3, HIGH);
              if((GPS.speed*1.15078) >= 1){
                timerBegin = millis();
                //delay(5000);
                zeroSixtyState = 2;
              }
            }
            else if(zeroSixtyState == 3){
              zeroSixtyState = 1;
            }

            else if(zeroSixtyState == 2){//wait for the speed to reach 60
              //digitalWrite(4, HIGH);
              if((GPS.speed*1.15078) >= 20){
                long timerEnd = millis();
                time = (timerEnd-timerBegin);
                zeroSixtyState = 3;
              }
            }

            //      // if millis() or timer wraps around, we'll just reset it
            //      if (timer > millis())  timer = millis();
            //
            //      // approximately every 2 seconds or so, print out the current stats
            //      if (millis() - timer > 5) {
            //        timer = millis(); // reset the timer
            //      } 
            // Rad. lets log it!
            //    Serial.println("Log");








            logfile.print(GPS.hour, DEC);
            logfile.print(':');
            logfile.print(GPS.minute, DEC);
            logfile.print(':');
            logfile.print(GPS.seconds, DEC);
            logfile.print('.');
            logfile.print(GPS.milliseconds);
            logfile.print(",");

            logfile.print(GPS.month, DEC);
            logfile.print('/');
            logfile.print(GPS.day, DEC);
            logfile.print("/20");
            logfile.print(GPS.year, DEC);
            logfile.print(",");

            logfile.print(GPS.latitude, 4);
            logfile.print(GPS.lat);
            logfile.print(",");
            logfile.print(GPS.longitude, 4);
            logfile.print(GPS.lon);
            logfile.print(",");
            logfile.print(GPS.altitude);
            logfile.print(",");
            logfile.print(GPS.speed*1.15078);
            logfile.print(",");
            logfile.print(GPS.angle, 0);
            logfile.print(",");
            logfile.print((int)GPS.satellites);
            logfile.print(",");
            //        logfile.print(xAccel);
            //        logfile.print("G");
            //        logfile.print(",");
            //        logfile.print(yAccel);
            //        logfile.print("G");
            //        logfile.print(",");
            //        logfile.print(zAccel);
            //        logfile.print("G");
            //        logfile.print(",");
            //        logfile.print(totalG);
            //        logfile.print("G");
            //        logfile.print(",");
            //        logfile.print(int(Pitch*180/PI));
            //        logfile.print(",");
            //        logfile.print(int(Roll*180/PI));
            //        logfile.print(",");
            ////        logfile.print((int)heading);
            //        logfile.print(",");
            logfile.println( degToCardinal(GPS.angle) );
            logfile.flush();



            //            Serial.print(GPS.hour, DEC);
            //            Serial.print(':');
            //            Serial.print(GPS.minute, DEC);
            //            Serial.print(':');
            //            Serial.print(GPS.seconds, DEC);
            //            Serial.print('.');
            //            Serial.print(GPS.milliseconds);
            //            Serial.print(",");
            //       
            //            Serial.print(GPS.month, DEC);
            //            Serial.print('/');
            //            Serial.print(GPS.day, DEC);
            //            Serial.print("/20");
            //            Serial.print(GPS.year, DEC);
            //            Serial.print(",");
            //       
            //            Serial.print(GPS.latitude, 4);
            //            Serial.print(GPS.lat);
            //            Serial.print(",");
            //            Serial.print(GPS.longitude, 4);
            //            Serial.print(GPS.lon);
            //            Serial.print(",");
            //            Serial.print(GPS.altitude);
            //            Serial.print(",");
            //            Serial.print(GPS.speed*1.15078);
            //            Serial.print(",");
            //            Serial.print(GPS.angle, 0);
            //            Serial.print(",");
            //            Serial.print(GPS.satellites);
            //            Serial.print(",");
            //            Serial.print(xAccel);
            //            Serial.print("G,");
            //            Serial.print(yAccel);
            //            Serial.print("G,");
            //            Serial.print(zAccel);
            //            Serial.print("G");
            //            Serial.print(",");
            //            Serial.print(totalG);
            //            Serial.print("G");
            //            Serial.print(",");
            //        //      Serial.print("Pitch: ");
            //          Serial.print(int(Pitch*180/PI));
            //              Serial.print(",");
            //        //  Serial.print(" Roll: ");
            //          Serial.print(int(Roll*180/PI));
            //              Serial.print(",");
            //            Serial.print((int)heading);
            //            Serial.print(",");
            //            Serial.println( degToCardinal(heading) );



            maxspeedold = maxspeed;

            int flag;

            if (maxspeedold < maxspeed) {

              flag = '1';
            }
            else {
              flag = '0';
            }

            if (maxspeed < (GPS.speed*1.15078))
            {
              maxspeed = (GPS.speed*1.15078);
            }


            //FLOAT TO STRING CONVERTION

            //SPEED
            float spd = (GPS.speed*1.15078);
            char cspd[6];

            dtostrf(spd, 5, 1, cspd);

            String s;
            s = String(cspd);

            //MAX SPEED     
            // float mspd = (maxspeed);
            char cmspd[6];

            dtostrf(maxspeed, 5, 1, cmspd);

            String ms;
            ms = String(cmspd);

            // ALTITUDE       
            float alt = (GPS.altitude);
            char calt[6];

            dtostrf(alt, 5, 0, calt);

            String a;
            a = String(calt);

            //   PITCH

            float pitch = ((Pitch*180/PI));
            char cpitch[6];

            dtostrf(pitch, 3, 0, cpitch);

            String p;
            p = String(cpitch);

            //   HEADING

            float head = (GPS.angle);
            char chead[6];

            dtostrf(head, 5, 0, chead);

            String h;
            h = String(chead);

            //   ROLL

            float roll = ((Roll*180/PI));
            char croll[6];

            dtostrf(roll, 3, 0, croll);

            String r;
            r = String(croll);

            //   SAT #

            float sat = (GPS.satellites);
            char csat[6];

            dtostrf(sat, 5, 0, csat);

            String st;
            st = String(csat);

            //   TOTAL G #

            float tg = (totalG);
            char ctg[6];

            dtostrf(tg, 4, 1, ctg);

            String tgs;
            tgs = String(ctg);       



            //int c = (degToCardinal(heading))
            String comp;
            comp = String(degToCardinal(GPS.angle));

            while (comp.length() < 2){

              comp=" "+comp;
            }


            switch (lcdLine) {
            case 0:
              lcd.setCursor(1, 0);
              lcd.print(s);//Serial.println(GPS.speed*1.15078);

              if (flag = 1) {

                lcd.setCursor(7, 1);
                lcd.print(ms);



              }
              //          else {
              //            }
              lcd.setCursor(15, 0);
              lcd.print(comp);



              //LOCK ICON

              if (LOG_FIXONLY && !GPS.fix) {
                unsigned long blink_currentMillis = millis();
                if(blink_currentMillis - blink_previousMillis > blink_interval){
                  blink_previousMillis = blink_currentMillis; 
                  if (blink_state == 0){
                    blink_state = 1;
                  }
                  else{
                    blink_state = 0;
                  }

                }
                if (blink_state == 0){                                   
                  lcd.setCursor(19, 0);
                  lcd.write(2);
                }
                else{
                  lcd.setCursor(19, 0);
                  lcd.write(1);
                }
              }
              else {
                lcd.setCursor(19, 0);
                lcd.write(1);
              }
              break;

            case 1:
              lcd.setCursor(1, 1);
              lcd.print(a); //Serial.println(GPS.altitude);
              lcd.setCursor(14, 1);
              lcd.print(p);

              break;

            case 2:
              lcd.setCursor(1, 2);
              lcd.print(h); //Serial.println(GPS.angle, 0);
              lcd.setCursor(14, 2);
              lcd.print(r);

              if (zeroSixtyState == 3){
                lcd.setCursor(8, 2);
                lcd.print(time/1000);
              }

              break;

            case 3:
              lcd.setCursor(1, 3);
              lcd.print(st); //Serial.println((int)GPS.satellites);
              lcd.setCursor(15, 3);
              lcd.print(tgs);
              break;


            default:
              break;

            }
            lcdLine++;
            lcdLine &= 3;  //increment lcdLine, but keep in range 0..3

              Serial.println(millis()-test);
          }
        }
      }
    }

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

Code: Select all

        analogReference(EXTERNAL);  //use external reference voltage (3,3V)
Do you have the external AREF connected?

thegunman
 
Posts: 54
Joined: Mon Jun 09, 2014 7:43 pm

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by thegunman »

No

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS shield can't run on more than 1hz with MEGA

Post by adafruit_support_rick »

You have to run 3.3V to the AREF pin. It's just up from Digital 13.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”