Hi guys,
I have a problem with my arduino projekt. im trying to make my own gpslogging system for a schoolprojekt, im using http://www.ladyada.net/make/gpsshield/index.html to create it.
it worked fine yet, but my teacher wants me to add a lcd display(16x2), which shows the current gps possion. i wanted to use the basic logging scatch of ladyada and i wanted to add the command to print it on the LCD but i don´t really know to do it. (https://github.com/adafruit/SD-Basic-GP ... Logger.pde). for my lcd display im useing these pins: LiquidCrystal lcd( 1, 7, 8, 9, 10, 0); does it work with that pins or what to i have to change to make it work.
Could you pls help me ty
Arduino GPS datalogging ++
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino GPS datalogging ++
Pins 0 & 1 will interfere with serial communication and pin 10 is the chip-select for the SD card. If you don't have enough pins, you should consider using an I2C backpack That will allow you to connect the display with only 2 pins.im useing these pins: LiquidCrystal lcd( 1, 7, 8, 9, 10, 0);
-
- Posts: 6
- Joined: Thu Oct 18, 2012 10:51 am
Re: Arduino GPS datalogging ++
Thank you so far i have enough pins to change them, but how can i actually add it to my sctach because i tried to print the buffer on the lcd and it showed nothing so how would you change the script that it show the same data as in the serial monitor?
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino GPS datalogging ++
If you change the wiring, you need to change the pins in the sketch to match. If you can post your sketch and a photo that shows your wiring we can help you figure it out.
-
- Posts: 6
- Joined: Thu Oct 18, 2012 10:51 am
Re: Arduino GPS datalogging ++
ok im now useing these pins 7,8,9,11,12,13 as you can see im my scatch:
[Edit - moderator - Please use the 'code' button when submitting code]
I can now write down something like lcd.print("hello world!") but actually i want to change the scatch that the lcd prints the same information like in the serial monitor, but i don´t know who to write it int the script.
Could you pls add the commands that it shows it on the lcd?
[Edit - moderator - Please use the 'code' button when submitting code]
Code: Select all
// Ladyada's logger modified by Bill Greiman to use the SdFat library
// this is a generic logger that does checksum testing so the data written should be always good
// Assumes a sirf III chipset logger attached to pin 2 and 3
#include <SD.h>
#include <avr/sleep.h>
#include "GPSconfig.h"
#include <LiquidCrystal.h>
// If using Arduino IDE prior to 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
LiquidCrystal lcd( 7, 8, 9, 11, 12, 13);
// power saving modes
#define SLEEPDELAY 0 /* power-down time in seconds. Max 65535. Ignored if TURNOFFGPS == 0 */
#define TURNOFFGPS 0 /* set to 1 to enable powerdown of arduino and GPS. Ignored if SLEEPDELAY == 0 */
#define LOG_RMC_FIXONLY 0 /* set to 1 to only log to SD when GPD has a fix */
// what to log
#define LOG_RMC 1 // RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define LOG_GGA 0 // GGA-Global Positioning System Fixed Data, message 103,00
#define LOG_GLL 0 // GLL-Geographic Position-Latitude/Longitude, message 103,01
#define LOG_GSA 0 // GSA-GNSS DOP and Active Satellites, message 103,02
#define LOG_GSV 0 // GSV-GNSS Satellites in View, message 103,03
#define LOG_VTG 0 // VTG-Course Over Ground and Ground Speed, message 103,05
// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
SoftwareSerial gpsSerial = SoftwareSerial(2, 3);
#else
NewSoftSerial gpsSerial = NewSoftSerial(2, 3);
#endif
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800
// Set the pins used
#define powerPin 4
#define led1Pin 5
#define led2Pin 6
#define chipSelect 10
#define BUFFSIZE 90
char buffer[BUFFSIZE];
uint8_t bufferidx = 0;
bool fix = false; // current fix data
bool gotGPRMC; //true if current data is a GPRMC strinng
uint8_t i;
File logfile;
// read a Hex value and return the decimal equivalent
uint8_t parseHex(char c) {
if (c < '0')
return 0;
if (c <= '9')
return c - '0';
if (c < 'A')
return 0;
if (c <= 'F')
return (c - 'A')+10;
}
// blink out an error code
void error(uint8_t errno) {
/*
if (SD.errorCode()) {
putstring("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(',');
Serial.println(card.errorData(), HEX);
}
*/
while(1) {
for (i=0; i<errno; i++) {
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, HIGH);
delay(100);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
delay(100);
}
for (; i<10; i++) {
delay(200);
}
}
}
void setup() {
WDTCSR |= (1 << WDCE) | (1 << WDE);
WDTCSR = 0;
Serial.begin(9600);
Serial.println("\r\nGPSlogger");
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(powerPin, OUTPUT);
digitalWrite(powerPin, LOW);
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card init. failed!");
error(1);
}
strcpy(buffer, "GPSLOG00.TXT");
for (i = 0; i < 100; i++) {
buffer[6] = '0' + i/10;
buffer[7] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(buffer)) {
break;
}
}
logfile = SD.open(buffer, FILE_WRITE);
if( ! logfile ) {
Serial.print("Couldnt create "); Serial.println(buffer);
error(3);
}
Serial.print("Writing to "); Serial.println(buffer);
// connect to the GPS at the desired rate
gpsSerial.begin(GPSRATE);
Serial.println("Ready!");
gpsSerial.print(SERIAL_SET);
delay(250);
#if (LOG_DDM == 1)
gpsSerial.print(DDM_ON);
#else
gpsSerial.print(DDM_OFF);
#endif
delay(250);
#if (LOG_GGA == 1)
gpsSerial.print(GGA_ON);
#else
gpsSerial.print(GGA_OFF);
#endif
delay(250);
#if (LOG_GLL == 1)
gpsSerial.print(GLL_ON);
#else
gpsSerial.print(GLL_OFF);
#endif
delay(250);
#if (LOG_GSA == 1)
gpsSerial.print(GSA_ON);
#else
gpsSerial.print(GSA_OFF);
#endif
delay(250);
#if (LOG_GSV == 1)
gpsSerial.print(GSV_ON);
#else
gpsSerial.print(GSV_OFF);
#endif
delay(250);
#if (LOG_RMC == 1)
gpsSerial.print(RMC_ON);
#else
gpsSerial.print(RMC_OFF);
#endif
delay(250);
#if (LOG_VTG == 1)
gpsSerial.print(VTG_ON);
#else
gpsSerial.print(VTG_OFF);
#endif
delay(250);
#if (USE_WAAS == 1)
gpsSerial.print(WAAS_ON);
#else
gpsSerial.print(WAAS_OFF);
#endif
}
void loop() {
//Serial.println(Serial.available(), DEC);
char c;
uint8_t sum;
// read one 'line'
if (gpsSerial.available()) {
c = gpsSerial.read();
#if ARDUINO >= 100
//Serial.write(c);
#else
//Serial.print(c, BYTE);
#endif
if (bufferidx == 0) {
while (c != '$')
c = gpsSerial.read(); // wait till we get a $
}
buffer[bufferidx] = c;
#if ARDUINO >= 100
//Serial.write(c);
#else
//Serial.print(c, BYTE);
#endif
if (c == '\n') {
//putstring_nl("EOL");
//Serial.print(buffer);
buffer[bufferidx+1] = 0; // terminate it
if (buffer[bufferidx-4] != '*') {
// no checksum?
Serial.print('*');
bufferidx = 0;
return;
}
// get checksum
sum = parseHex(buffer[bufferidx-3]) * 16;
sum += parseHex(buffer[bufferidx-2]);
// check checksum
for (i=1; i < (bufferidx-4); i++) {
sum ^= buffer[i];
}
if (sum != 0) {
//putstring_nl("Cxsum mismatch");
Serial.print('~');
bufferidx = 0;
return;
}
// got good data!
gotGPRMC = strstr(buffer, "GPRMC");
if (gotGPRMC) {
// find out if we got a fix
char *p = buffer;
p = strchr(p, ',')+1;
p = strchr(p, ',')+1; // skip to 3rd item
if (p[0] == 'V') {
digitalWrite(led1Pin, LOW);
fix = false;
} else {
digitalWrite(led1Pin, HIGH);
fix = true;
}
}
if (LOG_RMC_FIXONLY) {
if (!fix) {
Serial.print('_');
bufferidx = 0;
return;
}
}
// rad. lets log it!
Serial.print(buffer); //first, write it to the serial monitor
Serial.print('#');
if (gotGPRMC) //If we have a GPRMC string
{
// Bill Greiman - need to write bufferidx + 1 bytes to getCR/LF
bufferidx++;
digitalWrite(led2Pin, HIGH); // Turn on LED 2 (indicates write to SD)
logfile.write((uint8_t *) buffer, bufferidx); //write the string to the SD file
logfile.flush();
/*
if( != bufferidx) {
putstring_nl("can't write!");
error(4);
}
*/
digitalWrite(led2Pin, LOW); //turn off LED2 (write to SD is finished)
bufferidx = 0; //reset buffer pointer
if (fix) { //(don't sleep if there's no fix)
if ((TURNOFFGPS) && (SLEEPDELAY)) { // turn off GPS module?
digitalWrite(powerPin, HIGH); //turn off GPS
delay(100); //wait for serial monitor write to finish
sleep_sec(SLEEPDELAY); //turn off CPU
digitalWrite(powerPin, LOW); //turn on GPS
} //if (TURNOFFGPS)
} //if (fix)
return;
}//if (gotGPRMC)
}
bufferidx++;
if (bufferidx == BUFFSIZE-1) {
Serial.print('!');
bufferidx = 0;
}
} else {
}
}
void sleep_sec(uint16_t x) {
while (x--) {
// set the WDT to wake us up!
WDTCSR |= (1 << WDCE) | (1 << WDE); // enable watchdog & enable changing it
WDTCSR = (1<< WDE) | (1 <<WDP2) | (1 << WDP1);
WDTCSR |= (1<< WDIE);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
// sleep_enable();
sleep_mode();
// sleep_disable();
}
}
SIGNAL(WDT_vect) {
WDTCSR |= (1 << WDCE) | (1 << WDE);
WDTCSR = 0;
}
/* End code */
I can now write down something like lcd.print("hello world!") but actually i want to change the scatch that the lcd prints the same information like in the serial monitor, but i don´t know who to write it int the script.
Could you pls add the commands that it shows it on the lcd?
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino GPS datalogging ++
Find the place where you are writing to the Serial Monitor using Serial.print() and add an lcd.print() to write the same string.i want to change the scatch that the lcd prints the same information like in the serial monitor
Since the LCD does not scroll like the serial monitor, you will also need to use lcd.setCursor() to position the cursor.
Also, keep in mind that the display is much smaller than the serial monitor so you will need to make sure your output does not exceed the display width.
Code: Select all
Serial.print(buffer); //first, write it to the serial monitor
lcd.setCursor(0,0); // go to the first line of the display
lcd.pring(buffer); // print the same thing to the display
-
- Posts: 6
- Joined: Thu Oct 18, 2012 10:51 am
Re: Arduino GPS datalogging ++
Thanks a lot, i tried to solve the problem on my own a bit. I tried to add the lcd function the the scatch without sdcard- logging and it worked fine.
I now have this scetch:
I would now like to add the data logging part on the sd card to this scatch because I can understand this scatch much more and the output on the serial monitor looks quite better i think. So i wanted to ask if its possible to log the data that you get from this scetch on the sd card.
I now have this scetch:
Code: Select all
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 13, 9, 8, 7);
// A simple sketch to read GPS data and parse the $GPRMC string
// see http://www.ladyada.net/make/gpsshield for more info
// If using Arduino IDE prior to version 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
#else
#include "WProgram.h"
#include "NewSoftSerial.h"
#endif
// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
SoftwareSerial mySerial = SoftwareSerial(2, 3);
#else
NewSoftSerial mySerial = NewSoftSerial(2, 3);
#endif
// Use pin 4 to control power to the GPS
#define powerpin 4
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800
//#define GPSRATE 38400
// The buffer size that will hold a GPS sentence. They tend to be 80 characters long
// so 90 is plenty.
#define BUFFSIZ 90 // plenty big
// global variables
char buffer[BUFFSIZ]; // string buffer for the sentence
char *parseptr; // a character pointer for parsing
char buffidx; // an indexer into the buffer
// The time, date, location data, etc.
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;
void setup()
{
if (powerpin) {
pinMode(powerpin, OUTPUT);
}
// Use the pin 13 LED as an indicator
pinMode(13, OUTPUT);
// connect to the serial terminal at 9600 baud
Serial.begin(9600);
// connect to the GPS at the desired rate
mySerial.begin(GPSRATE);
// prints title with ending line break
Serial.println("GPS parser");
digitalWrite(powerpin, LOW); // pull low to turn on!
}
uint32_t parsedecimal(char *str) {
uint32_t d = 0;
while (str[0] != 0) {
if ((str[0] > '9') || (str[0] < '0'))
return d;
d *= 10;
d += str[0] - '0';
str++;
}
return d;
}
void readline(void) {
char c;
buffidx = 0; // start at begninning
while (1) {
c=mySerial.read();
if (c == -1)
continue;
Serial.print(c);
if (c == '\n')
continue;
if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
buffer[buffidx] = 0;
return;
}
buffer[buffidx++]= c;
}
}
void loop()
{
uint32_t tmp;
Serial.print("\n\rRead: ");
readline();
// check if $GPRMC (global positioning fixed data)
if (strncmp(buffer, "$GPRMC",6) == 0) {
// hhmmss time data
parseptr = buffer+7;
tmp = parsedecimal(parseptr);
hour = tmp / 10000;
minute = (tmp / 100) % 100;
second = tmp % 100;
parseptr = strchr(parseptr, ',') + 1;
status = parseptr[0];
parseptr += 2;
// grab latitude & long data
// latitude
latitude = parsedecimal(parseptr);
if (latitude != 0) {
latitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
latitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',') + 1;
// read latitude N/S data
if (parseptr[0] != ',') {
latdir = parseptr[0];
}
//Serial.println(latdir);
// longitude
parseptr = strchr(parseptr, ',')+1;
longitude = parsedecimal(parseptr);
if (longitude != 0) {
longitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
longitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',')+1;
// read longitude E/W data
if (parseptr[0] != ',') {
longdir = parseptr[0];
}
// groundspeed
parseptr = strchr(parseptr, ',')+1;
groundspeed = parsedecimal(parseptr);
// track angle
parseptr = strchr(parseptr, ',')+1;
trackangle = parsedecimal(parseptr);
// date
parseptr = strchr(parseptr, ',')+1;
tmp = parsedecimal(parseptr);
date = tmp / 10000;
month = (tmp / 100) % 100;
year = tmp % 100;
Serial.print("\n\tTime: ");
Serial.print(hour, DEC); Serial.print(':');
Serial.print(minute, DEC); Serial.print(':');
Serial.println(second, DEC);
Serial.print("\tDate: ");
Serial.print(month, DEC); Serial.print('/');
Serial.print(date, DEC); Serial.print('/');
Serial.println(year, DEC);
Serial.print("\tLat: ");
if (latdir == 'N')
Serial.print('+');
else if (latdir == 'S')
Serial.print('-');
Serial.print(latitude/1000000, DEC); Serial.print("* ");
Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
lcd.begin(16,2);
lcd.print("B:");
lcd.print(latitude/1000000, DEC); lcd.print("* ");
lcd.print((latitude/10000)%100, DEC); lcd.print('\''); lcd.print(' ');
lcd.print((latitude%10000)*6/1000, DEC); lcd.print('.');
lcd.print(((latitude%10000)*6/10)%100, DEC); lcd.println('"');
Serial.print("\tLong: ");
if (longdir == 'E')
Serial.print('+');
else if (longdir == 'W')
Serial.print('-');
Serial.print(longitude/1000000, DEC); Serial.print("* ");
Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
lcd.setCursor(0, 1);
lcd.print("L:");
lcd.print(longitude/1000000, DEC); lcd.print("* ");
lcd.print((longitude/10000)%100, DEC); lcd.print('\''); lcd.print(' ');
lcd.print((longitude%10000)*6/1000, DEC); lcd.print('.');
lcd.print(((longitude%10000)*6/10)%100, DEC); lcd.println('"');
}
//Serial.println(buffer);
}
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino GPS datalogging ++
Yes. Once you open a file, you can call file.print(), just like serial.print() and lcd.print().So i wanted to ask if its possible to log the data that you get from this scetch on the sd card.
-
- Posts: 6
- Joined: Thu Oct 18, 2012 10:51 am
Re: Arduino GPS datalogging ++
ok if i do the same with file.print();..... how do i create a file on the sd card and how do i write in this file?
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino GPS datalogging ++
The "datalogger" example sketch in the SD library shows how to open and write to a file.
-
- Posts: 6
- Joined: Thu Oct 18, 2012 10:51 am
Re: Arduino GPS datalogging ++
Hi its me again i have antoher problem with my project.
Thats my current scetch:
This one on its own (without this SD.print part) works fine:
As soon as i add the command to write on the sd card, the serial monitor shows me FAILED! like he should if the file is not aviable AND the lcd display shows rubish. it seems to have a problem creating the file how do i solve it?
Thats my current scetch:
Code: Select all
#include <LiquidCrystal.h>
#include <SD.h>
LiquidCrystal lcd(12, 11, 13, 9, 8, 7);
// A simple sketch to read GPS data and parse the $GPRMC string
// see http://www.ladyada.net/make/gpsshield for more info
// If using Arduino IDE prior to version 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
#else
#include "WProgram.h"
#include "NewSoftSerial.h"
#endif
// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
SoftwareSerial mySerial = SoftwareSerial(2, 3);
#else
NewSoftSerial mySerial = NewSoftSerial(2, 3);
#endif
// Use pin 4 to control power to the GPS
#define powerpin 4
const int chipSelect = 10;
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800
//#define GPSRATE 38400
// The buffer size that will hold a GPS sentence. They tend to be 80 characters long
// so 90 is plenty.
#define BUFFSIZ 90 // plenty big
// global variables
char buffer[BUFFSIZ]; // string buffer for the sentence
char *parseptr; // a character pointer for parsing
char buffidx; // an indexer into the buffer
File GPSDaten;
// The time, date, location data, etc.
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;
void setup()
{
if (powerpin) {
pinMode(powerpin, OUTPUT);
}
// Use the pin 13 LED as an indicator
pinMode(13, OUTPUT);
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// connect to the serial terminal at 9600 baud
Serial.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
// connect to the GPS at the desired rate
mySerial.begin(GPSRATE);
// prints title with ending line break
Serial.println("GPS parser");
digitalWrite(powerpin, LOW); // pull low to turn on!
}
uint32_t parsedecimal(char *str) {
uint32_t d = 0;
while (str[0] != 0) {
if ((str[0] > '9') || (str[0] < '0'))
return d;
d *= 10;
d += str[0] - '0';
str++;
}
return d;
}
void readline(void) {
char c;
buffidx = 0; // start at begninning
while (1) {
c=mySerial.read();
if (c == -1)
continue;
Serial.print(c);
if (c == '\n')
continue;
if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
buffer[buffidx] = 0;
return;
}
buffer[buffidx++]= c;
}
}
void loop()
{
uint32_t tmp;
Serial.print("\n\rRead: ");
readline();
// check if $GPRMC (global positioning fixed data)
if (strncmp(buffer, "$GPRMC",6) == 0) {
// hhmmss time data
parseptr = buffer+7;
tmp = parsedecimal(parseptr);
hour = tmp / 10000;
minute = (tmp / 100) % 100;
second = tmp % 100;
parseptr = strchr(parseptr, ',') + 1;
status = parseptr[0];
parseptr += 2;
// grab latitude & long data
// latitude
latitude = parsedecimal(parseptr);
if (latitude != 0) {
latitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
latitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',') + 1;
// read latitude N/S data
if (parseptr[0] != ',') {
latdir = parseptr[0];
}
//Serial.println(latdir);
// longitude
parseptr = strchr(parseptr, ',')+1;
longitude = parsedecimal(parseptr);
if (longitude != 0) {
longitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
longitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',')+1;
// read longitude E/W data
if (parseptr[0] != ',') {
longdir = parseptr[0];
}
// groundspeed
parseptr = strchr(parseptr, ',')+1;
groundspeed = parsedecimal(parseptr);
// track angle
parseptr = strchr(parseptr, ',')+1;
trackangle = parsedecimal(parseptr);
// date
parseptr = strchr(parseptr, ',')+1;
tmp = parsedecimal(parseptr);
date = tmp / 10000;
month = (tmp / 100) % 100;
year = tmp % 100;
Serial.print("\n\tTime: ");
Serial.print(hour, DEC); Serial.print(':');
Serial.print(minute, DEC); Serial.print(':');
Serial.println(second, DEC);
Serial.print("\tDate: ");
Serial.print(month, DEC); Serial.print('/');
Serial.print(date, DEC); Serial.print('/');
Serial.println(year, DEC);
Serial.print("\tLat: ");
if (latdir == 'N')
Serial.print('+');
else if (latdir == 'S')
Serial.print('-');
Serial.print(latitude/1000000, DEC); Serial.print("* ");
Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
lcd.begin(16,2);
lcd.print("B:");
lcd.print(latitude/1000000, DEC); lcd.print("* ");
lcd.print((latitude/10000)%100, DEC); lcd.print('\''); lcd.print(' ');
lcd.print((latitude%10000)*6/1000, DEC); lcd.print('.');
lcd.print(((latitude%10000)*6/10)%100, DEC); lcd.println('"');
GPSDaten = SD.open("GPSDatentest.TXT", FILE_WRITE);
if (GPSDaten){
GPSDaten.print(latitude/1000000, DEC); GPSDaten.print("* ");
GPSDaten.print((latitude/10000)%100, DEC); GPSDaten.print('\''); GPSDaten.print(' ');
GPSDaten.print((latitude%10000)*6/1000, DEC); GPSDaten.print('.');
GPSDaten.print(((latitude%10000)*6/10)%100, DEC); GPSDaten.println('"');
GPSDaten.close();}
else{Serial.println("failed!");}
Serial.print("\tLong: ");
if (longdir == 'E')
Serial.print('+');
else if (longdir == 'W')
Serial.print('-');
Serial.print(longitude/1000000, DEC); Serial.print("* ");
Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
lcd.setCursor(0, 1);
lcd.print("L:");
lcd.print(longitude/1000000, DEC); lcd.print("* ");
lcd.print((longitude/10000)%100, DEC); lcd.print('\''); lcd.print(' ');
lcd.print((longitude%10000)*6/1000, DEC); lcd.print('.');
lcd.print(((longitude%10000)*6/10)%100, DEC); lcd.println('"');
}
//Serial.println(buffer);
}
Code: Select all
#include <LiquidCrystal.h>
#include <SD.h>
LiquidCrystal lcd(12, 11, 13, 9, 8, 7);
// A simple sketch to read GPS data and parse the $GPRMC string
// see http://www.ladyada.net/make/gpsshield for more info
// If using Arduino IDE prior to version 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
#else
#include "WProgram.h"
#include "NewSoftSerial.h"
#endif
// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
SoftwareSerial mySerial = SoftwareSerial(2, 3);
#else
NewSoftSerial mySerial = NewSoftSerial(2, 3);
#endif
// Use pin 4 to control power to the GPS
#define powerpin 4
const int chipSelect = 10;
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800
//#define GPSRATE 38400
// The buffer size that will hold a GPS sentence. They tend to be 80 characters long
// so 90 is plenty.
#define BUFFSIZ 90 // plenty big
// global variables
char buffer[BUFFSIZ]; // string buffer for the sentence
char *parseptr; // a character pointer for parsing
char buffidx; // an indexer into the buffer
//File GPSDaten;
// The time, date, location data, etc.
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;
void setup()
{
if (powerpin) {
pinMode(powerpin, OUTPUT);
}
// Use the pin 13 LED as an indicator
pinMode(13, OUTPUT);
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// connect to the serial terminal at 9600 baud
Serial.begin(9600);
Serial.print("Initializing SD card...");
/*if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");*/
// connect to the GPS at the desired rate
mySerial.begin(GPSRATE);
// prints title with ending line break
Serial.println("GPS parser");
digitalWrite(powerpin, LOW); // pull low to turn on!
}
uint32_t parsedecimal(char *str) {
uint32_t d = 0;
while (str[0] != 0) {
if ((str[0] > '9') || (str[0] < '0'))
return d;
d *= 10;
d += str[0] - '0';
str++;
}
return d;
}
void readline(void) {
char c;
buffidx = 0; // start at begninning
while (1) {
c=mySerial.read();
if (c == -1)
continue;
Serial.print(c);
if (c == '\n')
continue;
if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
buffer[buffidx] = 0;
return;
}
buffer[buffidx++]= c;
}
}
void loop()
{
uint32_t tmp;
Serial.print("\n\rRead: ");
readline();
// check if $GPRMC (global positioning fixed data)
if (strncmp(buffer, "$GPRMC",6) == 0) {
// hhmmss time data
parseptr = buffer+7;
tmp = parsedecimal(parseptr);
hour = tmp / 10000;
minute = (tmp / 100) % 100;
second = tmp % 100;
parseptr = strchr(parseptr, ',') + 1;
status = parseptr[0];
parseptr += 2;
// grab latitude & long data
// latitude
latitude = parsedecimal(parseptr);
if (latitude != 0) {
latitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
latitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',') + 1;
// read latitude N/S data
if (parseptr[0] != ',') {
latdir = parseptr[0];
}
//Serial.println(latdir);
// longitude
parseptr = strchr(parseptr, ',')+1;
longitude = parsedecimal(parseptr);
if (longitude != 0) {
longitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
longitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',')+1;
// read longitude E/W data
if (parseptr[0] != ',') {
longdir = parseptr[0];
}
// groundspeed
parseptr = strchr(parseptr, ',')+1;
groundspeed = parsedecimal(parseptr);
// track angle
parseptr = strchr(parseptr, ',')+1;
trackangle = parsedecimal(parseptr);
// date
parseptr = strchr(parseptr, ',')+1;
tmp = parsedecimal(parseptr);
date = tmp / 10000;
month = (tmp / 100) % 100;
year = tmp % 100;
Serial.print("\n\tTime: ");
Serial.print(hour, DEC); Serial.print(':');
Serial.print(minute, DEC); Serial.print(':');
Serial.println(second, DEC);
Serial.print("\tDate: ");
Serial.print(month, DEC); Serial.print('/');
Serial.print(date, DEC); Serial.print('/');
Serial.println(year, DEC);
Serial.print("\tLat: ");
if (latdir == 'N')
Serial.print('+');
else if (latdir == 'S')
Serial.print('-');
Serial.print(latitude/1000000, DEC); Serial.print("* ");
Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
lcd.begin(16,2);
lcd.print("B:");
lcd.print(latitude/1000000, DEC); lcd.print("* ");
lcd.print((latitude/10000)%100, DEC); lcd.print('\''); lcd.print(' ');
lcd.print((latitude%10000)*6/1000, DEC); lcd.print('.');
lcd.print(((latitude%10000)*6/10)%100, DEC); lcd.println('"');
/*GPSDaten = SD.open("GPSDatentest.TXT", FILE_WRITE);
if (GPSDaten){
GPSDaten.print(latitude/1000000, DEC); GPSDaten.print("* ");
GPSDaten.print((latitude/10000)%100, DEC); GPSDaten.print('\''); GPSDaten.print(' ');
GPSDaten.print((latitude%10000)*6/1000, DEC); GPSDaten.print('.');
GPSDaten.print(((latitude%10000)*6/10)%100, DEC); GPSDaten.println('"');
GPSDaten.close();}
else{Serial.println("failed!");}*/
Serial.print("\tLong: ");
if (longdir == 'E')
Serial.print('+');
else if (longdir == 'W')
Serial.print('-');
Serial.print(longitude/1000000, DEC); Serial.print("* ");
Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
lcd.setCursor(0, 1);
lcd.print("L:");
lcd.print(longitude/1000000, DEC); lcd.print("* ");
lcd.print((longitude/10000)%100, DEC); lcd.print('\''); lcd.print(' ');
lcd.print((longitude%10000)*6/1000, DEC); lcd.print('.');
lcd.print(((longitude%10000)*6/10)%100, DEC); lcd.println('"');
}
//Serial.println(buffer);
}
Please be positive and constructive with your questions and comments.