Go Down

Topic: Gps converter (Read 4 times) previous topic - next topic

gert

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

Code: [Select]
[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

Jantje

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.

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

gert

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

Jantje

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

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)


$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
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

gert

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

Code: [Select]


// 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

Go Up