loosing first characters of nmea sentence

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
tristan74656
 
Posts: 18
Joined: Tue Mar 18, 2014 3:20 pm

loosing first characters of nmea sentence

Post by tristan74656 »

Hello Experts,

i use an Arduino Uno R3 and a Adafruit Ultimate GPS Schield. I want to read the NEMA every second and write it to SD card. In the meantime i put the Arduino to sleep. The GPS does the wake up after 1s.
Loop()
- read GPS
- write SD card
- sleep

Problem is: the first 1- 3 signs of the NMEA sentence are not written to the sd card. Should start with $GPRMC, but is PRMC, or only RMC,

Thanks for any help on this.

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: loosing first characters of nmea sentence

Post by Franklin97355 »

Could you post your code and a description or drawing of your connections between it all?
Please use the code button "</>" as shown below.
Code Button.jpg
Code Button.jpg (4.49 KiB) Viewed 338 times

tristan74656
 
Posts: 18
Joined: Tue Mar 18, 2014 3:20 pm

Re: loosing first characters of nmea sentence

Post by tristan74656 »

I have put the gps read code in a class. You find the source code below the loop code.

Code: Select all

void loop()
{
  static uint8_t  uiCounter = 0;
  
  if (0 != this->pSoftSerial->available())
  {
    Extensions::GPS.Receive();
    const char* pcSentence = Extensions::GPS.GetSentence();
    
    logfile.write((uint8_t *)pcSentence, strlen(pcSentence));
    
    if (10 == uiCounter)
    {
      logfile.flush();
      uiCounter = 0;
    }
    
    uiCounter++;
  }
  
  System::Sleep(SLEEP_4S);
}

Code: Select all

unsigned int
CGPS::Receive(void)
{
	char		received	= '\0';
	unsigned int	byteCount	= 0;

	while ('\n' != received)
	{
		if (this->pSoftSerial->available())
		{
			received = this->pSoftSerial->read();

			if ('$' == received)
			{
				byteCount	= 0;
			}

			this->buffer[byteCount]	= received;
			byteCount++;

			if (GPS_BUFFER_LENGTH == byteCount)
			{
				byteCount	= 0;
			}
		}
	}

	this->buffer[byteCount++]	= '\0';
	return byteCount;
}

Code: Select all

const char*
CGPS::GetSentence(void)
{
	return this->buffer;
}
I simply use a Arduino Uno R3 with the ultimate gps logger shield.
https://learn.adafruit.com/adafruit-ult ... d/overview

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: loosing first characters of nmea sentence

Post by Franklin97355 »

Could you post the entire code so we could try to run it and troubleshoot? Have you tried running the example code to see if that works or printing what you receive from the GPS with your code to see if the problem is with the receiving code or the SD writing code?

tristan74656
 
Posts: 18
Joined: Tue Mar 18, 2014 3:20 pm

Re: loosing first characters of nmea sentence

Post by tristan74656 »

I checked the hardware with your sample code and it works fine. So it must be a software Problem.
I will attach the hole library code.

Code: Select all

#include <SoftwareSerial.h>
#include <Extensions.h>
#include <System.h>
#include <SD.h>



//--------------------------------------------------------------------------------------------------
//                                                                                            define
//--------------------------------------------------------------------------------------------------
#define  SERIAL_BAUDRATE             115200
#define  SERIAL_PIN_RECEIVE          8
#define  SERIAL_PIN_TRANSMIT         7

#define  ANALOG_PIN_VIN              0



//--------------------------------------------------------------------------------------------------
//                                                                                            global
//--------------------------------------------------------------------------------------------------
File   logfile;


void SetupLogFile();

//--------------------------------------------------------------------------------------------------
//                                                                                             setup
//--------------------------------------------------------------------------------------------------
void setup()
{
  Serial.begin(SERIAL_BAUDRATE);
  
  // -> SD card
  SetupLogFile();
  // <-
  
  // -> GPS
  Extensions::GPS.Connect(SERIAL_PIN_RECEIVE, SERIAL_PIN_TRANSMIT);

  Extensions::GPS.SetOutputFormat(OutputFormat_RMC);
  Extensions::GPS.SetUpdateRate(UpdateRate_1Hz);
  Extensions::GPS.SetAntennaStatus(false);
  // <-
  
  Serial.println("setup done.");
  delay(1000);
}



//--------------------------------------------------------------------------------------------------
//                                                                                              loop
//--------------------------------------------------------------------------------------------------
void loop()
{
  static uint8_t  uiCounter = 0;
  
  if (true == Extensions::GPS.IsAvailable())
  {
    Extensions::GPS.Receive();
    const char* pcSentence = Extensions::GPS.GetSentence();
    
    logfile.write((uint8_t *)pcSentence, strlen(pcSentence));
    
    if (10 == uiCounter)
    {
      logfile.flush();
      uiCounter = 0;
    }
    
    uiCounter++;
  }
  
  System::Sleep(SLEEP_4S);
}



//--------------------------------------------------------------------------------------------------
//                                                                                      SetupLogFile
//--------------------------------------------------------------------------------------------------
void SetupLogFile()
{
  pinMode(13, OUTPUT);
  pinMode(10, OUTPUT);
  
  if (0 != SD.begin(10))
  {
    char filename[16];
    strcpy(filename, "PEGLOG00.TXT");
    
    for (uint8_t i = 0; i < 100; i++)
    {
      filename[6] = '0' + i / 10;
      filename[7] = '0' + i % 10;
      
      if (0 == SD.exists(filename)) break;
    }
    
    if (0 != (logfile = SD.open(filename, FILE_WRITE)))
    {
      Serial.print("writing to file: ");
      Serial.println(filename);
    }
    else
    {
      Serial.print("could not open file: ");
      Serial.println(filename);
    }
  }
  else
  {
    Serial.println("SD card initialization failed.");
  }
}
Attachments
Lib.zip
contains all the libraries i used in my program
(3.37 KiB) Downloaded 22 times

tristan74656
 
Posts: 18
Joined: Tue Mar 18, 2014 3:20 pm

Re: loosing first characters of nmea sentence

Post by tristan74656 »

I am still clueless about the problem. Could you find something out ?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: loosing first characters of nmea sentence

Post by Franklin97355 »

If it works with the example programs and not your code the problem is with your code and I don't know enough about code to answer but I will move this to the general project forum so it will get better coverage.

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

Return to “General Project help”