cannot dump ultimate log with my own code

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jferguson
 
Posts: 37
Joined: Mon Aug 20, 2012 2:29 pm

cannot dump ultimate log with my own code

Post by jferguson »

Utlimate (MT3339) GPS running with FEATHER Proto MO. GPS output fine. I'm using the GGA NMEA sentence

Logging start, stop, and flash erase work fine in my code, but not dump.

LOCUS_DUMP_BASIC also works perfectly, but I cannot make it work in my own sketch. I'm using Arduino IDE 1.8.9 and C+(whatever) .
I''m using a SHARP E-INK display and an encoder to select function desired from menu.

Here are two of menu selections including the dump one:

Code: Select all

[  if (pos1 == 2) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("STOP LOG");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      GPS.sendCommand(PMTK_LOCUS_STOPLOG);
      display.clearDisplay();
      display.println(" LOG STOPPED");
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1;
     }
     display.refresh();
    }
    if (pos1 == 3) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("DUMP LOG");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
      dumplog();
      display.clearDisplay();
      display.println(" LOG DUMPED");
      GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_GGAONLY);
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1;
      }
    display.refresh();
}
  
    code]

and here is the dumplog function: [code]    void dumplog(){
  
    GPS.sendCommand("$PMTK622,1*29");
    
   uint32_t updateTime = 1000; 
   
    while (GPSSerial.available()) {
    char c = GPSSerial.read();
    Serial.write(c);
  } 
} 
 [ /code]

This dumps about half of each log sentence.  I'm running serial output at 115200 and the gps at 9600.

What am I missing?

I can post all the code if that might be helpful.

User avatar
jferguson
 
Posts: 37
Joined: Mon Aug 20, 2012 2:29 pm

Re: cannot dump ultimate log with my own code

Post by jferguson »

Each line in the dumps produced by my code are the same length exactly and about half the number of characters in a complete dump. They are accurately truncated.

Could this be a buffer problem?

User avatar
jferguson
 
Posts: 37
Joined: Mon Aug 20, 2012 2:29 pm

Re: cannot dump ultimate log with my own code

Post by jferguson »

it looks like the problem is that the DUMP is called within a millis loop.

User avatar
jferguson
 
Posts: 37
Joined: Mon Aug 20, 2012 2:29 pm

Re: cannot dump ultimate log with my own code

Post by jferguson »

It Was. works now.
sorry for the noise.

User avatar
jferguson
 
Posts: 37
Joined: Mon Aug 20, 2012 2:29 pm

Re: cannot dump ultimate log with my own code

Post by jferguson »

well it doesn't work. I cannot get the log dump to dump the entirety of every line. And yes, Ada's LOCUS_DumpBasic.ino works fine.
Every thing else seems to work ok. Here's the code.

Where am I messing up??

Code: Select all

 /*  working development for mobileGPS 9/26/2020 jaf
 *  reset display print rows 9/30/2020 jaf
 *  seems to work - needs e-ink display cleanup 10/17/2020 jaf
 *  works fine - 10/18/2020 jaf
 *  added HDOP instead of Q, tried to seek WAAS DGPS, but not sure it's working 10/20/2020 jaf
 *  combined with encoder code 10/21/2020 jaf
 *  function choosing seems to work, but still need to read & display gps 10/21/2020 jaf
 *  substiture while loop for if 10/22/2020 jaf
 *  seems to work but need to slow down encoder select display 10/24/2020 jaf
 *  works ok 10/25/2020 jaf
 *  chooose single nmea sentence to make log translator work. 10/26/2020 jaf
 *  turn off antenna message 10/26/2020 jaf
 *  tryu to get CR/LF on logger output 10/27/2020 jaf ??
 *  changed NMEA sentence to GGA 10/28/2020 jaf
 *  trying to fix dump output to include line-feeds jaf 9-26-2021
 */
#include <Adafruit_GPS.h>
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);

#define GPSECHO false

#include <Adafruit_GFX.h>
#include <Adafruit_SharpMem.h>

const int buttonPin1 = A0;     // the number of the pushbutton pin

// pins used as per project wiring 10/15/2020 jaf
#define SHARP_SCK  10
#define SHARP_MOSI 11
#define SHARP_SS   13

Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
#define BLACK 0
#define WHITE 1

int minorHalfSize; // 1/2 of lesser of display width or height

#define VBATPIN A7

uint32_t timer = millis();
uint32_t timer1 = millis();

signed char lastpos;

int buttonState1 = 0;

#include "EncoderStepCounter.h"

#define ENCODER_PIN1 A3
#define ENCODER_PIN2 A4

// Create instance for one full step encoder
EncoderStepCounter encoder(ENCODER_PIN1, ENCODER_PIN2);

void dumplog(){
   
  if (Serial.available()) {
    char c = Serial.read();
    GPSSerial.write(c);
  }
  if (GPSSerial.available()) {
    char c = GPSSerial.read();
    Serial.write(c);
  }
   
}
void gpsloop() {
  float measuredvbat = analogRead(VBATPIN);
  measuredvbat *= 2;    // we divided by 2, so multiply back
  measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
  measuredvbat /= 1024; // convert to voltage 
  
  // read data from the GPS in the 'main loop'
  char c = GPS.read();
  // echo turnbed off because it was causing double prints. 10/26/2020 jaf
  // if you want to debug, this is a good time to do it!
//  if (GPSECHO)
//    if (c) Serial.print(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 trying to print out data
    Serial.print(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false -HAD PRINTLN 10/26/2020 jaf
    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
  }

 // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    if (GPS.fix) {
        display.setRotation(3);
        display.clearDisplay();
        display.setTextSize(2); 
        display.setCursor(0,0);
        display.print("S:");display.print((int)GPS.satellites);
        display.print("F:");display.print((int)GPS.fix);display.print("Q:");
        display.println((float)GPS.HDOP,2);
        display.print(" VBat: ");display.println(measuredvbat);
        display.setTextSize(3);
        display.println( );
        display.print(" ");display.print((GPS.latitude/100), 4); display.println(GPS.lat);
        display.print(" ");display.print((GPS.longitude/100), 4); display.println(GPS.lon);
        display.refresh();
    }
  }
}
void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("Start of GPS Encoder Routine");
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  //added commands 10/20/2020 jaf
 GPS.sendCommand(PMTK_ENABLE_SBAS);
 GPS.sendCommand(PMTK_ENABLE_WAAS);
 GPS.sendCommand("$PGCMD,33,0*6D");
 
  // 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 GGA data
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_GGAONLY);
  
  // 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
 

  display.begin();
  display.setRotation(3);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("This is Start:");
  display.refresh();
  delay(4000);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(BLACK);
  display.setCursor(0, 0);
  display.println("GPS STARTING");
  display.refresh();

  pinMode(buttonPin1, INPUT);
  
  // Initialize encoder
  encoder.begin();
  
  encoder.tick();
  
  lastpos = encoder.getPosition();
}

void interrupt() {
  encoder.tick();
}
uint32_t uodateTime = 1000;

void loop(){
    
   // Call tick on every loop 
   
    encoder.tick(); //this is an interrupt which acts when encoder is rotated
    
    signed char pos = encoder.getPosition();
    
   while ((lastpos != pos)){
    encoder.tick(); 
    signed char pos1 = encoder.getPosition();
    
    if (millis() - timer1 > 1000) {
    timer1 = millis(); // reset the timer
      
      if (pos1 == 1) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("START LOG");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      GPS.sendCommand(PMTK_LOCUS_STARTLOG);
      display.clearDisplay();
      display.println(" LOG STARTED");
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1;
      }
      display.refresh();
     }
    if (pos1 == 2) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("STOP LOG");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      GPS.sendCommand(PMTK_LOCUS_STOPLOG);
      display.clearDisplay();
      display.println(" LOG STOPPED");
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1;
     }
     display.refresh();
    }
    if (pos1 == 3) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("DUMP LOG");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
     
      while (GPSSerial.available())
      GPSSerial.read();

      delay(1000);
      
  GPS.sendCommand("$PMTK622,1*29");
  Serial.println("----------------------------------------------------");
     //uint32_t updateTime = 1000;

      dumplog();
      display.clearDisplay();
      display.println(" LOG DUMPED");
      GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_GGAONLY);
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1;
      }
    display.refresh();
    }
    if (pos1 == 4) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("ERASE LOG");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      display.clearDisplay();
      GPS.sendCommand(PMTK_LOCUS_ERASE_FLASH);
      display.println(" LOG ERASED");
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1; 
      }
      display.refresh();
    }
    if (pos1 == 5) {
      display.clearDisplay();
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.println("DISPLAY");
      buttonState1 = digitalRead(buttonPin1);
      if ((buttonState1 == HIGH)){
      display.clearDisplay();
      display.println(" RE-DSIPLAYED");
      display.refresh();
      pos = encoder.getPosition();
      lastpos = pos1; 
      }
      display.refresh();
      }
     }
   gpsloop();
}

User avatar
jferguson
 
Posts: 37
Joined: Mon Aug 20, 2012 2:29 pm

Re: cannot dump ultimate log with my own code

Post by jferguson »

see "void dumplog" I'm pretty sure this is where the problem is. I know this is probably CODE 101, but i suspect that instead of running through the log once it's initiated, it doesn't run continuously and so only writes the first half of each line of the log and then goes on to the next one. For the life of me. I cannot see how this is different from Ada's dump code which works so relaibly.

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

Return to “Arduino Shields from Adafruit”