Gps converter

Hallo iedereen
Ik ben Gert ik ben van limburg (be)
en ik ben al van kleinsaf al bezig met basiselectronica
en sinds dat ik arduino heb leren kennen is er een andere wereld voor mij opengegaan
ik ben nog niet zo heel lang bezig met arduino
en daarmee dat ik hier even om raad kom vragen

Ik ben bezig met een gps project en in dit geval zit ik toch wel een beetje vast
nu ben ik wel geen programmeur en meestal kijk ik rond op internet en pas ik de code aan aan mijn wens
zo ook in dit geval ben ik vertrokken vanaf een sketch van adafruit

ik ben al zo ver geraakt dat ik de coordinaaten op mn lcd scherm krijg
(via de §gprmc string)
maar nu moet ik die nog converteren en daar loop ik vast

elders op het arduinoforum heb ik al iets gelijkaardigs gevonden van een gps conversie zoals dit:

float long = 45.124783;
int deglong = long;
long -= deglong; // remove the degrees from the calculation
long *= 60; // convert to minutes
int minlong = long;
long -= minlong; // remove the minuts from the calculation
long *= 60; // convert to seconds

maar het lukt mij niet om dit toe te voegen of veranderen zodat het werkt in mn bestaande sketch
Kan iemand mij hiermee verder helpen of een duw in de juiste richting geven ?

mn setup is het volgende :
ik werk met een arduino uno r3 en ide 1.0
een rgb lcd display en een gps mtk 3329 van adafruit

[quote]


[color=#7E7E7E]// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver[/color]
[color=#7E7E7E]//[/color]
[color=#7E7E7E]// This code shows how to listen to the GPS module in an interrupt[/color]
[color=#7E7E7E]// which allows the program to have more 'freedom' - just parse[/color]
[color=#7E7E7E]// when a new NMEA sentence is available! Then access data when[/color]
[color=#7E7E7E]// desired.[/color]
[color=#7E7E7E]//[/color]
[color=#7E7E7E]// Tested and works great with the Adafruit Ultimate GPS module[/color]
[color=#7E7E7E]// using MTK33x9 chipset[/color]
[color=#7E7E7E]//    ------> http://www.adafruit.com/products/746[/color]
[color=#7E7E7E]// Pick one up today at the Adafruit electronics shop [/color]
[color=#7E7E7E]// and help support open source hardware & software! -ada[/color]
#include <[color=#CC6600]LiquidCrystal[/color].h>
[color=#7E7E7E]// initialize the library with the numbers of the interface pins[/color]
[color=#CC6600]LiquidCrystal[/color] lcd(12, 11, 5, 4, 3, 2);
#include <Adafruit_GPS.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
  [color=#7E7E7E]// Older Arduino IDE requires NewSoftSerial, download from:[/color]
  [color=#7E7E7E]// http://arduiniana.org/libraries/newsoftserial/[/color]
 #include <[color=#CC6600]NewSoftSerial[/color].h>
 [color=#7E7E7E]// DO NOT install NewSoftSerial if using Arduino 1.0 or later![/color]
#endif


[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()  
{ 
  [color=#CC6600]pinMode[/color] (6, [color=#006699]OUTPUT[/color]);[color=#7E7E7E]// pin 6 , blauw[/color]
  [color=#7E7E7E]//pinMode (9,OUTPUT);//pin9 , groen[/color]
  [color=#7E7E7E]//pinMode (10, OUTPUT);//pin10 , rood[/color]
    
  [color=#7E7E7E]// connect at 115200 so we can read the GPS fast enough and echo without dropping chars[/color]
  [color=#7E7E7E]// also spit it out[/color]
  lcd.[color=#CC6600]begin[/color](16,2);
  lcd.[color=#CC6600]print[/color]([color=#006699]"waiting fix ..."[/color]);

  [color=#7E7E7E]// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800[/color]
  GPS.[color=#CC6600]begin[/color](9600);
  
  [color=#7E7E7E]// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude[/color]
  [color=#7E7E7E]//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);[/color]
  [color=#7E7E7E]// uncomment this line to turn on only the "minimum recommended" data[/color]
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  [color=#7E7E7E]// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since[/color]
  [color=#7E7E7E]// the parser doesn't care about other sentences at this time[/color]
  
  [color=#7E7E7E]// Set the update rate[/color]
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   [color=#7E7E7E]// 1 Hz update rate[/color]
  [color=#7E7E7E]// For the parsing code to work nicely and have time to sort thru the data, and[/color]
  [color=#7E7E7E]// print it out we don't suggest using anything higher than 1 Hz[/color]

  [color=#7E7E7E]// the nice thing about this code is you can have a timer0 interrupt go off[/color]
  [color=#7E7E7E]// every 1 millisecond, and read data from the GPS for you. that makes the[/color]
  [color=#7E7E7E]// loop code a heck of a lot easier![/color]
  useInterrupt([color=#CC6600]true[/color]);

  [color=#CC6600]delay[/color](1000);
}


[color=#7E7E7E]// Interrupt is called once a millisecond, looks for any new GPS data, and stores it[/color]
SIGNAL(TIMER0_COMPA_vect) {
  [color=#CC6600]char[/color] c = GPS.[color=#CC6600]read[/color]();
  [color=#7E7E7E]// if you want to debug, this is a good time to do it![/color]
  [color=#CC6600]if[/color] (GPSECHO)
    [color=#CC6600]if[/color] (c) UDR0 = c;  
    [color=#7E7E7E]// writing direct to UDR0 is much much faster than Serial.print [/color]
    [color=#7E7E7E]// but only one character can be written at a time. [/color]
}

[color=#CC6600]void[/color] useInterrupt([color=#CC6600]boolean[/color] v) {
  [color=#CC6600]if[/color] (v) {
    [color=#7E7E7E]// Timer0 is already used for millis() - we'll just interrupt somewhere[/color]
    [color=#7E7E7E]// in the middle and call the "Compare A" function above[/color]
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = [color=#CC6600]true[/color];
  } [color=#CC6600]else[/color] {
    [color=#7E7E7E]// do not call the interrupt function COMPA anymore[/color]
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = [color=#CC6600]false[/color];
  }
}

uint32_t timer = [color=#CC6600]millis[/color]();
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()                     [color=#7E7E7E]// run over and over again[/color]
{
  [color=#7E7E7E]// in case you are not using the interrupt above, you'll[/color]
  [color=#7E7E7E]// need to 'hand query' the GPS, not suggested :([/color]
  [color=#CC6600]if[/color] (! usingInterrupt) {
    [color=#7E7E7E]// read data from the GPS in the 'main loop'[/color]
    [color=#CC6600]char[/color] c = GPS.[color=#CC6600]read[/color]();
    [color=#7E7E7E]// if you want to debug, this is a good time to do it![/color]
    [color=#CC6600]if[/color] (GPSECHO)
      [color=#CC6600]if[/color] (c) UDR0 = c;
      [color=#7E7E7E]// writing direct to UDR0 is much much faster than Serial.print [/color]
      [color=#7E7E7E]// but only one character can be written at a time. [/color]
  }
  
  [color=#7E7E7E]// if a sentence is received, we can check the checksum, parse it...[/color]
  [color=#CC6600]if[/color] (GPS.newNMEAreceived()) {
    [color=#7E7E7E]// a tricky thing here is if we print the NMEA sentence, or data[/color]
    [color=#7E7E7E]// we end up not listening and catching other sentences! [/color]
    [color=#7E7E7E]// so be very wary if using OUTPUT_ALLDATA and trytng to print out data[/color]
    [color=#7E7E7E]//Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false[/color]
  
    [color=#CC6600]if[/color] (!GPS.parse(GPS.lastNMEA()))   [color=#7E7E7E]// this also sets the newNMEAreceived() flag to false[/color]
      [color=#CC6600]return[/color];  [color=#7E7E7E]// we can fail to parse a sentence in which case we should just wait for another[/color]
  }

  [color=#7E7E7E]// if millis() or timer wraps around, we'll just reset it[/color]
  [color=#CC6600]if[/color] (timer > [color=#CC6600]millis[/color]())  timer = [color=#CC6600]millis[/color]();

  [color=#7E7E7E]// approximately every 2 seconds or so, print out the current stats[/color]
  [color=#CC6600]if[/color] ([color=#CC6600]millis[/color]() - timer > 2000) { 
    timer = [color=#CC6600]millis[/color](); [color=#7E7E7E]// reset the timer[/color]
    
    
     
    [color=#CC6600]if[/color] (GPS.fix) {
      lcd.[color=#CC6600]setCursor[/color](0,0);
      lcd.[color=#CC6600]print[/color]([color=#006699]"lat  "[/color]);
      lcd.[color=#CC6600]print[/color](GPS.latitude/100, 4);
      lcd.[color=#CC6600]print[/color]([color=#006699]", "[/color]);
      lcd.[color=#CC6600]setCursor[/color](0,1);
      lcd.[color=#CC6600]print[/color]([color=#006699]"lon  "[/color]); 
      lcd.[color=#CC6600]print[/color](GPS.longitude/100, 4);
      lcd.[color=#CC6600]print[/color]([color=#006699]", "[/color]);
      
    }
  }
}

[/quote]

ik heb wel wat code moeten verwijderen anders was het te groot
don't shoot er zullen nog wel andere fouten of overbodige dingen inzitten
maar veel ervaring heb ik nog niet met arduino

het enige wat nu nog moet aangepast worden zijn de cijfers na de comma delen door 60
dacht dat dit toch wel een beetje makkelijker was voor ik er aan begon :~

Groeten Gert

Dag Gert
Welkom op het Nederlandse forum.
Je zegt ook dat je je GPS coordinaten moet converteren. Maar je zegt niet van wat naar wat.

Met vriendelijke groet
Jantje

PS Je code heeft nogal veel tags om goed te lezen. Je kan best je berichtje aanpassen en leesbare code geven.

Hallo Jantje

Bedankt voor de snelle reactie

ik heb een formule gevonden elders op het internet
maar vraag mij niet hoe dat ze de indeling noemen
het voorbeeld is het volgende :

$GPRMC,035211.000,A,1259.3254,N,07740.1250,E,0.24,86.89,0302

Your resulting latitude should be 12.9887566666667 ie 12 + (59.3254/60)

Similarly the longitude should be 77.66875 ie 077 + (40.125/60)

ps wat bedoel je met tags aanpassen ? hoe moet ik dat doen ?

Groeten Gert

Gert
Ik denk dat het belangrijk is dat je weet wat je wilt.

gert:
float long = 45.124783;
int deglong = long;
long -= deglong; // remove the degrees from the calculation
long *= 60; // convert to minutes
int minlong = long;
long -= minlong; // remove the minuts from the calculation
long *= 60; // convert to seconds

Hier doe je maal 60 (*=60)

gert:
$GPRMC,035211.000,A,1259.3254,N,07740.1250,E,0.24,86.89,0302

Your resulting latitude should be 12.9887566666667 ie 12 + (59.3254/60)

Similarly the longitude should be 77.66875 ie 077 + (40.125/60)

Hier doe je gedeeld door 60 (/60)

en in je code kan ik het niet zien omdat er veel te veel tags instaan.

Met vriendelijke groet
Jantje

Oei daar gaat het al mis
het zou dus moeten zijn zoals het tweede voorbeeld delen door 60 dus

// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop 
// and help support open source hardware & software! -ada
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <Adafruit_GPS.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
  // Older Arduino IDE requires NewSoftSerial, download from:
  // http://arduiniana.org/libraries/newsoftserial/
 #include <NewSoftSerial.h>
 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif

// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
//#if ARDUINO >= 100
  //SoftwareSerial mySerial(3, 2);
//#else
  //NewSoftSerial mySerial(3, 2);
//#endif
//Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
Adafruit_GPS GPS(&Serial);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  false

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = true;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{ 
  pinMode (6, OUTPUT);// pin 6 , blauw
  //pinMode (9,OUTPUT);//pin9 , groen
  //pinMode (10, OUTPUT);//pin10 , rood
    
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  lcd.begin(16,2);
  lcd.print("waiting fix ...");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) UDR0 = c;
      // writing direct to UDR0 is much much faster than Serial.print 
      // but only one character can be written at a time. 
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
    
    
     
    if (GPS.fix) {
      lcd.setCursor(0,0);
      lcd.print("lat  ");
      lcd.print(GPS.latitude/100, 4);
      lcd.print(", ");
      lcd.setCursor(0,1);
      lcd.print("lon  "); 
      lcd.print(GPS.longitude/100, 4);
      lcd.print(", ");
      
    }
  }
}

is de code beter zo ?
ik had iets verkeerd gedaan met kopieren en plakken

Groeten Gert

Gert
Als dit het stukje code is dan is het normaal dat het niet werkt. Je deelt door 100

    if (GPS.fix) {
      lcd.setCursor(0,0);
      lcd.print("lat  ");
      lcd.print(GPS.latitude/100, 4);
      lcd.print(", ");
      lcd.setCursor(0,1);
      lcd.print("lon  "); 
      lcd.print(GPS.longitude/100, 4);
      lcd.print(", ");

terwijl de ander code deelt door 60 en ook nog andere dingen doet.
Als de code dus moet zijn

float long = 45.124783;
int deglong = long;
long -= deglong; // remove the degrees from the calculation
long /= 60; // convert to minutes
int minlong = long;
long -= minlong; // remove the minuts from the calculation
long /= 60; // convert to seconds

moet je dat als volgt zien

float long = 45.124783;

long =45.124783

nt deglong = long;

deglong=45

long -= deglong;

long = 0.124783

long /= 60;

long=0,00207971666666666666666666666667 (ik weet niet hoeveel beduidende cijfers precies)

int minlong = long;

minlong =0 (dat zal altijd zo zijn dus deze code kan nooit correct zijn.
Dus ik blijf bij mijn vraag "Maar je zegt niet van wat naar wat." en dus zeker niet hoe.

Met vriendelijke groet
Jantje

Hallo Jantje

Ik heb wat meer informatie gevonden
de indeling van de gps informatie (de $gprmc string)
is in het formaat graden° minuten.mmmm'
en ik wil die omzetten naar het formaat graden° minuten' seconden"

maar ik zie dat ik helemaal verkeerd zit met mn code
ik dacht dat er maar één manier was voor zoiets om te zetten
maar dus helemaal niet
Ik ga eens die conversie er terug uitgooien uit de code en opnieuw beginnen

hoe kan ik dit beste doen denk je ?

Groeten Gert

Gert
Ik zou het als volgt doen
De tekst in text omvormen naar een stuk minuten en seconden
dan de minuten en seconden omzetten van 60 delig naar honderddelig (of omgekeerd)
Dat is waarschijnlijk niet het snelst maar wel het makkelijkst te begrijpen.
Met vriendelijke groet
Jantje

Ok bedankt
Ik ga het proberen en ik laat wel iets weten als het lukt
... en ook als het niet lukt

Groeten Gert

Hallo hier ben ik terug
ik zit nog met een probleem
het splitsen van de graden van de minuten lukt mij niet helemaal
de graden heb ik nu apart maar bij de minuten krijg ik resultaat 0
ik ben nu nog niet met de conversie bezig ik probeer het eerst te splitsen
maar ik zit weer op een verkeerd spoor
kan iemand mij hierbij helpen ?
Groeten Gert

// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop 
// and help support open source hardware & software! -ada
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <Adafruit_GPS.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
  // Older Arduino IDE requires NewSoftSerial, download from:
  // http://arduiniana.org/libraries/newsoftserial/
 #include <NewSoftSerial.h>
 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif

// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
//#if ARDUINO >= 100
  //SoftwareSerial mySerial(3, 2);
//#else
  //NewSoftSerial mySerial(3, 2);
//#endif
//Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
Adafruit_GPS GPS(&Serial);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  false

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = true;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
int deglon, minlon, deglat, minlat;
long lon, lat;
void setup()  
{ 
  pinMode (6, OUTPUT);// pin 6 , blauw
  //pinMode (9,OUTPUT);//pin9 , groen
  pinMode (10, OUTPUT);//pin10 , rood
    
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  lcd.begin(16,2);
  lcd.print("Minlon .4");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) UDR0 = c;
      // writing direct to UDR0 is much much faster than Serial.print 
      // but only one character can be written at a time. 
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
    
    
    int deglon = GPS.longitude;
GPS.longitude -= deglon; // remove the degrees from the calculation
int lon = deglon/100; // convert to minutes
long minlon = GPS.longitude;
GPS.longitude -= minlon; // remove the minuts from the calculation
long lon2 = minlon;

    int deglat = GPS.latitude;
GPS.latitude -= deglat; // remove the degrees from the calculation
int lat = deglat/100; // convert to minutes
long minlat = GPS.latitude;
GPS.latitude -= minlat; // remove the minuts from the calculation
long lat2 = minlat;   
     
    if (GPS.fix) {
      lcd.setCursor(0,0);
      lcd.print("lat  ");
      lcd.print(lat);    // = 50
      lcd.print(", ");
      lcd.print(lat2);          // = 0
      lcd.setCursor(0,1);
      lcd.print("lon  "); 
      lcd.print(lon);    // = 5
      lcd.print(", ");
      lcd.print(lon2);          // = 0
    }
  }
}

C++ is een krachtig taaltje; dus je moet goed opletten

    int deglon = GPS.longitude;

stel GPS.Longitude is 45.124783
dan is deglon nu 45 (geheel getal(45.124783))

   GPS.longitude -= deglon; // remove the degrees from the calculation

Hier zeg je voluit geschreven

GPS.longitude =GPS.longitude - deglon;

of in data

GPS.longitude = 45.124783 - 45

dus GPS.longitude is nu 0.124783

   int lon = deglon/100; // convert to minutes

Voluit wordt dit

 lon = geheel getal (0.124783 / 100)

of dus 0;

   long minlon = GPS.longitude;

Dit wordt

   long minlon = geheel getal(0.124783)

minlon wordt dus 0

   GPS.longitude -= minlon; // remove the minuts from the calculation

dit wordt

 GPS.longitude =  0.124783 - 0

GPS.longitude blijft dus 0.124783

   long lon2 = minlon;

wordt dus

   long lon2 = geheel getal (0);

lon2 is dus 0;

Het is nooit een goed idee om een variabele van een klasse te veranderen als dat geen betekenis heeft voor de klasse.
Met andere woorden de lijn hieronder is geen goed idee.

   GPS.longitude -= minlon; // remove the minuts from the calculation

Ik hoop dat het nu wat duidelijker is.
Met vriendelijke groet
Jantje

Ok bedankt
eens kijken wat ik ervan kan maken

Ben jij misschien programmeur van beroep dat je dat allemaal zo goed kent ?

Groeten Gert

gert:
Ben jij misschien programmeur van beroep dat je dat allemaal zo goed kent ?

Die job heb ik gedaan. In de vorige eeuw ergens :wink:

Met vriendelijke groet.
Jantje

Ik heb het aan de praat gekregen zoals het hoort
werd wel stilletjes tijd na 3 maanden proberen

hier is de code die ik heb veranderd ( stukje vd code )
het is mss niet de beste manier van programmeren maar het werkt :slight_smile:

int deglon = GPS.longitude/100;
 // remove the degrees from the calculation

 
float lon = GPS.longitude/100 ; 

float deglon2 = lon - deglon;

float deglon3 = deglon2/6*1000000; 

              

int deglat = GPS.latitude/100;
 // remove the degrees from the calculation
 
 
float lat = GPS.latitude/100; 

float deglat2 = lat - deglat;

float deglat3 = deglat2/6*1000000 ;

     
    if (GPS.fix) {
      lcd.setCursor(0,0);
      lcd.print("lat  ");
      lcd.print(deglat);   
      lcd.print(", ");
      lcd.print(deglat3);         
      lcd.setCursor(0,1);
      lcd.print("lon  "); 
      lcd.print(deglon);    
      lcd.print(", ");
      lcd.print(deglon3);          
    }

Bedankt voor de informatie
en ik ga zeker nog een tijdje blijven rondhangen op het forum

Groeten Gert

Gert
!!!goed gedaan!!!!
Het enigste wat je zou kunnen verbeteren is dat je 2 maal hetzelfde doet. dat zou in een functie kunnen die je dan 2 maal aanroept. Maar das een kniesoor (zoals ik ]:slight_smile: ) die daar over begint. :wink:
Dit is dus bovenste beste code. Proficiat
Met vriendelijke groet
Jantje