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/07 14:03] 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. | ||
| - | Sketch below is a work in progress - and is not yet fully functional! | + | A GPS example can be found in the newest Digistump IDE Release - 1.5.8A or higher - under File->Examples->Digispark_Examples->GPS |
| - | Based on: https://www.insidegadgets.com/2013/10/11/playing-around-with-gps-attiny-gps-longlat-logger/ | + | NOTE: You must select the Digispark Pro (16Mhz) (64 byte buffer) for the example to work! |
| - | + | ||
| - | <code arduino> | + | |
| - | #include <DigiCDC.h> | + | |
| - | + | ||
| - | void setup() { | + | |
| - | // put your setup code here, to run once: | + | |
| - | SerialUSB.begin(); | + | |
| - | Serial.begin(9600); | + | |
| - | } | + | |
| - | + | ||
| - | + | ||
| - | char tempBuffer[15]; | + | |
| - | + | ||
| - | + | ||
| - | void loop() { | + | |
| - | // put your main code here, to run repeatedly: | + | |
| - | if(Serial.available()){ | + | |
| - | char rxData = Serial.read(); | + | |
| - | + | ||
| - | // Start of frame | + | |
| - | if (rxData == '$') { | + | |
| - | // Read next chars | + | |
| - | ReadSerialToComma(); | + | |
| - | + | ||
| - | // Check if GPRMC | + | |
| - | if (memcmp(tempBuffer, "GPRMC", 5) == 0) { | + | |
| - | ReadSerialToComma(); // Timestamp | + | |
| - | //buffer has time right now | + | |
| - | SerialUSB.println(tempBuffer); | + | |
| - | ReadSerialToComma(); // Validity | + | |
| - | + | ||
| - | // If valid GPS data | + | |
| - | if (tempBuffer[0] == 'A') { | + | |
| - | + | ||
| - | ReadSerialToComma(); // Latitude | + | |
| - | //buffer has lat right now | + | |
| - | SerialUSB.println(tempBuffer); | + | |
| - | + | ||
| - | ReadSerialToComma(); // N or S (ignore | + | |
| - | ReadSerialToComma(); // Longitude | + | |
| - | //buffer has lon right now | + | |
| - | SerialUSB.println(tempBuffer); | + | |
| - | + | ||
| - | ReadSerialToComma(); // W or E (ignore) | + | |
| - | + | ||
| - | ReadSerialToComma(); // Speed in knots | + | |
| - | //buffer has speed right now | + | |
| - | SerialUSB.println(tempBuffer); | + | |
| - | + | ||
| - | ReadSerialToComma(); // Course made good (ignore) | + | |
| - | + | ||
| - | ReadSerialToComma(); // Date | + | |
| - | //buffer has date right now | + | |
| - | SerialUSB.println(tempBuffer); | + | |
| - | + | ||
| - | SerialUSB.delay(1000); //wait 1 second before fetching again | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | } | + | |
| - | } | + | |
| - | } | + | |
| - | } | + | |
| - | SerialUSB.refresh(); | + | |
| - | } | + | |
| - | + | ||
| - | + | ||
| - | byte ReadSerialToComma(void) { | + | |
| - | int x = 0; | + | |
| - | tempBuffer[x] = Serial.read(); | + | |
| - | + | ||
| - | while (tempBuffer[x] != ',') { | + | |
| - | x++; | + | |
| - | tempBuffer[x] = Serial.read(); | + | |
| - | SerialUSB.refresh(); | + | |
| - | } | + | |
| - | + | ||
| - | x++; | + | |
| - | tempBuffer[x] = 0; | + | |
| - | return x; | + | |
| - | } | + | |
| - | </code> | + | |