[adrotate banner=”7″]

We have an exciting project today. It is an extension of lesson. 22. What we’re going to do today is we are going to create a GPS data tracker and the way this works is is that you’ve got a GPS. We are using the most excellent Adafruit ultimate GPS, connected to the Arduino and we are using the virtue of boat X, SD card reader writer, and then we are going to power. The whole thing with a dandy rechargeable battery, and so when we get this thing programmed up to plug the battery in walk around outside and it will constantly be logging, our position, our GPS coordinates and then, when we come back inside, we can take the SD card Out pop it into the computer, and we can see where we have been using Google Earth, and so this is a pretty pretty exciting project and we are going to jump right into it and get started. The first thing that you’re going to need to get started. Go ahead and the easiest way to get this information is to go to top tech boy comm my website, and when you go to that website, you can look for Arduino lesson: number 23, okay, Arduino lesson number 23 and what you will need to do. You will need to connect up the GPS. Let’S see let’s talk about where you can get this stuff. I’Ve got links here of where you can get your Arduino, the ultimate GPS, virtu, a boat X, SD card reader, the battery clip and the 9 volt battery system, or you can hunt around and see see where you can find this stuff.

But these are the these. Are the specific units that I’m using okay you’re going to need to hook your GPS up for easy connections to get the GPS hooked up to the Arduino Uno v into 5 volts ground to ground our x2 pen to our x2 pin 2 and tx2? Pin 3 you’ll also need to hook up your virtue of bow ticks data logger, and you can use that as follows. Ground to ground ground from the SD card to ground 3.3 volts is not used because we’re going to connect with 5 volts 5 volts to 5 volts the cs chip select on the on the SD card to pen for mosy on the SD card to pin 11 Sc K to pin 13 miso to pin well Vaughn the Arduino and ground to ground so there’s a ground on both sides of this just to be safe. I hope both of them up to the Arduino, because you’re powering a lot of stuff here, you probably need to create you a 5 volt rail here and a ground rail and then just hook your 5 volts into here and hook your 5 volts into here and Ground and so that you have plenty of connections for ground and 5 volts, because our circuit is starting to get pretty pretty complicated. Okay, we need we need to go ahead and get the food that we developed in lesson 22 and if you haven’t gone through lesson. 22, you need to do that.

You can go to top tech boy, comm go to our dueo. Lessons come down and you should see lesson number 22. And if you go to lesson number 22, you can catch right up to where we are word here. Is the code we can click this? We can copy this code. You need to go in and develop this yourself, but I’m, assuming you’ve already done that on lesson. 22. So you can just jump right in what you had before and then we start with a nice new Arduino development environment and we come in and we paste our code from lesson. 22. If you remember what we ended up with on lesson 22, we just kind of got to the point that we could talk to the GPS, and then we were just sitting there and we were printing out our GPS. We were printing out our NEMA sentences, okay and so just very simple. We were just printing out our NEMA sentences and we could see that we were. We were getting those NEMA sentences off of the GPS and then we were. We were printing them out yesterday or on lesson 22. We didn’t actually take the thing outside and walk around with it, because if we did that there would be no way to see what the data look like so that’s. What we’re going to do today today can do that because we’ll have the data logger and will have the battery where we can actually walk around outside, but there is a little code that we need to develop before we can on before.

We can do that and mainly what we’re going to be doing today is we’re going to be taking the code from lesson 22 and we’re going to be getting that that SD card working. I think it was in Lesson 21 that we learned how to do the SD card reader and so hopefully already have your card reader. And hopefully you can recognize this stuff and in fact figure out most of it for yourself, since we have already kind of kind of done most of this in in our earlier lessons. Okay, so let’s just jump in here and start doing our code. If we are going to use the SD card, reader we’ve got to load the SD library. The good news is the SD card. Library is already it’s, something that comes with Arduino, so you don’t have to install it. You just got to load it into the sketch. So we go load sdh or include SDH and on that is simple enough load. The SD card library right. We also the SD card needs to use the SP ie, the serial, peripheral interface, library and that’s, just a way for sophisticated components to communicate to each other and so we’re talking between the SD card and the Arduino using SPI, which is a very useful protocol. H. Okay, remember in this unique case of loading, our libraries we don’t put the semicolon: okay load, the SPI library, alright, remember that you’ve got to install this Adafruit library and you can go back to the earlier.

I think the previous lesson 22 to see how to install this library, so you can’t just load this one because it doesn’t come with the Arduino. You have to actually install that library. Lesson. 22 will show you how to do that. Okay, we come down here. The rest of this looks pretty good. What we are going to need to do is to find a few variables for using the SD card reader. A remember. We have to tell it where our chips select is connected and we connected the chip, select, a pin for okay chip, see luck is connected to Arduino and for okay, and we have to have a file object because we have to treat this SD card reader as An object, so we have to have a file variable and remember: we’ve done is we’ve done, strings, we’ve done floats, and now we have a variable type of file, which is very good for interacting with files and we’re going to call it. My sensor data, okay, the file name that we’re going to use is my sensor data they declare variable for reading or for your SD card object. Okay, so that’s just a convenient way that we’ll be able to write to that file and read from that file. By having an object, name, that’s of type file, okay, so that’s pretty good. Now we come down here and we are setting up our GPS and we also need to while we’re in the void set up.

We need to set up our SD card and, if you remember there are some quirky things about this card, that it wants to have 1010 reserved as an output and not use for anything else. Even if we’re not connecting to it, must declare and ten and output to keep SD card reader happy. Okay, sometimes you just go with it, whether it makes sense or not. Now we need to turn it on so it’s called SD because that’s, what the library is. We do an SD begin, okay, and we want to do an SD begin and we got to tell it where we’re connected well. Where are we connected? We are connected to chip select okay, so we got to tell it. Chip select and chip select is for. I guess we could write for in or because we’ve got the chip select connected to four but it’s just better practice to use our variables okay, so we initialize our SD SD card and say it is two chip select all right, so that looks good let’s see. Ah, there’s a there’s a couple of things that we’re going to have to jump right into here. What we want to do is remember that we’re creating a file and we’re writing the file here and when we open a file on that SD card. If we open a file, if the file doesn’t exist, it’ll create it, but if it does exist, then it appends data to it and the problem with that is that you end up with all the old data from your earlier experiments or your earlier walking’s around and So i want to just take a second here and if the file is there on the SD card, i want to erase it okay.

If the file is there, I want to erase it so that then I start with a clean, fresh file and I get rid of that old data. Okay. Now this is a couple of new commands that we’re going to learn is we can see if a file is there? We can do that by saying. If SD SD dot exists, okay and what file are we looking for we’re going to hold our data in mm? A dot txt all right and actually we’re going to have two data files. I always like to. I always like to store my raw nema sentences, because, if anything goofy ever happens, you can go back and look at those nema sentences and you can see your raw data, so I always like to have one file where I’m just dumping those nema sentences too, and So I’m checking to see if that nema dot txt file is there and if it is there, okay, okay, we’re going to check and see if nema text is on 50 SD card, if so Akili ticked. So this is the start of my if statement. Let me end my if statements I don’t forget to do that so open curly braket to start the if statement close curly bracket to end it and then what do I want to do inside that? Well, if it’s there, I want to SD dot, remove it and to make sure I get it in here, right I’m, going to copy that copy and then I’m going to paste it like that.

So if it’s there remove it okay, so that will get rid of the old file. Now I said I had two files, so I want to do this for the second file as well, so I’m going to come down here and just copy and paste. So I take those three lines and I copy and paste I’m going to do this for my second file and my second foul I’m going to have is GPS date, uh dot, txt, GPS data, dot, txt, and I will copy and paste that alright and what I Do is in this nema file, we’re, going to save the raw nema sentences and in this file, we’re going to save our generic parse. Gps coordinates in elevation, so we’ll have two different files, so I want to check and get rid of both of them before I move on. That looks pretty good, so we’ve got our we’ve got our things going there. Now we come down to our main loop and we’re, going to read the GPS and remember this: read: GPS is a function that we created and what it does is it goes in and it clears the GPS and then it reads in two good sentences and when It gets to good sentences, it pops back up here. So when we get to this line in the code, we should have two good GPS sentences and they should be parsed because we parse them as well right. We said GPS, GPS parse, and so that once we parse them down here, then that opens up some new commands that we can do up here.

But one of the things is is that we don’t want to do anything if we don’t have a fix yet and a fix just means. The GPS sees the satellites. The GPS sees the satellites and is getting good data. Okay and it’ll spit out empty NEMA sentences. But we don’t want to save any of that data until we get good Chi, good GPS data or get a fix, and so what we do here is we’re going to look and we’re going to say: gif GPS dot fix equals equals one. So what happens? Is GPS? Dot fix is going to be zero until we get a fix and once it gets a fixed, then GPS, dot fix is equal to one and so we’re checking. If GPS dot fix is equal to one, then we are going to look we’re going to go and we’re going to do all these following commands. And so let me go ahead and start my if statement and really everything is going to be inside here, because we don’t want to save any of the data or do anything unless we have a fix, and so what this is going to do is like right. Now, if you look at this red light, blinking kind of on and off that does not have a fix and I don’t have a fix because I’m inside and you can’t see the satellites through the roof. But when you have a fix, this thing will just blink like once every 15 seconds.

So when you walk outside watch that red light and when it just blinks once every 15 seconds that tells you you have your fix and then once it has the fix, then you want to log the data. Okay, so only log data app after you have a fix right. So when I am here now, I put a little white space in here, while I am here I’m going to have a fit fix, and so what do I want to do? If I have a fix, while I want to write the data to the SD cards so I’m going to open my first file – and we called this file that we’re working with up here, the file tap is going to be my sensor, data, so I’m, going to Say my sense or theta is going to be equal to what do we need to do? We need to open the file open st dot open, and then we got a tell it put. The file name is n m e, a NEMA dot, T X, T, okay and remember that’s the file that we erased up here, so we’re going to be starting with a clean file. Now, when you do an SD open and there is not that file name, there it’ll create it. So, even though you’ve erased it it’ll create it here, the first time through and then how do we want to open it? We want to write so we’re going to have a file right, and so that just tells it that when you open it, you want to open it for writing.

Okay, so we’re going to open nema txt for writing all right. So now that we have opened it. What do we want to do? We want to write those two sentences. Remember in the earlier lesson, when we do this GPS read we get to GPS sentences, enemy a 1 and M nm e a 2 one of those should be your RMC sentence and the other one should be your GG a sentence. So we should have those two sentences and we want to write them to the data file so I’m, going to say my sense or data, ok, dot print L in because I just want one sentence per line and I’m a print in a one. My first sentence right first sentence, QV SD card, okay and then I’ll just copy and paste this to make it easier control, C control, V and then I’ll write my second enemy, a my second name, a sentence to the SD card: okay, I’ve written those things. I’Ve got to always remember to close my file so I’m, going to close this file object out dot C oose like that. Okay, close the file all right so that little bit of data right there is going to is going to write is going to write the data to the odd to the right, the two nema sentences to the SD card. But in addition to that, what I’m going to want to do is in addition to that, I also want to put the parsed data to a different file and remember when we came down here and in our void GPS read when we do a GPS read, we Actually come down and we parse the data, we do a GPS dot, parse of the GPS last nema, and what that does is that opens up all these new commands in that library, where I can just go out and I can grab things like grab the latitude Grab the longitude grab the altitude okay, I can just go grab those things and so that’s very useful.

So since I parsed it down here in the since I parsed it down here in the void, read GPS function, I can come up here and I can just start writing new stuff to that other file. But if I’m going to write new stuff to that other file, the first thing I need to do is open it. So I need to do Hisense license or theta dot B. My sensor data ah is equal to and make sure I spelled it right. My sensor data is equal to. I got to open the file again SD dot open, but I don’t want to put it in this Nima text file. I want to put it in a new file and what I’m going to call that new file is GPS data, dot txt like that, and how do I open it? I’M, alright, so I’m going to say file underscore right, because I want to open it for writing. Okay, and so what this is going to do, is I open the GPS data dot txt file on Gus SD card? Okay? I think that would be good now that it’s open. I can write it so I’m going to say my sensor, data dot print, and then I put in here what I want to print to it: okay and what the command I want. This is what I want to print. I want to print the latitude and then the comma and then the longitude okay, I get the latitude by getting GPS dot latitude.

I get the longitude by GPS, dot, longitude and then also one of the quirky things is. Is that it’s not just the latitude? The number you also need to know which hemisphere you’re in north or south, on latitude and east or west on on longitude, and so we need to. We need to print those things out as well and so let’s just start. First thing that we want is to print the GPS dot flat, kick okay, and what we got to be sure is: is that normally, when you do a print, I think it gives you two decimal places well, that latitude number is going to have four decimal places. So I have to click the comma four there just to make sure that when it puts this on the SD card, I get all the data that it doesn’t truncate it because on these GPS locations we want it to the very last very last decimal point. So we’re going to write, write latitude to the GPS yeah to the G to the GPS file, all right now, my sense or data print. We got to tell it which hemisphere it’s, since we do GPS dot and to get the product, whether you’re in the end or the on latitude, yeah it’s. In or s you just do L, eighty and that will get be either an N or an S, okay, which I can this fear you are in, which will be an N or an S.

Now we want to be my sense or and notice how I’m putting this all on one line because I’m doing prints, because I want this one. I want latitude longitude and altitude all on the same line: theta dot print now I’m going to do cheap, GPS dot. One one one, two, two, okay and I want those four decimal points on that as well: okay, so right longitude to the GPS file, now my sense or data dot, still on the same line: print GPS, dot, L, o N, and what that’s going to be. As that will either be at E or a W okay for east or west, and you need this information because we go to put this stuff into Google Maps. It wants to see where you are north or south, east or west, so ah, which camp in this year you are in this, is east or west, like that, okay, I I think I forgot to do something here. I forgot my comma so after I did latitude and lat. I need a comma in there. Okay, after after that, I need to do just a nice since my since org data dot print and I need to ah print the comma comma, like that, right, comma and now I’ve got longitude and lon okay. Now I need another comma, my sense or data dot print and now what I’m going to need is aa g, p s, dot, elk, okay and that’ll just pop that altitude right in there right altitude, okay, now I’ve written all the things.

I need to write. What do I need to do? Hope you remember to close the file. Believe me, you have more problems because you don’t close your files, at least speaking of the students that I have oftentimes forget to close their files. Close, your close, your file, all right, okay, so let’s! Look at this I come up. I read the GPS. If I have a fix, then I want to write all of this data. I open my NEMA file. I write my NEMA sentences and I close my NEMA file. I open my GPS data file. I write my latitude, then the which hemisphere I’m in I write the comma. I write the longitude. I write the lon which hemisphere I’m in and oh, I need a comma in there between those two. So I want a comma between my longitude and the altitude, so I forgot to print not print and I need a comma and also when I get to this. This is the last thing on that line it’s how I want to go to a new line, so I need to prove the print null in there. Okay, so let’s see if this thing is going to work here, let’s see if I made any mistakes, let’s go. No, I didn’t mean to do that. Let’S go like that. Oh, what is it not like? Ah up here on this, I forget forgot my colon semicolon there did you guys catch that? Hopefully you did as I was going through it.

Hopefully you were yelling at the top of your lungs. It need to put my semicolon in there. Okay. So now it looks like it’s going to compile. It looks like it’s going to download and let’s hold our breath. I hope I don’t have a serial monitor, open yeah. I took it okay. So now, if I look at the serial monitor, I think I should see let’s see. Oh yeah, I have the print statement down in the this isn’t. Those rights we just did but remember in that GPS read, I had a print statement and so we see an ans see an anus II and anus II and AM se and ans see and so we’re sitting here, we’re sitting here reading these Nemo sentences – and we Are getting a good, a and a good C, and all these look like good sentences, and so this all just looks really good so I’m going to go ahead and close that so now guys what’s going to happen I’m going to go outside and I’m going to Walk around so I’m going to unplug this from the from the computer, all right, the programs already down in it so now I’m going to take my little 9 volt battery, and I will get this where you can see it. And then you see this right here, that is for plugging in the 9 volt battery and then, when I plug it in what you can see is the Arduino has come back to life and the GPS has come back to life and I am completely mobile.

I am free to roam around the area, so what I’m going to do is I’m going to run outside? I will pause the video run outside and then continue the video and then we’ll we’ll. Look at this data coming off of here. Right now. I don’t have a fix right because that LED is inking fast. I don’t have a fix. The red LED is blinking. I don’t have a fix so there’s, no data being logged right now, but as soon as I go outside it’ll take about 30 seconds to get the fix and then I’ll walk around and then we’ll come back in and see. If we can see that data. Okay. Okay, okay, I am back in, I have been outside walking around brought the unit back in. You can see that we were operating on battery power alone and what I’ve done is I popped the SD card out. I can stick it over in the computer II and let’s open that SD card up and see what we can see in there. Give me just a second here, so I can pop it open, and what we can see is is that there’s, two files and it’s the two files we created nem a dot txt and GPS data. This one should just have the NEMA sentences. Let’S take a look at it, we pop it open and sure enough. This is the MC and the are MC sentence in the GG. A sentence are MCG, GA and so we’re sitting there and we’re grabbing one of each type of sentence and we’re dumping.

It here to the SD card, if you can remember in our previous lesson, our nemo sentences were empty. They had a bunch of commas and zeros, and you can see here when we went outside and actually got a fix, we’re now getting data. This represents the time. Thirty fifty one point: seven eight, eight zero North is our latitude and then our longitude, and it shows that we’re in the northern hemisphere, the western hemisphere and so there’s all types of useful data in here. But this data is kind of hard to read. We just like to keep kind of the raw data. The better data should be in our GPS data txt file and if we open that, ah look at that, we have latitude and then northern hemisphere, comma, longitude and we’re in the western hemisphere, and look at that. Our altitude and meters and so let’s check that altitude and see how that looks. It says that I’m at 779 meters – and so what I can do is I can come over here and I can say 779 meters in feet and that saying that I am at an altitude of 25 55 77, which is very close to what my known altitude Is at this location, so this is really neat. I went outside and walked around a little bit and I got these sets of coordinates, but how could we use these coordinates in Google Earth so let’s open up our Google Earth takes it a second to get open and I think I’ll close that and then get This the nice size where you can see it, okay, so let’s call back this and of course right now.

We don’t want to be putting altitude in there we’re not quite ready to do that yet, but let’s just get these two okay, so I’m getting the latitude and the longitude. I come up here to Google Earth and I paste it in and I say, search and it says I don’t understand this. Okay and I’ll explain to you why you don’t understand it that the way this this comes out of the Nima sentence is the 30 represents degrees and then the 50 one point: seven nine three is minutes, so it’s 30 degrees, 51 minutes. 7950. One point: seven, nine! Three seven minutes in the northern hemisphere. This would be a hundred degrees in 36 minutes. So when you find the decimal point and two to the left of the decimal point, is minutes so that’s thirty, six point: oh two, seven three minutes and a hundred degrees and Google doesn’t understand this nice long thing here. It wants to see a space, and so that looks to Google like 30 degrees. 51 point, seven, nine, three seven minutes, and similarly here the two by the decimal point are the minutes. So I come over here and this is a hundred degrees, so it’s always two to the left of the decimal two to the left of the decimal. And then I had a hundred two to the left of the decimal, and then I had 30 and now let’s put search and look at that. It looks like it’s coming to Texas.

It looks like it’s coming to my location here and if i zoom in this is exactly where I went to walk around now see exactly where am i Here? I am right here I mean this is actually right at em I’m in this building the school and I came out – and I came over here to stand in the shade and I rested in the shade for about 45 seconds. While it was getting a fix and then I started walking around and so let’s see, if we can see me walking around a cop, I don’t want the altitude so I’ll just copy this and then I’ll come in. I paste it and remember to to the left of the decimal oops so that’s 30 degrees 51 to the left of the decimal 100. Okay – and you can see I got here and I started walking around the courtyard. A little bit. Let’S come down and get one of the get one of the later ones and what it should be is. I should just be kind of continuing to walk around in the courtyard some copy. Okay and then you can see what I did was I walk from there back to the back door, and then I went back in and then once I went back in it lost the fix because the ceiling, the GPS can’t see it. So this is just really neat. We now have a device that we can walk around with and it will log our position as long as this little GPS has a clear view of the sky, and I think this is just really really slick.

We can come back and then we can plug those coordinates into Google and we can see Google Earth and we can see where we were. This is just really really really neat. I’Ll tell you what I hope is. I hope you will come back for the next lesson which what I think the next lesson is going to be like lesson: 24, all right, yeah let’s see this has been. Ah, we are presently on lesson 23, and so, if you come back for lesson 24, what I’m going to do is I’m going to show you the you know, kind of like the the little bit slow thing about this. Was we have this this? This data file that has all of these coordinates in it.


[adrotate banner=”1″]

Paul McWhorter arduino lesson 31 Video

[mam_video id=TdXbP8XhbX8]



[adrotate banner=”2″]


[mam_tag id=5626]



[adrotate banner=”3″]


Paul McWhorter arduino lesson 31 news






[adrotate banner=”4″]



Paul McWhorter arduino lesson 31 Social



[adrotate banner=”5″]




We’re opening the Arduino IoT Cloud to other platforms, starting with the ESP8266 by Espressif Systems — NodeMCU, SparkFun’s ESP Thing, ESPDuino, and Wemos (to name a few) — along with other inexpensive, commercially available plugs and switches based on this module.

How fast can you run the 40-yard dash? Find out with your own wireless timing gate system.


[adrotate banner=”6″]