Tutorial 15 for Arduino: GPS Tracking

Just another WordPress site

Tutorial 15 for Arduino: GPS Tracking

everybody Jeremy Blum here with another Arduino tutorial as you can tell on outside talking to myself like a crazy person that’s because this week we’re going to be focusing on using GPS so I’ve got my GPS tracker here I’ll show you guys what looks like later but this is the antenna sneaking out the top and I’m in Washington Square Park in New York City right now so what we’re going to do is we’re going to walk around see what kind of data we can grab or put on the SD card and then we’ll be able to sit on a map of where our GPS logger has been so let’s go for a walk you as you just saw in this Arduino tutorial we’ll be talking about how to interface the Arduino with a GPS module GPS or Global Positioning System is a way to get real-time information about your latitude and longitude and altitude from satellites so we’ll specifically be using the Arduino mega the cooking hacks GPS shield and the cooking hats SD card shield so I’ve used this one before in my data logging tutorial go ahead and watch it if you haven’t already what we’ll be doing is using our GPS antenna to get real-time location data and save that information specifically latitude and longitude to a comma separated values file on our SD card we’ll be using the tiny GPS arduino library to help us parse that data and then what we’ll do is we’ll be able to put the SD card in our computer grab the latitude longitude information off of it and use a service like Google Fusion charts and Google Earth I have one of the Google Earth charts and maps up on the screen behind me take that latitude longitude data and turn it into a map overlay that shows us where we’ve been over the course tenth day I chose to use an Arduino mega for this because I wanted a serial port to use the GPS shield with GPS transmits data in a standard format at 4800 baud into a serial port but I wanted to also be able to use a serial port to do debugging on the computer you can do this with an Arduino Uno you can either choose to disable debugging to the computer and use that serial port to interface with your GPS or you can use software serial which is a library included in order we know to interface with your GPS module but since I had the mega round and I want to make it as easy as possible for me to communicate with both the same time a lot of debugging the system I chose to use the Arduino mega you also want to make sure that you have a 9-volt battery and some kind of power switch so that you can make this thing portable and carry it around with you I also recommend getting some kind of case I repurposed the case from a logic analyzer I have carrying this thing around New York City outside I didn’t want anyone to be stopping me saying I look suspicious so I thought it was a good idea to put this in a case okay let’s start by taking a look at some of the history of GPS and kind of how we got to where we are today and that’ll help give us a little bit of explanation for how we’re going to use the GPS system to get our latitude and longitude data onto our Arduino GPS stands for the global positioning system it was initialized by the US Department of Defense in the 1970s originally for military purposes however President Ronald Reagan issued a directive making a degraded version of GPS available to civilians in the early 90s this however still was not very accurate Bill Clinton later signed a bill making the 20 meter full resolution version of GPS available to civilian users around the year 2000 the system today is still maintained by the US government but is accessible by users worldwide GPS systems require unobstructed line-of-sight to four satellites in order to function all GPS satellites constantly transmit the time and the current position above the earth they use code division multiple access the same technology employed by some cellular carriers to allow multiple satellites to communicate to communicate over the same Channel simultaneously since we know the speed at which electromagnetic waves travel the speed of light three times 10 to the eighth meters per second the position of our receiver can be calculated by analyzing the differences in the time it took for the signal from each GPS satellite to be received ordinarily three satellites would be enough to triangulate our position since we live in 3d space and are presumably on the Earth’s surface but four or more generally required in order to compensate for timing errors even a several microsecond offset in a satellites atomic clock when multiplied

by the speed of light can result in wildly inaccurate positioning information a three-dimensional version of distance equation which people are probably familiar with from geometry courses with edited biasing for some time offsets is used to calculate position the GPS receiver that we’ll be using today as well as most gps receivers uses the NMEA zero one eight three serial communication specification the spec designates a typical baud rate 4,800 bond and the message format knowing this format will be able to decode the data string that we receive in serial into time latitude longitude etc the formatting of this string is pretty ugly and there’s multiple ways to analyze it so I won’t go into all the details because we’ll be using the tiny GPS Arduino library to do most of that decoding for us if you’re interested in the content of the string you can look at the raw value coming in over the serial connection or you can look on Wikipedia and all the information that can be contained in that string in addition to receiving information from the GPS you can also send requests to it that tell it what kind of data you’re interested in receiving there’s multiple format type of strings that will contain different GPS information and you can choose what you want to receive over the serial interface our hardware setup is as follows there’s an Arduino mega with an SD card shield mounted to the top it’s plugged into in circuit serial programming header which is basically just SPI pins and I’ve also connected the slave select pin to pin 53 on the Arduino mega as that’s a default slave select pin in the software the GPS shield is connected to one of the Arduino mega s extra Hardware serial ports in this case it’s UART number three so TX three and Horrocks three making sure you put it in the proper orientation so that TX on the GPS goes to Arduino and vice versa make sure you also have got power and ground on the GPS shield I’ve also added a battery and I’ve put a switch in line with the battery in order to enable me to easily turn the system on and off first things first we’ll need to get our SD card set up and we’ll need to download the tiny GPS library if you’re on Linux or Mac it’s a similar operation you can do it from the terminal just Google how to format an SD card on windows you’ll right-click on a hit format choose fat you want to be fat 16 and the default allocation size is fine you can change the volume label I changed mine to GPS if you want it’ll tell you it’s going to raise all the data and you’re all done now we want to add a file to our SD card that will actually be logging the data to so make a new file you can do this in the Linux or Mac command prompt by using the touch command or you can do it on Windows but it’s making a text document in changing the extension is pretty easy so I’m going to call it capital log dot CSV make sure you change the extension to dot CSV cuz that’s what our code will be expecting later CSV is a comma separated values file it’s the easiest way to get it uploaded to things like Google Maps to overlay image data okay that’s perfect you can eject the SD card and put it into your Arduino next up we want to make sure we get the tiny GPS library go to this web address I’ll link it as well and go down to the download section to download the zip of the library I’ve already gone ahead and downloaded this so I won’t download it again but once you’ve downloaded it you’ll want to put it into your partly on program directory so in Windows it’ll be wherever you installed Arduino slash libraries extract the tiny GPS folder and should go in there and should look something like this with the examples and the C++ and H files once that’s in there then you can go ahead and open our – we know and we’ll load up one of the example programs to see if we can get our GPS outputting some data so go ahead and open up the Arduino programming environment once the Arduino programming environment is open go to file examples and we’ll go to the tiny GPS example so we’re going to choose the test with GPS device option and there’s already some nice sample code here that’s written that will grab the data from the GPS and spit it out over the serial connection to our computer we’re going to make a few minor modifications to it though we’re like I mentioned before we’re not using software serial for our connector I chose to use a hardware serial connection if you’re using a new no you’ll just keep the software serial and set the ports up right here for which one is Rx and TX but for us I’m going to change it to hardware serial so I’m going to remove the inclusion of the software serial interface I’m going to remove the Declaration of the software serial object and you can see here is where we’re setting up the new soft serial interface it operates at 4800 broad like I mentioned with our GPS module I’m just going to do a fine and replace for all NS s with cereal 3 because that’s what we’re hooked up to so that’ll change it to using hardware cereal so I’ll hit replace oh okay and we can see that it’s been changed to cereal 3 there and all the places where it’s doing that so before we actually load this code on let’s take a very quick run through it I’m not going to go through all the details but basically at the beginning it’s printing out some header information so you can see what you’re going to be looking at and then it goes to a loop and it prints out an update every one second the GPS step is word get the actual data

from the GPS and it’s using some built-in functions from the library to do that what we’re going to care about the most later and where we’re going to make modifications to this program to log to the SD card is the GPS dump function so this is calling various functions from the library that get things like altitude the course the speed things like the float versions of latitude and longitude the number of satellites that we have connected all kinds of good information and then printing it out on the screen in a pretty format and so we’ll grab this information later modify it a little bit and put it in a friendly format for putting into a CSV file that we can then get on the web and use to overlay some data from our GPS trip there’s a couple of helper functions down here like print int and print float that allow and that allow the library author to more readily print the information that we’re getting to the serial monitor which is nice it just looks good but this is all like I said mostly for kind of debugging purposes so this is what we’re working with we didn’t have to modify too much let’s go ahead and save this file as a new files because we can’t save over the example so go to file save as for now I’ll just put this on my desktop and we’ll call this GPS a debug okay so put that on the desktop hit save we’re good okay now make sure you have the right Arduino and port selected and upload it to your order we now I already have mine connected once it’s done uploading open up your serial monitor okay and we’ll see on the serial monitor that it’s printing out some information for us it’s printed out that header that I showed you earlier and it’s printing out all these stars that’s because there’s no valid sattell Fix however we do know it’s working because the charge received is talking about the charge that have been received from the GPS unit so we can see that it’s increasing with time which means that the GPS unit is transmitting information to the Arduino that we can then use naturally I’m filming this video inside I don’t not out sides I don’t have a satellite fix in the beginning of this tutorial when I showed you outside the GPS said I’d already gotten a satellite fix I was walking around with it obviously when we modify the sketch we’ll add an LED indicator that shows us when the satellite actually has a fix so that when you’re not next to a computer that you can debug it you can confirm that this data is in fact getting filled in ok so we do know it’s working it’s definitely receiving data and we’re not getting anything it’s not valid but that’s that’s just fine when you do go outside it’s suggesting that you put some kind of plastic enclosure over the antenna it should help it get a satellite fix a little bit sooner and you shouldn’t be surprised if you have to walk around or stand still for a couple minutes before it does actually manage to get a satellite fix and this will vary with different GPS units and things like that ok so we have our example sketch working it’s not showing us anything too interesting right now but I’ll use some sample data later to show you what we might kind of expect to get here the next thing we’ll do is take our GPS debug program and modify it so that it saves data to the SD card in a format that we’re interested in and so that it turns an LED on when we have valid data so that we know when we’re walking around outside if we’re actually gathering valid satellite latitude and longitude data so let’s get started on doing that now that we know our GPS is working properly we can go ahead and get it outputting data to our SD card as well by modifying the sketch I recommend first that you save this sketch as a new sketch so that we don’t overwrite our example code so I’ll say this one as GPS logger ok so we hit save we’re good to go there let’s include some other necessary app libraries that we’ll need of course we’re going to need the SD card library so we can write to our as D card I’m also going to include the standard library so that we can do some string manipulations and things like that that requirement so standard live dot H you should also modify your comments of course always to make sure they’re up to date this is no longer up to date this requires the use of a second serial port and assumes that you have a 4100 bought GPS device hooked up on serial three which is more accurate alright so you’re already defining the tiny GPS object here I also want to go ahead and define some other important things that we’ll be using first thing is a static chart call that we’re going to use as a character buffer to hold string data as we’re processing it so a buffer is just you can kind of think of it like a temporary holding place for information as we buffer it in from a received line or something like that so you’ll see where I’m going to use this a little bit later so that’s static char d2 STR buffer and we’ll use this a little bit for the line I’m going to make it 20 right now which means they can hold up to 20 8-bit characters in it and this is statically this is statically defined because of the way we’ll be using it a little bit later

which I’ll show you I also want to choose our SD card pin so that’s going to be C s equals 53 because that’s the pin I showed you earlier that I had hooked up to the SD card interface chip select pin we don’t really need to define the card tech panics we’re not going to use that but we should define our LED pin because we’re gonna use that for some debugging I’m just going to use the onboard led which you should all know is already hooked up to pin 13 okay so that’s the the next thing is I wanted to find some strings that we’re going to use to hold information that is coming in about latitude longitude and date times this will be like our global variables that are at any given time have the most recent latitude longitude and date/time information that will then output to the SD card I wanted to find these globally because I want to be able to update them in the called functions and then in the a loop I want to use them to write to the SD card so we’re going to define them up here so make the first one string SD date/time so the first string will have the date and time in it and I’m going to initialize these all to invalid values and the reason why I’m doing that is because as you saw earlier when you’re inside you don’t get valid values so we want to make sure that on the SD card we’re not just outputting garbage we’re going to actually write the word invalid to that entry on the SD card CSV file if we don’t have a satellite lock and that’ll make it really easy when we’re going through later to just delete the lines from the CSV file that we don’t care about and only graph the ones that we do care about so I’ll do this for all of them so we’ll do lat latitude and longitude to okay and that’s all really the information that I care about you could get other information like the number of satellites and stuff like that but the only stuff I want to save touristy card is this right now so I’m going to write one more string here called data string and the data string is basically I started off empty we’re going to concatenate the values from these three guys into the data string with commas in between it like I mentioned earlier four comma separated value files that will then actually write to each line on the SD cards log file so this is the data that string that will actually fill up and use to write data correctly okay all of our function definitions are still fine here they’ve just defined them at the top and then they read if they’re using them at the bottom these are called function prototypes okay the next thing we want to do is in our setup we already have our serial and stuff set up but we’re also going to want to make sure that we set up our chip select pins and our LED debug pin to be outputs so we all of course I’m going to do this already that’s pinmode CS output oops dispel pin mode correctly and pin mode LED output as well so the those are both says outputs now again add comments comments are your friend so this is the chip select pin for the SD card and this is the LED indicator these are our serial interfaces this is where we’re outputting debug information to the screen now before we do that I want to make sure it connects the SD card and is working properly so let’s connect to the SD card and this is all taken directly out of my tutorial on doing data logging I copied the code pretty much straight out of there so go take a look at that if you haven’t already so the first thing we’re going to do is going to say if the SD if it can’t begin in connection to the SD card we want to throw up an error and have the system not work because then we’re not gonna be getting anything that’s okay so make sure you declare the chip select pin so it’s going to try to begin a connection just on that chip select pin with the SD card and so I think it will do it this will do it but if it can’t for some reason then we want to have it kind of fail and cancel the program because then no it’s not worth doing anything else after this point so we’ll print some debug information to our terminal in the event that a computer is connected in which case we’ll say card failure it’s all busted debug issues if we run into them and we’re going to enter a return here which basically just kills the program where it stands all right the next thing we’re going to do is basically leave the setup the same here this is all still fine to prep the display will keep printing information it’s since we called Hart originally wrote the library it’s nice to keep his name in there or you can remove it do whatever you want it’s up to you and now we’re going to go into the loop okay so we’re going to have to modify the loop a little bit so that we can in addition to printing data out to the screen and coring the GPS we also

want to use a loop to write information to our SD card and like I said before we had this GPS this feed GPS and GPS dump functions that are grabbing all the information from the GPS the functions below here I’m not going to go into the full details of how they work but it’s grabbing all that information and then it’s printing out the serial we’re going to add information to these functions down here that save the current latitude and longitude to those global varies we defined earlier so if those are updating those global variables then when we exit the functions after calling them from GPS dump then we’ll go to the next part of the loop which will be to use those values that were just updated and to print those out to the SD card so right after GPS dump we’re going to write the newest information to the SD card okay great so I already mentioned this before we made that data string and this is going to be concatenation of all the values so we’ll go ahead and actually add the capturing for those values in a minute but for right now we’re going to assume okay those values the latitude longitude and date/time have just been updated and we now want to concatenate them all together into a comma-separated format and put those onto the SD card so the first thing we need to do is actually concatenate them so to do that we’ll put them all in there well use a plus sign for concatenated strings and make sure you put commas in between them so this is grabbing a date/time and then putting a comment after it and then we’re going to add the SD latitude and then after that we’re going to put another comma and then after that we’re going to put SD longitude so this is precisely what’s going to be written to the next line essentially on our SD card and we’ll use a print line statement to do that so it does put a new line after it so we have a one entry for each second that we’re grabbing data because this isn’t updating once a second the next thing we’re going to want to do here is update our status indicator LED so again we’ll get down to this in just a second but like I showed earlier I’ve been setting these to invalid when we don’t have valid data so we can actually just look at these strings see if they’re still set as invalid because that would mean that when we add them to the functions down here it hasn’t updated their values and if they’re invalid we want to keep it LED off and we’ll just turn that LED on when they’re grabbing valid data so if they’re ever being saved as invalid then we know we don’t have a satellite lock and our GPS unit isn’t doing anything so let’s actually check that using an if statement in a string compare so SD and you only have to check one of them because if one man is invalid all the other ones are going to be invalid so we’ll just check date time that’s fun and if it equals invalid that either means it still said is invalid from when I set its initial value to invalid up here or it means that in these functions down down below here where we’re actually up in those values in a minute we’re going to set them so that if they are getting invalid data it will change this back to invalid so whenever we have invalid data we can pretty much be certain that that will say invalid so we’ll keep the light off in that event so if it’s not invalid which is what I’ve said here we will turn the light on we don’t need to put a bracket here it’s only one line when you’re just writing one line in an if statement you don’t need a bracket so we’ll write the LED too high to turn it on and that will indicate to us that we’re grabbing valid data otherwise let’s make sure that we set it to off so digitalwrite LED low perfect okay so that’s that’s great so we have our LED updating to keep us up to date with whether or not it has a valid of satellite fix the next thing we’re going to want to do is open up our data file so that we can actually write to it and again this is right from my data logging tutorial so we’re going to open the data CSV file to do that we’re first going to make a new file type so we’re going to type in so we’re defining an object here file data file equals SD dot open and remember we named it earlier when we set up our SD card capital log dot CSV and we’re going to open it for writing so we use the file write definition again this is right from my other toriel okay so we have that setup for writing and now what we’re going to do is actually make sure that it opens successfully and if not we’ll print an

error out to the debug so if data file so this will be true if it was opened successfully in a file not fail then we want to print the newest string to it this data string that we concatenate it right up here from all the data that we’ll be getting so we defined our object as data file so I’ll write data file dot print line and we’re going to write the data string that we just concatenate it together okay and print line is ensuring that we’re putting a new line after it so there’ll be one entry in each line of the CSV file that has date/time latitude and longitude and for debugging purposes in addition to writing to the SD card let’s also do a serial print line out to the computer so we can see not only the nicely formatted data but the format of the data that has been written to the SD card so we’re bugging as we’re testing this we’ll be able to ensure that it isn’t in fact writing the data format that we expect to the SD card and then we’ll close the connection just like I did in my previous data logging tutorial now if we couldn’t get a connection to the data file the file is not there for some reason or something like that we want to make sure we’re aware of that so let’s put an elf statement that tells us about that potential issue and in that case we’ll just write out to the debug terminal serial dot print line I’m going to put a new line here so that it doesn’t go on the same line as as something previous backslash n just puts basically an enter or a carriage return but for whatever you’re typing and I’ll have it tell us couldn’t open the all right so now we’ll know if something went wrong there so we’re making great progress so now we have all of our strings set up and in the loop every second that it would normally just be outputting to the print line display or a terminal monitor it’s also going to open up the SD card concatenate together the most recent information about the GPS indicate whether we have a satellite fix or not by determining whether that data is invalid or valid and then we’ll write that data to the SD card which we can then use after to make very pretty maps the next thing we’re going to do is investigate a little bit more closely this GPS dump function and look at all the places where it’s grabbing data we want go look at those functions and add some code in those functions that’s going to allow us to extract the latitude and longitude data that we care about and the quickest and easiest way possible okay so looking at GPS dump let’s see if we can identify the things that we care about the first thing it’s writing is the number of satellites and then it’s printing a whole bunch of information things like altitude and course that we don’t really care about that much what we care about are a few things we care about the actual latitude and longitude so we can see that it’s getting those from GPS F get position and we’re also going to care about the date and time so in terms of things that we actually care about we see it has this function print float that’s MIT that’s printing out the float in a pretty format so this is our longitude right here or sorry our latitude this is our longitude and you can tell because F flat is float latitude and F LAN is float longitude and so they’re actually grabbing it from some functions that are built into the GPS library and calling the print float function to print them out to the screen so not being printed right here the function is printing them to the screen we also of course care about the date which is actually should more accurately say at the end time so this is the date and time so looking at this carefully we can see that in the print float function we’re going to want to go into the print flip function and if we’re trying to print out latitude also save it to the also save it to that global variable that will then get written to the SD card same thing goes for longitude and we’ll look at the print date function in order to kind of steal the data for the date and put it onto the SD card global variables that we’ll be using as well so let’s first go take a look at print float because that’s being used for latitude and longitude and we’ll only want to modify it for when it’s being used for latitude and longitude printing okay so print float we can see it it takes in a value which is the actual latitude latitude data that it’s grabbed from the GPS library whether or not it’s invalid the length of the information and the precision so what we’re going to do here that’s going to be kind of sneaky is we’re going to add in other argument to this function that allows us to determine if we’re trying to get latitude or longitude data well had another thing here called another integer and we’ll call it SD Val and this will kind of determine what we’re actually trying to grab so up up back here what we’ll do is we will add another thing that we can pass in so after that other information after those

other arguments that we see we can add another entry here that tells us what we’re trying to grab that we only try to output that to the SD card for that particular information so when we’re printing the longitude what we’ll do is we’ll make that a number two and when we’re printing the latitude we’ll make that a number one and so what this little complex information we’re trying to call and we’ll only do will only output at the SD card if it’s the particular information that we care about now one more thing remember they have function prototypes defined up at the top here so we’re going to make sure we want to up the update these as well so SD Val yeah that’s an integer and SD as well it’s just for print float I guess so we’ll update that now also importantly anything else that’s calling print float you can’t just leave that empty because the compiler will be unhappy so let’s just put in zeros here so if it’s a zero we’re just going to not print anything to the SD card so these are all using print floats okay I think that’s all the places are using it we can use a search to make sure it looks like we got all of them okay so back down to the actual function let’s modify it so that if it is a 1 or a 0 it outputs the correct value to that global variable that we care about so let’s see if we can figure out how this is actually working it’s defining a char array which is essentially just a string a bunch of characters strung together that’s 32 long that it calls s see if it’s been told that the information it gets is invalid and again this is coming from the library it will print out those stars which we saw on the the print line debug display earlier so it’s printing out all those stars if it’s invalid fine and it’s saving that it’s doing a string copy so it’s putting that into the SD variable now that’s all well and good we want to make sure that if it’s invalid that like we defined earlier it sets our SD card value to invalid as well or just stars is fine as well because we’re only checking invalid for date/time so we can kind of set latitude and longitude to whatever we want so we can see it prints out SD here so that’s where it’s actually printing it to the display so in addition to doing that if the SD Val is 1 and remember that latitude so if s DL is 1 then that means SC is currently holding the information about what the current latitude is so we want to save that to that global variable so we say if it’s equal 1 then we want to say SD lat equals SC so we’re just literally setting it to all stars again doesn’t really matter it just shows it’s invalid the only one we’re actually checking whether or not it’s invalid it to turn on the LED is date time so we have to make sure that that says the words invalid instead of just stars but for this this is fine so otherwise or else if well if the SD Val that we have input into this function is equal to 2 then we know we’re dealing with longitude so we want to say SD long equals SC and if it’s anything else just won’t do any of these so if it’s 0 like all the other ones then it won’t be writing anything to the SD card which is exactly what we want otherwise this is when Val is valid so this if statement was when it has invalid data or doesn’t have a satellite lock when it is valid we want to make sure that we’re writing the information that we want to our SD card so this is going to get a little bit more complicated and this is why I imported that additional library earlier so what we have to do here is deal with the fact that value is passed to us as a float so it’s a decimal number representation but what we’re printing out to the screen is we wanted to concatenate strings so not only do we need to just grab this float we actually need to convert it to a string and that’s why I imported standard live earlier so let me write it up first and then I’ll explain exactly what it’s doing okay so let’s investigate kind of what’s going on here I’m walking into the complexities of what he’s doing down here this is just making it formatted and look pretty to print out evenly on the display we don’t really care about that we do care about is grabbing this value of Val and making it a nicely formatted string so I imported standard Lib up at the top of this program up at the top of this program let’s take a look on the CIE reference online to see

what d2 STR F is doing so if we look online at the online documentation for C this function converts double passes a vowel into an ASCII representation that will be stored in s so if we look at the actual parts of it we can see here that these are kind of all of the parts so we have this Val which is a double or a float number the width and the precision so the width is basically determining the number of maximum number of digits before the decimal place and the precision is referring to the place the dots the places after the decimal place and then the string is that buffer that I was talking about earlier that is basically being used as sufficient storage space to hold this as we do the transfer so what’s happening here is we’re using that buffer that I define up the top which is more than long enough I think I made it 20 and this is 10 up to 10 total and then 5 after the decimal place and so this is taking the Val and converting it to a string that we have as SD lat so this function will save it into this global variable and then in the main loop will call this global variable and concatenate into a string that we can put on the SD card and then we do the same thing if the value is 2 except we’re saving it to the longitude value so that’s it for that it’s very very simple not too complicated and it easily allows us to turn the the float into a string all right so we really just have one more major thing to do here which is to deal with the date so we saw earlier that it was using this function called date to print out the the current date that it’s getting from the satellite so if we go down to print date we’re gonna have to make a modification here as well this function is only being used by the date so we don’t have to add another argument to determine when we’re being called into it but what we will do is handle printing so here it’s clearly printing this is the invalid string all those stars what we’re going to do is add a function in here where if it’s invalid we save SD date time to invalid as I defined earlier and remember whenever SD date time is invalid that means you know the satellite lock it also means the LED is off so it’s either initially defined to invalid or get set invalid in here when it does not have a satellite lock so that’ll handle that state correctly and now we also have to look at worth doing when it does have a satellite lock how was it printing the date and how we can kind of steal that to put it onto the SD card so the way we’ll do that is we’re going to rely on another function here so if we look at the else so this is when it is valid it’s again using this SC here and this is printing out all this information it’s basically all this % zero to D is formatting the each month day year hour minute and second in to a certain decimal format and printing it out into a string on the display so and then it’s saving it into SD for us so that’s convenient for us it makes our job pretty easy all we have to do is grab that SC for self and put it on to our SD card variable so SD date time equals SZ and that should be it so that’s a that’s grabbing all of the date/time values and putting into that SZ variable and now what’s going to happen is back up on the loop if we go look at the loop again were every time for the loop it does it does the GPS dump here which updates those global variables and then we grab those glow the variables in here write them to a data string and output those onto the SD card and that’s it we’re basically just hijacking the functions of this example script make our life nice and easy and grab all the SSD information from the existing print line debugger info so go ahead and save your file and get it uploaded at the Arduino and let’s take a look at what is happening make sure you have your SD card into now and of course I have a stupid issue here as the date time and there should be no space before the exclamation mark and the equal sign SD lon should be ello in this needs a bracket I guess it’s two lines once you’ve corrected all the stupid errors that I made and you upload it to your Arduino you should open up the serial monitor and we should be getting out only the pretty debug info but also each line should also have the information exactly it’s being saved to the SD card and we

can see that we are indeed getting that so we’re getting invalid for the date time and then stars and stars and these are comma separated values so that should work out just great so now let’s actually close this and load up the SD card into our computer so take the SD card out of your Arduino pop it into your computer and let’s make sure that we’re actually getting the data saved to the SD card so open up that file yes and we can indeed see that I mean it’s not useful data because I don’t have a satellite fix but we are getting the data written to the SD card exactly as we would hope it to be perfect good job so now we have our GPS unit and it’s logging the data to our SD card the next step is we’re going to take this data obviously go outside walk around turn the Machine turn the GPS on it’ll turn the LED on onboard when it is indeed connect to a satellite to make it easy for you to tell and then we’ll start to gather some data and I’ve already gathered some example data which I showed you at the beginning of this video and now I’ll show you how to take some example data that I’ve already taken and get it up on Google Maps or on Google Earth to plot it out once you’ve gone around and acquired some awesome data go ahead and open it up on your computer I have some sample data that I took in Washington Square Park in New York City walking around so go ahead and open that up that’s what I have here I’ve already gone ahead and deleted the invalid row entries because those aren’t obviously not useful to us I’m going to insert an additional column at the top that gives us some more information and tells us what each column is so date / time latitude and longitude and this will just allow us to import more easily into Google Fusion charts which we’re doing a second so once you’ve done that do a save as with headers okay make sure you keep it as a CSV file because that’s what Google will understand yes to replace it yes again and close out of that next login to your Google account as of right now this is beta functionality that only works with default actual gmail accounts you can’t use it on a Google Apps domain yet go to your Google Drive up here and then click on create go to more then choose table which is a beta option next you’ll choose to upload a file from this computer we can see that it wants CSV files we’ll choose the one that we just did with headers hit open all the default options are fine hit next okay and we can see it’s imported the table quite nicely the column names which we just added are in row 1 which is correct hit next again you can name this something so this is a test of my GPS we can allow export that’s fine if you want ahead an attribution link do that otherwise this is all good so I didn’t finish okay and we can now see that it’s imported the entire table into Google Drive into Fusion Tables beta program so now this is actually surprisingly easy hit visualize choose a map it automatically figures everything out and will map it for you instantly it zooms out very far for whatever reason but I can zoom in here and sure enough this is all the data so if you’re watching the video at the beginning I started recording sitting on a bench over here walked over to or I started a start recording GPS data over here walked over here to the fountain this is where I started filming and that sped up portion that I showed as me walking around here like this I got back to the fountain turned off the video camera and then walk to nearest intersection to start heading home and that’s basically this is imported you can do whatever you want with it you can do all kinds of cool stuff I won’t go into all of it now one particular thing I will say is that you can download the kml kml a sling that you can import into google earth and if you notice at the beginning I showed a virtual fly-through of what I was doing so I can export this KML file and then if I want I can go open up Google Earth and open up this KML file and do a visualization of it in Google Earth which is actually pretty neat I won’t go into all the things that you can do with it from there there’s quite a bit but you can definitely go experiment with this you can do things like attach photos to different locations things along those lines you

can also just go to file open and look at the data set that we just exported so I put mine on my desktop so this is my test hit open it’ll add it over here and zoom on into it and sure enough there is our test data you can see actually two of mine overlaid on top of each other because I’ve already imported this before so I’ll turn this one off there we go so that’s what we just imported you can mouse over each one it’ll tell you the time latitude and longitude that you are at that particular location and you can make all kinds of adjustments to it and do fly throughs and stuff like that so that’s it that’s how you grab deep GPS data now you log it to an SD card getting on your computer and do some really awesome visualizations thanks for watching my latest Arduino tutorial I hope you guys enjoyed it don’t worry and working on more of them I’m sorry but they take a really low long time to put together I’m sure you understand as always you can get all the schematics source code sample data etc on my website on element14.com and on the links in this YouTube video you can also find them on my github page if you need to get in touch with me the fastest way to do so is through Twitter my username is Sai guy 14 same as my YouTube username and if you haven’t already to go check out my recent tutorial series on Eagle which teaches about schematic design and PCB board layout okay thanks again for watching and help see you guys soon thanks to element14 for helping me to sponsor this video series they were kind enough to provide a lot of the materials that I’ll be using to create these tutorials feel free to go visit their website at element14.com check out their community which is a great place talk to you about electronics they already know and basically anything else engineering related and that’s all the store where you can buy a lot of the parts that we’ll be using in these videos Oh