TinyGPS simple question

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()

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




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);
  digitalWrite(Dled, LOW);
  dataReady = false;   
//   NMEA
   pinMode(rxPin, INPUT);
   pinMode(txPin, OUTPUT);

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;
if (counter1 == 300) {
return 0;
if (byteGPS == ',') {
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");
  return 0;
// Check that we received $GPRMC
for (int j=0; j<6; j++) {
if (buf[j] != cmd[j]) {
  Serial.print("Not good command");
return 0;
// Check that time is well formed
if (get_size(1) != 10) {
  Serial.print("Not good time command");
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++) {
if (j==1) {
} else if (j==3) {
} else if (j==5) {
Serial.print("s UTC");
// print date

for (int j=0; j<6; j++) {
if (j==1 || j==3) {
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
} else {
if (!handle_byte(byteGPS)) {

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

Not good pices25                           
Not good pices39                                              
Not good pices68                                                              
Not good pices44                                 
Not good pices46

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




Where are you? Near Kczewo?


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!='

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

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 ,

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