TinyGPS simple question

Hi.
I’m try to work on my 1st code in arduino environment.
Code will be part of self driving robot, and i have small PCB board with Atmega168 and GPS module.
When i try to compile TinyGPS hex file is enormous !
And for my needs ( for testing purpose ) i will be heppy to have only speed in 100th knots will do the job.
Someone can strip for me TinyGPS example just to obtain speed ?
On example there ale loot of variable that i still don’t understand :(( .
I will use only hardware uart

#include <TinyGPS.h>
TinyGPS gps;
//SoftwareSerial ss(4, 3);
static void smartdelay(unsigned long ms);     // do i need this for speed ? 
static void print_float(float val, float invalid, int len, int prec);  // do i need this for speed ? 
static void print_int(unsigned long val, unsigned long invalid, int len); // do i need this for speed ? 
static void print_date(TinyGPS &gps);               // do i need this for speed ? 
static void print_str(const char *str, int len);   // do i need this for speed ? 

(..)

On main loop can i have only this ?

void loop()
{
   Serial.print(gps.speed());
}

read up on http://aprs.gids.nl/nmea/
U need the "$GPRMC" sentence only.
Skip the library, and listen for the correct sentence to arrive.
As the sentence always have the same structure, you can pick only the chars you want..

Well before i use some step by step code to have some data from NMEA but code takse char table long as 300 bytes - thats a lot for me ... and with connection to another my code i think i have buffer overflow or ram leak.
Why do i think so ?
When GPS is under roof code looks like it works - i have speed 0.0 (because there is no signal) but when gps is outside it looks like it stop.Only difference is amount data that arduino have from gps ...
In home

$GPRMC,000129.799,V,,,,,0.00,0.00,060180,,,N*4F

Outside

$GPRMC,193714.000,A,5422.9526,N,01823.7613,E,0.21,160.38,141014,,,A*6B

Code that i take for 1st my attempt was from this site :

But what i see guy is using 2kB ram atmega .. well my have only 1kB

You dont need reading the whole sentence

  • identify "RMC"
  • then count incoming commas ","
  • read digits for speed

You don't need to worry about the functions you listed. If you don't use them, the linker won't include them.

The ATMega328 chip is the same size and same pin arrangement as the ATMega168, and costs almost exactly the same amount, but has twice the memory. Why are you stuck on using a 168?

Where is your code? There may be other ways to reduce its size.

Here is some simple code that parses the $GPRMC sentence and returns character strings for the various entries. It counts commas as suggested previously. 威尼斯人直营网址

Edit: I checked out this code a bit more carefully, and it is pretty buggy. Don’t bother with it.

Code for my robot

#include <Wire.h>
#include <string.h>
#include <ctype.h>
#define STATUS_LED 7
int Dled = 8;
int Dfix = 10;

int ledPin = 6;                  // LED test pin
int rxPin = 0;                    // RX PIN 
int txPin = 1;                    // TX TX
int byteGPS=-1;
char buf[300] = "";
char cmd[7] = "$GPRMC";
int counter1 = 0; // counts how many bytes were received (max 300)
int counter2 = 0; // counts how many commas were seen
int offsets[13];
byte Data[2];

// ##############################################################################3

void setup()
{
  pinMode(ledPin, OUTPUT);       // Initialize LED pin
  pinMode(Dled, OUTPUT);      // led from 3d fixa
  pinMode(Dfix, INPUT);        // input 3d fixa
  digitalWrite(Dled, HIGH);
  delay(600);
  digitalWrite(Dled, LOW);
  pinMode (STATUS_LED,OUTPUT);
  digitalWrite(STATUS_LED,HIGH);
  delay(10);
  digitalWrite(STATUS_LED,LOW);
  dataReady = false;   
//   NMEA
   pinMode(rxPin, INPUT);
   pinMode(txPin, OUTPUT);
   Serial.begin(9600);
    reset();
}

 
void reset() {
counter1 = 0;
counter2 = 0;
}
 
int get_size(int offset) {
return offsets[offset+1] - offsets[offset] - 1;
}
 
int handle_byte(int byteGPS) {
buf[counter1] = byteGPS;
//Serial.print((char)byteGPS);
counter1++;
if (counter1 == 300) {
return 0;
}
if (byteGPS == ',') {
counter2++;
offsets[counter2] = counter1;
if (counter2 == 13) {
return 0;
}
}
if (byteGPS == '*') {
offsets[12] = counter1;
}
 
// Check if we got a <LF>, which indicates the end of line
if (byteGPS == 10) {
// Check that we got 12 pieces, and that the first piece is 6 characters
if (counter2 != 12 || (get_size(0) != 6)) {
Serial.print("Not good pices");
Serial.println(counter1);
Serial.println(counter2);
Serial.println();
  return 0;
}
 
// Check that we received $GPRMC
for (int j=0; j<6; j++) {
if (buf[j] != cmd[j]) {
  Serial.print("Not good command");
Serial.println();
return 0;
}
}
 
// Check that time is well formed
if (get_size(1) != 10) {
  Serial.print("Not good time command");
 Serial.println();
return 0;
}
 
// Check that date is well formed
if (get_size(9) != 6) {
return 0;
}
 
// TODO: compute and validate checksum
 
// TODO: handle timezone offset
 
// print time

for (int j=0; j<6; j++) {
Serial.print(buf[offsets[1]+j]);
if (j==1) {
Serial.print("h");
} else if (j==3) {
Serial.print("m");
} else if (j==5) {
Serial.print("s UTC");
}
}
 
// print date

for (int j=0; j<6; j++) {
Serial.print(buf[offsets[9]+j]);
if (j==1 || j==3) {
Serial.print(".");
}
}
return 0;
}
return 1;
}
 
/**
* Main loop
*/
void loop() {
byteGPS=Serial.read(); // Read a byte of the serial port
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
} else {
if (!handle_byte(byteGPS)) {
reset();
}
}
}

Its clear code from link above - i add some debug in code and i’v got on serial monitor:

Not good pices25                           
5
                                                                           
Not good pices39                                              
9
                                                                           
Not good pices68                                                              
11
                                         
Not good pices44                                 
9
                                                                                                     
Not good pices46
 12

So it looks like not good formated NMEA but form gps module i hvae this :

$GPGSA,A,3,23,17,09,01,04,11,31,06,32,,,,2.11,0.88,1.92*04
                    
$GPRMC,171449.000,A,5422.9519,N,01823.7377,E,0.02,196.81,151014,,,D*69
        
$GPVTG,196.81,T,,M,0.02,N,0.05,K,D*38
                                         
$GPGGA,171450.000,5422.9519,N,01823.7377,E,2,9,0.88,166.3,M,34.2,M,0000,0000*5E

$GPGSA,A,3,23,17,09,01,04,11,31,06,32,,,,2.11,0.88,1.92*04
                    
$GPRMC,171450.000,A,5422.9519,N,01823.7377,E,0.03,196.81,151014,,,D*60
        
$GPVTG,196.81,T,,M,0.03,N,0.06,K,D*3A
                                         
$GPGGA,171451.000,5422.9519,N,01823.7377,E,2,9,0.88,166.3,M,34.2,M,0000,0000*5F

$GPGSA,A,3,23,17,09,01,04,11,31,06,32,,,,2.11,0.88,1.92*04
                    
$GPGSV,4,1,16,20,82,123,16,23,61,209,45,32,36,096,22,01,34,164,40*72
          
$GPGSV,4,2,16,04,31,164,41,31,31,055,20,06,30,308,22,09,30,225,37*7F
          
$GPGSV,4,3,16,17,25,255,32,33,20,219,31,11,08,169,21,13,07,223,18*7B
          
$GPGSV,4,4,16,25,07,010,,08,04,166,34,10,02,279,,12,02,336,*7D
                
$GPRMC,171451.000,A,5422.9519,N,01823.7377,E,0.02,196.81,151014,,,D*60

Where are you? Near Kczewo?

//Serial.print((char)byteGPS);

Why is this commented out? How can you know what you are getting?

Forget having a bazillion lines of code to parse data until you KNOW you are getting good data.

// Replace Serial… with GPS…

 char ch;
void setup()
{}
char read_char_from_gps()  // funtion to read a char from GPS
{
  if (Serial.available()) return Serial.read(); else return '\0';
}

void loop()
{
do  ch=read_char_from_gps(); while (ch!='

EDIT:
There should of couse be added counting while searching for the ‘C’. If not char nbr 5 - ‘goto start’ - search for ‘$’); // read until hit ’


EDIT:
There should of couse be added counting while searching for the 'C'. If not char nbr 5 - 'goto start' - search for '$'
do  ch=read_char_from_gps(); while (ch!='C'); // read on till 'C'
for (byte cnt=0; cnt<7; cnt++)   do  ch=read_char_from_gps(); while (ch!=',') ;    // start counting commas
// now read and keep digits/chars until next ,
}

EDIT:
There should of couse be added counting while searching for the ‘C’. If not char nbr 5 - ‘goto start’ - search for ‘$’