Author Topic: Digispark + GPS + Serial LCD  (Read 4822 times)

tycen

  • Newbie
  • *
  • Posts: 18
Digispark + GPS + Serial LCD
« on: March 25, 2014, 03:28:31 pm »
I'm trying to get a Digispark to pull GPS data (EM-406A) and display it on a 16x2 Serial LCD (not IC2, but Serial: https://www.sparkfun.com/products/9395

Using the info from this thread (https://digistump.com/board/index.php?topic=927.0) I'm able to use the Serial LCD w/o using a software serial library.  So, that means I should be able to use the software serial library to grab data from the GPS receiver, right?

I've found a few examples to this affect, but they all use TinyGPS which is too big for the Digispark's ~6k.

I only really care about the Altitude data from the GPS (using this as an altimeter for a small quadcopter).

Here's what I want to accomplish:
1) Digispark polls the NMEA data from the GPS receiver via software serial
2) Digispark parses the NMEA data and grabs the altitude
3) Digispark prints the Altitude to the LCD (just a Serial.print).

I keep finding code that dances around this, but can't bring it all together.  I see people getting GPS data w/o TinyGPS, but I'm not sure how to parse it and print it to a small 16x2 LCD (most seem to output it to a serial monitor).  I think it's doable and I've gotten close...but no luck yet.

Any help would be appreciated!
« Last Edit: March 25, 2014, 03:37:47 pm by tycen »

tycen

  • Newbie
  • *
  • Posts: 18
Re: Digispark + GPS + Serial LCD
« Reply #1 on: March 25, 2014, 04:47:07 pm »
This post looks close, but I don't get anything except "Waiting GPS data..."

http://www.cooking-hacks.com/documentation/tutorials/arduino-gps#nmea_arduino

I commented out all of the GPS serial prints except the "Antenna altitude" lines.

The LED on my GPS blinks - which according to the datasheet tells me it's getting a position fix (https://www.sparkfun.com/datasheets/GPS/EM-406A_User_Manual.PDF).

tycen

  • Newbie
  • *
  • Posts: 18
Re: Digispark + GPS + Serial LCD
« Reply #2 on: March 26, 2014, 10:47:44 am »
Here's the code I'm using.  On the LCD display I get "Waiting GPS data..." and then shortly after I get "DEBUG1" - but that's it.  My GPS is telling me I have a position lock (via it's blinking LED).  Per the datasheet (link above) I have the RX pin of the GPS connected to pin 3 of the Digispark and the TX pin of the GPS connected to pin 5 of the digispark.  Pin 2 of the Digispark is connected to the serial/data wire of the Serial LCD.

Any ideas?  Any thoughts on the code between DEBUG1 and DEBUG2 as to why it isn't progressing?

Thanks for any help!

tycen

  • Newbie
  • *
  • Posts: 18
Re: Digispark + GPS + Serial LCD
« Reply #3 on: March 26, 2014, 10:50:15 am »
Oops, forgot to paste the code:

Code: [Select]
// From http://www.cooking-hacks.com/documentation/tutorials/arduino-gps#nmea_arduino

// Include the SoftwareSerial library
#include <SoftwareSerial.h>

// Constants
#define txPin 5      //tx pin in GPS connection
#define rxPin 3      //rx pin in GPS connection

// Set up the GPS serial port
SoftwareSerial gps = SoftwareSerial(rxPin, txPin);


// Variables
byte byteGPS = 0; 
int i = 0;
int state = 0;
char dataGPG[100]="";
char *pch;
char *GGA[15];
int sat = 0;

void setup()
{
//setup for Serial Port
Serial.begin(9600);

// clear screen
//  Serial.write(0xFE);
//  Serial.write(0x1);
//  delay(10);   


//setup for GPS Serial Port 
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
gps.begin(4800);


//setup satellites signal
pinMode(1, OUTPUT);
digitalWrite(1, LOW);     // Turn off the led until a satellite signal

//  Serial.write(0xFE);
//  Serial.write(0x80);
//  delay(10);   

}


void loop()
{
Serial.write(254); // cursor to beginning of first line
Serial.write(128);
Serial.print("Waiting GPS data...");

// Prepare all for reading GPS Serial Port
memset(dataGPG, 0, sizeof(dataGPG));    // Remove previous readings
byteGPS = 0;                            // Remove data
byteGPS = gps.read();                   // Read the byte that is in the GPS serial port
delay(1000);

Serial.print("DEBUG1");
delay(1000);

// Find the desired string
while(byteGPS != '$')
{
byteGPS = gps.read();
}

Serial.print("DEBUG2");
delay(1000);

// Save the string in an array
i=1;
dataGPG[0] = '$';

Serial.print("DEBUG3");
delay(1000);


while(byteGPS != '*' )
{
byteGPS = gps.read();
dataGPG[i]=byteGPS;
i++;
}

dataGPG[i]= '\0';
string();                                 // Call to the function that manipulates our string

Serial.print("DEBUG4");
delay(1000);
}



/*
This function will allow us to identify the data we need to get the longitude, latitude ...
*/

void string()
{
i=0;
memset(GGA, 0, sizeof(GGA));          // Remove previous readings

pch = strtok (dataGPG,",");

// Analyze the saved interval in pch to see if it the needed string
if (strcmp(pch,"$GPGGA")==0)
{
while (pch != NULL)
{
pch = strtok (NULL, ",");
GGA[i]=pch;   
i++;
}

plot(GGA,"$GPGGA");         // Call to the function that is going to display the data
}
}

/*
This function organize the gps data received for printing in the serial monitor.
*/

void plot(char **GGAPrint, char *trama)
{
state = atoi(GGAPrint[5]);
sat = atoi(GGAPrint[6]);

if(trama=="$GPGGA" && state==1)
{
digitalWrite(1, HIGH);            // Then there are satellites, the LED switch ON

//Serial.println("");
//Serial.println("----------------------------------------------");
//Serial.print("UTC Hour -> ");
//Serial.println(GGAPrint[0]);
//Serial.print("Latitude -> ");
//Serial.print(GGAPrint[1]);
//Serial.println(GGAPrint[2]);
//Serial.print("Longitude -> ");
//Serial.print(GGAPrint[3]);
//Serial.println(GGAPrint[4]);
//Serial.print("GPS quality: 0=null; 1=GPS fixed -> ");
//Serial.println(GGAPrint[5]);
//Serial.print("Number of satellites -> ");
//Serial.println(sat);
//Serial.print("Horizontal Dilution of Precision -> ");
//Serial.println(GGAPrint[7]);
Serial.print("Antenna altitude -> ");
Serial.print(GGAPrint[8]);
Serial.println(GGAPrint[9]);
//Serial.print("Geoid Separation -> ");
//Serial.print(GGAPrint[10]);
//Serial.println(GGAPrint[11]);
//Serial.println("----------------------------------------------");
//Serial.println("");

}

else                                // If no satellite connection
{
digitalWrite(1, LOW);                                              // Turn off the LED
//Serial.println("");
//Serial.println("-----------------------------");
//Serial.print("|--- Satellites Used -->");
//Serial.print(sat);
//Serial.println(" |");
Serial.println("Waiting location");
//Serial.println("-----------------------------");
//Serial.println("");
}
}