This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
digispark:tutorials:gps [2014/12/12 14:28] digistump |
digispark:tutorials:gps [2016/06/09 12:03] (current) |
||
|---|---|---|---|
| Line 30: | Line 30: | ||
| =====Assembly:===== | =====Assembly:===== | ||
| + | **NOTE:** Before you start: If you have a multimeter check for shorts between the GND pin hole and the other pin holes - if you find any please send us an email at support at digistump dot com and we will replace the board. | ||
| [[https://s3.amazonaws.com/digispark/images/m/gps1.JPG|{{https://s3.amazonaws.com/digispark/images/t/gps1.JPG}}]] | [[https://s3.amazonaws.com/digispark/images/m/gps1.JPG|{{https://s3.amazonaws.com/digispark/images/t/gps1.JPG}}]] | ||
| Line 63: | Line 63: | ||
| NOTE: The first time you use the GPS module it may take 5 minutes or more, near a window or outside, to acquire a fix and produce data. | NOTE: The first time you use the GPS module it may take 5 minutes or more, near a window or outside, to acquire a fix and produce data. | ||
| - | The below code will type the data out like a keyboard and must be connected to a computer - but other than the DigiKeyboard stuff, it can be reused in non-connected projects as well. | + | A GPS example can be found in the newest Digistump IDE Release - 1.5.8A or higher - under File->Examples->Digispark_Examples->GPS |
| - | + | NOTE: You must select the Digispark Pro (16Mhz) (64 byte buffer) for the example to work! | |
| - | <code arduino> | + | |
| - | #include "DigiKeyboard.h" | + | |
| - | + | ||
| - | String nmeaString; | + | |
| - | bool gpsReady = 0; | + | |
| - | + | ||
| - | void setup() { | + | |
| - | + | ||
| - | DigiKeyboard.delay(3000); | + | |
| - | Serial.begin(9600); | + | |
| - | initGPS(); | + | |
| - | } | + | |
| - | + | ||
| - | + | ||
| - | void loop() { | + | |
| - | + | ||
| - | if(updateGPS()){ | + | |
| - | DigiKeyboard.println(nmeaString); | + | |
| - | DigiKeyboard.println(getStatus()); | + | |
| - | if(gpsReady){ | + | |
| - | DigiKeyboard.println(getTime()); | + | |
| - | DigiKeyboard.println(getDate()); | + | |
| - | } | + | |
| - | } | + | |
| - | DigiKeyboard.delay(1000); | + | |
| - | + | ||
| - | + | ||
| - | } | + | |
| - | + | ||
| - | void initGPS(){ | + | |
| - | + | ||
| - | Serial.println(PSTR("$PUBX,40,RMC,1,1,1,0*46")); //turn on RMC msgs | + | |
| - | Serial.println(PSTR("$PUBX,40,GLL,0,0,0,0*5C")); //turn off the rest | + | |
| - | Serial.println(PSTR("$PUBX,40,GGA,0,0,0,0*5A")); | + | |
| - | Serial.println(PSTR("$PUBX,40,GSA,0,0,0,0*4E")); | + | |
| - | Serial.println(PSTR("$PUBX,40,GSV,0,0,0,0*59")); | + | |
| - | Serial.println(PSTR("$PUBX,40,VTG,0,0,0,0*5E")); | + | |
| - | + | ||
| - | } | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | bool updateGPS() { | + | |
| - | if(Serial.find("GPRMC,")){ | + | |
| - | nmeaString = Serial.readStringUntil('$'); | + | |
| - | if(getStatus() == 'A') | + | |
| - | gpsReady = 1; | + | |
| - | else | + | |
| - | gpsReady = 0; | + | |
| - | + | ||
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | return false; | + | |
| - | + | ||
| - | } | + | |
| - | + | ||
| - | + | ||
| - | long getTime(){ | + | |
| - | return nmeaString.substring(0,6).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | char getStatus(){ | + | |
| - | return nmeaString.charAt(nmeaString.indexOf(',')+1); //this has to work even if the other data isn't present | + | |
| - | } | + | |
| - | + | ||
| - | float getLat(){ | + | |
| - | return nmeaString.substring(12,22).toFloat(); | + | |
| - | } | + | |
| - | + | ||
| - | int getLatDeg(){ | + | |
| - | return nmeaString.substring(12,14).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | float getLatMin(){ | + | |
| - | return nmeaString.substring(14,22).toFloat(); | + | |
| - | } | + | |
| - | + | ||
| - | float getLon(){ | + | |
| - | return nmeaString.substring(25,36).toFloat(); | + | |
| - | } | + | |
| - | + | ||
| - | int getLonDeg(){ | + | |
| - | return nmeaString.substring(25,28).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | float getLonMin(){ | + | |
| - | return nmeaString.substring(28,36).toFloat(); | + | |
| - | } | + | |
| - | + | ||
| - | float getKnots(){ | + | |
| - | return nmeaString.substring(39,44).toFloat(); | + | |
| - | } | + | |
| - | + | ||
| - | long getDate(){ | + | |
| - | return nmeaString.substring(46,52).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | int getDay(){ | + | |
| - | return nmeaString.substring(46,48).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | int getMonth(){ | + | |
| - | return nmeaString.substring(48,50).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | int getYear(){ | + | |
| - | return nmeaString.substring(50,52).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | long getFullYear(){ | + | |
| - | return 2000 + nmeaString.substring(50,52).toInt(); | + | |
| - | } | + | |
| - | + | ||
| - | char getNS(){ | + | |
| - | return nmeaString.charAt(23); | + | |
| - | } | + | |
| - | + | ||
| - | char getEW(){ | + | |
| - | return nmeaString.charAt(37); | + | |
| - | } | + | |
| - | + | ||
| - | </code> | + | |