This question is about the simplest way to convert the data (char) from a field (field 7) in an $GPRMC NMEA sentence?
I would like to take field 7 from the NMEA sentence, convert that 'Knots' reading into an int form, divide it by .54 and output it to a PWM pin that I can RC filter and output via an LM358 to give me an analog output...
I'm having problems finding an easy way to convert the char field into an int variable? I think I have missed something!
I'm happy with this sketch otherwise and have not used TinyGPS.
I also want to output to an LED the status of field 2 (LED on if field is "A") so need to test for that as well at some stage?
Here is the current raw sketch that needs the additions....
Any help appreciated! Thanks.....
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;
char sentence[sentenceSize];
void setup()
{
Serial.begin(9600);
gpsSerial.begin(9600);
}
void loop()
{
static int i = 0;
if (gpsSerial.available())
{
char ch = gpsSerial.read();
if (ch != '\n' && i < sentenceSize)
{
sentence[i] = ch;
i++;
}
else
{
sentence[i] = '\0';
i = 0;
displayGPS();
}
}
}
void displayGPS()
{
char field[20];
getField(field, 0);
if (strcmp(field, "$GPRMC") == 0)
{
Serial.println("Speed over the ground in knots is:");
getField(field, 7); // Knots value from GPS
Serial.println(field);
[color=red][font=Verdana] // I would like to take field 7 from the
// NMEA sentence, convert that 'Knots' reading into an int form,
// div it by .54 and output it to a PWM pin that I can
// RC filter and output via an LM358 to give me an analog output....[/font][/color]
}
}
void getField(char* buffer, int index)
{
int sentencePos = 0;
int fieldPos = 0;
int commaCount = 0;
while (sentencePos < sentenceSize)
{
if (sentence[sentencePos] == ',')
{
commaCount ++;
sentencePos ++;
}
if (commaCount == index)
{
buffer[fieldPos] = sentence[sentencePos];
fieldPos ++;
}
sentencePos ++;
}
buffer[fieldPos] = '\0';
}
Edit: add code tag! sorry....