If I use the sketch above:
/*
Example 17.2 "My First GPS"
http://tronixstuff.com/tutorials > Chapter 17
Based on code by Aaron Weiss of SparkFun Electronics;
http://bit.ly/99YnI6
also based on code and libaries by arduiniana.org.
LCD Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net)
and modified 25 July 2009 by David A. Mellis
Thank you :)
We are using the Sparkfun GPS shield and EM-406 GPS receiver module
Make sure the switch on the GPS shield is set to UART
*/
// necessary libraries
//#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <LiquidCrystal.h>
// initialize the LiquidCrystal library with the numbers of the interface pins
// LiquidCrystal lcd(12, 11, 5, 4, 2, 3); //original
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //at niq_ro
// indic modul de legare, vezi mai jos:
/* -------------------
| LCD | Arduino |
-------------------
LCD RS pin to digital pin 7 | RS | D7 |
LCD Enable pin to digital pin 6 | E | D8 |
LCD D4 pin to digital pin 5 | D4 | D9 |
LCD D5 pin to digital pin 4 | D5 | D10 |
LCD D6 pin to digital pin 3 | D6 | D11 |
LCD D7 pin to digital pin 2 | D7 | D12 |
LCD R/W pin to ground | R/W | GND |
-------------------
niq_ro adapted this sketch for see data on 2004 LCD
*/
// Create an instance of the TinyGPS object
TinyGPS gps;
//SoftwareSerial nss(4, 3);
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
void setup()
{
Serial.begin(4800);
// set up the LCD's number of rows and columns:
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("* My First GPS *");
lcd.setCursor(3,1);
lcd.print("tronixstuff.com");
lcd.setCursor(1,2);
lcd.print("adapted by niq_ro");
lcd.setCursor(2,3);
lcd.print("www.tehnic.go.ro");
delay(5000);
lcd.clear();
lcd.setCursor(2,1);
lcd.print("Waiting for lock");
}
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);
// clear LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Lat:");
lcd.print(latitude,5);
lcd.write(0b11011111); // degree symbol
lcd.setCursor(0,1);
lcd.print("Lng:");
lcd.print(longitude,5);
lcd.write(0b11011111); // degree symbol
// Same goes for date and time
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
// Print data and time
lcd.setCursor(0,2);
int ora = 3 + hour;
if (ora ==24) ora=0;
if (ora ==25) ora=1;
if (ora ==26) ora=2;
if (ora<10)
{
lcd.print(" ");
lcd.print(ora);
}
else if (ora>=10)
{
lcd.print(ora);
}
lcd.print(":");
if (minute<10)
{
lcd.print("0");
lcd.print(minute, DEC);
}
else if (minute>=10)
{
lcd.print(minute, DEC);
}
lcd.print(":");
if (second<10)
{
lcd.print("0");
lcd.print(second, DEC);
}
else if (second>=10)
{
lcd.print(second, DEC);
}
/*
lcd.print(" ");
lcd.print(day, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(year, DEC);
*/
// numar sateliti receptionati
lcd.setCursor(10,2); // put cursor at colon 15 and row 2
lcd.print(gps.satellites());
if (gps.satellites() == 1) lcd.print(" satelit ");
else lcd.print(" sateliti");
// lcd.setCursor(0,3);
// lcd.print(gps.f_altitude());
// lcd.print("m ");
// altitudine
lcd.setCursor(15,0); // put cursor at colon 16 and row 0
lcd.print("alt:");
int cota = gps.f_altitude();
lcd.setCursor(14,1); // put cursor at colon 15 and row 1
// cota=5;
//cota=15;
//cota=497;
//cota=2056;
if (cota>1000) lcd.print(cota);
else
if (cota>100) {lcd.print(" "); lcd.print(cota);}
else
if (cota>10) {lcd.print(" "); lcd.print(cota);}
if (cota<10) {lcd.print(" "); lcd.print(cota);}
lcd.print("m");
// lcd.print(gps.f_speed_kmph());
// lcd.print("km/h");
// viteza
lcd.setCursor(10,3); // put cursor at colon x and row y
double viteza = gps.f_speed_kmph();
// tests
// double viteza = 0;
// double viteza = 5;
// double viteza = 14;
// double viteza = 104;
if (viteza<0) lcd.setCursor(9,3);
if (viteza>100.0) lcd.print(viteza);
else
if (viteza>10.0) {lcd.print(" "); lcd.print(viteza);}
else
if (viteza<10.0) {lcd.print(" "); lcd.print(viteza);}
// lcd.print(viteza);
// lcd.print(gps.speed.kmph());
lcd.print("km/h");
/* You can also have course, but I couldn't fit it on the LCD
lcd.print("Course (degrees): "); lcd.println(gps.f_course());
*/
}
void loop()
{
byte a;
if ( Serial.available() > 0 ) // if there is data coming into the serial line
{
a = Serial.read(); // get the byte of data
if(gps.encode(a)) // if there is valid GPS data...
{
getgps(gps); // then grab the data and display it on the LCD
}
}
}
}
on my LCD speed is -1.00:
I try sketch from initial post:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#define RXPIN 4
#define TXPIN 3
//Set this value equal to the baud rate of your GPS
#define GPSBAUD 4800
// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the SoftwareSerial library to the pins you defined above
SoftwareSerial mySerial = SoftwareSerial (RXPIN, TXPIN);
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
// In the setup function, you need to initialize two serial ports; the
// standard hardware serial port (Serial()) to communicate with your
// terminal program an another serial port (NewSoftSerial()) for your
// GPS.
void setup()
{
// This is the serial rate for your terminal program. It must be this
// fast because we need to print everything before a new sentence
// comes in. If you slow it down, the messages might not be valid and
// you will likely get checksum errors.
Serial.begin(115200);
//Sets baud rate of your GPS
mySerial.begin(GPSBAUD);
}
// This is the main loop of the code. All it does is check for data on
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences,
// then jumps to the getgps() function.
void loop()
{
while(mySerial.available()) // While there is data on the RX pin...
{
int c = mySerial.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
}
}
}
void getgps(TinyGPS &gps)
{
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
Serial.print("Lat/Long: ");
Serial.print(latitude,5);
Serial.print(", ");
Serial.println(longitude,5);
//date and time
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths);
// Print data and time
Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":");
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
Serial.print("."); Serial.println(hundredths, DEC);
Serial.print("No. of Sats: ");Serial.println(gps.satellites());
Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
Serial.print("Course (degrees): "); Serial.println(gps.f_course());
Serial.print("Speed(mph): "); Serial.println(gps.f_speed_mph());
Serial.println();
Serial.print("http://maps.google.com/maps?q="); Serial.print(latitude,8); Serial.print(",+"); Serial.println(longitude,8);
Serial.println();
}
but in serial monitor is same error:
I change in SerialSoftware.h lengh value for buffer, but nothing change...
//#define _SS_MAX_RX_BUFF 64 // RX buffer size
#define _SS_MAX_RX_BUFF 128 // RX buffer size