Paul McWhorter arduino lesson 22


Our very own GPS, tracker now I’ll be honest with you. This is actually going to take two lessons, so we’re going to do the first part today and the second part tomorrow. What we’re going to do for today, where our goal for today is, is to get the GPS hooked up to get the circuit hooked up and to have it streaming the data to us so that we’re getting that position data coming off of the GPS module. Then, tomorrow, what we’ll do is we’ll finish up the program where we write the parsing program, where we parse the data and store it in a useful format on an SD card, but for dead today, let’s get this thing. Hooked up and let’s get some good data. Coming off of it, we will be using the most excellent at a froot ultimate GPS, breakout Version. Three okay, you can pick this up. I you can pick this up for about forty dollars and there are several reasons we use it there’s a lot of these GPS units in this price range. The reason that we like the Adafruit one is that you probably know that myself and my students do a lot of high altitude ballooning where we develop instrument packages and send them to the edge of space, as you can see, with the picture back here, send back Data send back pictures. The thing is most GPS stopped working above 60000 feet and they stopped working because the GPS manufacturers miss read the government regulations on GPS equipment and they turn them off when they go above 60000 feet.

The thing about the Adafruit unit is, they have correctly interpreted the government regulations which will allow you to have a GPS working above 60000 feet on a slow moving object. The balloon is slow, moving object and therefore it is perfectly legitimate to hook a GPS up to it, and so the neat thing is is that this Adafruit unit is one of the few that really work at very high altitudes. I will say in some of our launches: we have taken this little unit up to altitudes of 120 to 130 thousand feet and have had it performed flawlessly at those very, very high altitudes, and so, if you’re thinking about doing high altitude ballooning. This is a great GPS unit as well as it’s, just it’s, pretty good for just any just about any application, so that’s why we chose this particular particular unit. Now, if we are going to do this there’s a little useless there’s a little bookkeeping, we need to take care of right off the bat Etta fruit provides a very nice library to help do some of the hard work for you in developing software for this. So we need to start by downloading that the easiest way to do that is to go to my website. Www.Wefeedtheplanet.Com go GLE, Chrome as I am. It shows up down here, the zipped folder. If you are on a different browser, you will go have to hunt for this in your download folder, but for us we can just click on it and it will enough the folder.

It has opened. The zip folder. The folder we want is the folder inside the zip folder, so don’t just drag the zip folder to your desktop. You want to open the zip folder and then you want to get the folder inside the zip folder and drag that to your desktop. Ok, then, once that is to your desktop, this is the library we want to rename it so we’re going to come in and I am going to rename it. I just like this. Take that off add a fruit where that is, you want to underscore Adafruit underscore GPS like that. Okay, we need to put that in our library folder. Well, where is our library folder? This is the easiest way to find it, and this should work, no matter where you have it installed. You come to your little Arduino ie, you come over here and you look at preferences under file, and then this shows you where your sketchbook is and inside your sketchbook. You should see a library folder. Well, what I can do is, I can come over here and let’s just say I open up a folder like. Let me just open up any folder. Let me go to my computer and then let’s just sort of navigate. There let’s go back and look at this window and let’s kind of navigate there, so you can see that it’s under users, my name documents arduino. I could go sort of one by one on that let’s just do it one by one let’s go local disk.

I said should see something here that says users and then I should see something that has my name there. It is and then I want Arduino okay or I want documents, and so we come down to documents in my documents or synonymous, and then there is the Arduino folder in boom. There is the library folder. We want to drop this inside that library, folder. Okay, let me show you another way to do it. Let me just go back to a computer, I could get this and I could copy this controls that come up here to this bar and paste it. And then, if I go boom, it takes me there as well so that’s, two different ways that you can do it and we now have the library loaded very important for you to be able to see that library. You have to kill your IDE, your integrated development environment and then you have to open up a fresh one: okay, because it’s, when you open up that fresh one right here, all this business it’s going out and it’s looking for your libraries and so now. If I tell your under libraries, there is my Adafruit GPS library. So now the library is there. That is a good deal. Okay, that is very good. Now let’s go ahead and let’s hook, let’s hook this thing up, so let me find where we, where we went here, let’s go back to WWE boy, calm. We are on lesson 22, okay.

So what we want to do is we want to go ahead and just sort of see if we can hook this up now. The interesting about this particular sensor is, is that once you put power, but it starts streaming, data, okay and that’s kind of like a good thing and you’ll see in a minute it’s a little bit of a bad thing. It creates a challenge for us as soon as you turn it on. It starts streaming data so let’s see if we can get this thing hooked up the way you hook it up. Is you come over here and you should see a pen that says VN? Okay, the VN pin or Mon is over here almost to the left you hook, VN to volts on the Arduino ground goes to ground, okay and what we’re going to do to start with now, just to sort of see if it’s working? What I want you to do is I want you to ignore what I say here: okay and we’re just going to see if it’s working. So I want you to take the TX, pin the the rx pin I’m. Sorry, the rx pin is next to ground and I want you to take the rx pin and I want you to hook it to pin 0 okay, the rx pin to pin 0 on the Arduino, and then I want you to take the TX pin, which is Next to it, and hook it to pin 1 on the Arduino, ok, so our X to 0 and our and TX to pin 1 all right.

And what that should do is that should just stream the data that’s coming off the TX Rx data off the GPS, and it should just throw it on your serial port. Ok, so let’s see if that works. So what we I need you to do is I need you to open up an integrated development environment like this that’s. Just blank avoid setup with nothing in it avoid loop with nothing in it and then download that to your Arduino. Okay, you get that downloaded and notice. We haven’t loaded any libraries, we haven’t done anything but just connect power and connect to those serial. Those receive transmit pins and if I hit this – and I need to set this back to 9600, which is probably where it’s coming through yeah. So what I want you to see here is this is the data that is just streaming off of that GPS module and what these are called is. These are called NEMA in EM e. A sentence is in these: each line is one sentence, and each lineman has data about what your location is well I’m, going to stop this for a second, so that you can see it and there’s a couple of things that we ought to talk about here. Each line is one NEMA sentence and each NEMA sentence has various data that’s very useful and informative to you. It has things like what time it is. What is your latitude? What is your longitude? What is your altitude? Do you have a fix? How many satellites can you see the quality of your fix velocity, all types of useful information? All right now, if you look at my names sentences, what you see are a bunch of commas and a bunch of zeros and that’s, because because I’m sitting inside I cannot get a fix because I’ve got a big roof over me, I’m.

Not getting a fix so it’s just streaming empty NEMA sentences, but what this is saying is it’s, saying that the GPS is nominally working and it’s talking to the Arduino and it’s streaming this data out. What I want you to see is: is that there’s different types of NEMA sentences, I have the dollar GP, they all start with dollar GP, but I have dollar GP and then I have the RMC sentence. And then, after that I have the GGA sentence, and then I have the RMC sentence and I have the G see a sentence. I had programmed this up earlier to only show those two sentences if you’ve just just turned your GPS on for the first time, you probably see a whole bunch more than this, but one of your goals is going to be is is to just get it down To where it’s only streaming, these two sentences, because for most applications for high altitude ballooning and for most applications that I can think of all the data that you will ever need is in the GCE a and the RM see sentences. And so what we’ll be trying to do is to get it where it only sends those two sentences out, but the neat thing is: is that you can see without writing any code at all. This thing is already stringing data and if I took this outside and set it with a clear view of the sky, you would start seeing data coming through here that, ah that would have position, information and other neat and useful things like that.

So this is the neat thing is that it just sits there and it disputes this data out. The problem is that it just sits there in spews the data out so let’s say that I write a program and I’m off doing something else. Well, what I’m off doing something else is spitting all this data at me, then, when I go to read the data off the serial monitor, the problem is: is that that data might be old because it might have been? You know, data from ten minutes ago. That was the first data in and then it filled up the serial port buffer. It filled up that buffer and then, who knows what’s happening. I have either old data or corrupt data in that serial buffer it’s. Not you would like it to be more of a client server type of relationship where the Arduino could go out to the GPS and said, send me data and then GPS says here’s your data, you ask where’s the data and it says here’s your data, but no The GPS does not listen, it’s just sitting there. Just throwing data at us and we’ve got to keep that in mind when we develop the software, because I’ll tell you I’ve really struggled with this part and in our high altitude ballooning work we found many times. We were ending up with old or corrupt data in that serial buffer and so we’ve got to make sure that we are mindful of the fact that this thing is constantly streaming data.

And if we go away and do something else with the Arduino like the Arduino goes away and reads pressure or something like that comes back, tries to read that serial monitor the data could be old, the data could be corrupt. We can fix that, but we’ve got to keep it we’ve got to keep that in mind as we’re as we’re doing that. Okay, so that just shows that if I connect TX and rx to Penn zero and one which are sort of like just a little direct path to your serial to your serial port, I can just stream directly from the GPS into the serial port. And I can display it, but we want to be able to program and we want to do a little bit better than that, and so we need to go out and we need to connect rx to pen, two and tx2 pen. Three be sure to do this. So I’m, coming over here and I have I have a TX I’m going to put on, pin three. I got to look very carefully and then our X I’m going to put on, pin all right just like it says here so now. What that’s going to do is we’re going to have to load a library called software serial, so we’re going to create sort of a new serial port on pins two and three and we’re going to be talking to them on this rx TX Rx TX protocol.

All right so what’s up let’s start developing our code. Here, let’s get our code going so open up a new window and there’s some things that we are going to need to do. First of all, we’re going to have to load some libraries in here there’s several libraries we are going to have to include, which is how we load a library and we need our add a fruit underscore GPS, dot H. That is, that library that we just installed. Okay, that is, that library that we just installed – okay, so let’s, say install the PATA fruit, GPS library. Now we are going to have to include let’s fill it right include and we need the software serial libraries, software serial dot H. I better put a comment here. This is not going to be happy make it a comment: okay load, the software serial library, okay, what the software serial library does is allows you to create kind of like a new serial port over here on these two pins, so that that you still use your Normal serial port for normal things – and you created another one over here to talk to the to talk to the GPS. Now that we have loaded that we need to create a software serial object, so we’re going to say software serial, okay and let’s call it my serial and what we’re going to do is we’re going to tell it how we’re talking to the GPS? Well, where do we want that software serial? Where do we want it to show up? We want it to show up at pins three and two okay, three and two.

So this is telling this is setting up that that new serial port and we’re telling it that we connected to the GPS on pins three and two okay, so we’re going to get that set up. This is a mystery initialize, the software serial port. Okay. Now what we want to do is actually create our GPS object, so we use the library named Adafruit underscore GPS, make sure that you’re getting the underscores right, make sure you’re getting the capitalization right and the way we do this is and my cereal. So what I’m saying is – and I need to give it a name here – let me uh so the library name is Adafruit GPS and now my object name is going to be GPS and I’m going to connect to it through, and I need to put an and My serial because remember this is my serial port that I created to connect to this on pins three and two, and so I’ve got to tell it that the GPS is connected through the my sea, real and for some reason, these new Adafruit libraries like to do This thing where you got to put an end in front of there, I don’t understand it, but I know that the end needs to be there okay. So what are we doing here? Create the GPS object? Alright, so that looks good. So we have that little business taken care of what variables are we going to need? Well dad to show you that I showed you where you want the GP GG a NEMA sentence and you want the GP RMC NEMA Senate.

So when we go out, we want to grab two sentences and then, when we come back and read again, we want to grab two sentences, and so we need to keep track of two name of sentences. And really we don’t know whether it’s going to read the GGA first or read the RMC. First, we don’t care we’re just going to have two variables one for the first sentence, one for the second sentence, so those are going to be string variables and so we’re going to have mm e am e a1, okay variable for for first EEMA sentence and then Strain in mea two very variable for second and then be a sentence: okay and then the way we read this, did you see how those things were coming in that data was coming in they’re, coming in as just characters, and so the way we read that it We just read a character over and over and over we’re just reading a character, so we need a variable to read that character into. Is it streaming in? So we need a char, a character. I’Ll just call it C to read: characters come I mean from the GPS. I think those are our variables in our void. Set up. We’Ve got some business to take care of. We always want to start our serial ports, we’re going to say serial dot begin, and this is just our normal serial port that talks to the computer so we’ll.

Well, we better go fast. We have no time to dilly dally with this thing, so we’re going to go fast. Okay, turn on serial monitor in the baud rate is 115200. We’Ve got to now start the the GPS, and so just like we did serial again. We got to do a GPS dot again. Why is it GPS because that’s what we named our object up here and that we can talk to it 9600? I don’t think it likes to go very much faster than that. Okay, turn on GP GPS at 9600, baud. Okay, now, this is where it gets kind of confusing. One of the really frustrating things about the adafruit GPS is is that it keeps wanting to send you the status of the antenna. Is there an antenna connected and I don’t care if there’s an antenna connected because I don’t have an external antenna? I know there’s, not one connected, and so, when I’m out there trying to grab these sentences that are coming off of the GPS. All of a sudden. It keeps spewing at me data about the antenna and I don’t care about the antenna and then that messes me up when I’m trying to parse the data. All I want is the GGA sentence and the RMC sentence. I don’t want you to send me an update on the antenna, so I have to force it because the commands that a different says will turn that off don’t work.

Okay, so we’ve got to get down and dirty in this thing, and we have to do a GPS because that’s what we named it up here and then we’ve got a dot, send a command. Okay and the command we are going to send is dollar uppercase. P G C M D, comma 33, comma, zero, star six uppercase D in quotes; okay, what this is doing is this is just sending a command down into the registers that turns that thing off kind of like finally, at the hardware level, okay, turn off and Keena Update new since data okay, so let’s look at this again I’m going to this one I know works so I’m going to copy and paste it from over here and then I will read it to you again very carefully because you were typing this in it is Dollars it’s in quotes, dollar sign, uppercase, P G C and D, comma thirty, three comma, zero star 6d and ended that will turn that off in your life will be so much easier. If you are not getting that data in there, we need to do another. Send command. Okay, GPS got send command. We need to tell it what speed we want it to work at and that is going to be the command P m. Tk. All uppercase underscore set underscore in a M a in a a underscore update, underscore 10 Hz close that into the colon okay set up update break q10.

First, your other choices. You could change this 10 to a 5. 4 5 hurt, so you could change it to a 1 4, 1 Hertz, and so those are kind of your choices you can’t put in any number. You want, you can kind of make it 10, 5 or 1. So that’s p m TK underscore set underscore in and oh I have a typo here in M e. A NMEA underscore update underscore 10 Hertz. It gets easier here in a second, but this is just some bookkeeping that we’ve got to send these commands so that we get the GPS configured correctly now we’re going to do GPS underscore send command what we want to do now is we want to just tell It that we want two sentences, we want the GGA sentence in the RMC sentence and it sends them over and over, but we’ll send the g8. The GG armc GG armc GG armc, but it won’t put all those other sentences in there that we don’t work, and so I am going to copy and paste this so that I do not make a mistake and then I will read it to you carefully. You want PMT K underscore set underscore in M EA, underscore output, underscore R MC GGA, so we’re saying we want the our MC sentence and we want the GG a sentence: okay, request, our MC and Gigi a sentences. Only alright now let’s give it a second type digest all this, so we will say delay by a thousand milliseconds just to give it a chance to get all this information yeah.

Alright, now let’s come down. We are actually getting pretty close here. This gets pretty easy and what I’m going to do is I’m, just going to write my own function and then I’m going to call it and the function that I am going to call it or the function that I am going to make is going to call Read GPS and what I’m going to do here in this loop in my avoid loop, I’m just going to sit and read: GPS reach; epi, sorry, GPS, okay, and so this is a function, so I have to define that function so after the void loop is over. Okay, this is the end of my void loop. I will create a new type of function, called void and it’s going to be read. Gps, okay, void means I’m, not passing it any parameters in the parentheses I’m, not passing any parameters to it. I’M, not getting any parameters back I’m just going to do the steps in there so void. Just means: don’t expect any data return from it. Okay, so now let’s do the avoid reread GPS. Well, what do I want to do? Okay, I want to come down here, and this is going to be just like our void loop and our void setup. We have a begin of the clause and we have an end of the clause with curly brackets, so this function starts with this and ends with this, and then everything in here it will do when I call this so when it sees this command.

It jumps down here and does these steps, and then it goes back. What I want to do is I want to sit and loop. Okay, I just want to sit and loop until I get a good NEMA Senate sin. So what I’m going to do is I’m going to say, while I exclamation means not, while I don’t have while it’s, not okay, GPS dot new in in E, a re see okay, and what you got to do here is be very careful of your capitalization uppercase Gps and then dot new and then uppercase n m e, a the r is uppercase received and then an open, a closed and then a closed for the while loop and then open bracket for the while loop and then close curly bracket for the while loop. All right, so what is this going to do? This is going to sit and loop until it gets a GPS dot. New Nima received when GPS dot new Nima received is true. It has a new Nima sentence and it will drop out of this. But as long as you don’t have a GPS dot new Nima received, it will sit here in loop, so it’s going to sit here and loop until it gets a sentence. Well, what are we doing? The loop we read so C is equal to GPS. Dot. Read open closed all right, so let’s let’s let’s, think about this. We call the GPS, read, we come down here and we loop and we just keep reading a character, keep reading a character, keep reading a character, keep reading a character until this function, GPS, new Nemo received is true and once it’s true, it drops out of this.

While loop, meaning you have one of those sentences, okay, so what we are doing here is loop until you have a good nema sentence, all right. Well, once you have a good name, a sentence: once you have a good name, a sentence. What do you want to do? You want to parse it so you’re going to say GPS dot parse? What do you parse? You parse that, ah, you parse the GPS dot last nema parse that last good name, uh sentence all right, so once it gets a sentence. Where is that sentence? That sentence is in the the function or the command GPS blasts? Nema? Okay, I take that GPS. Last nema and i parse it, which that means it’s going to take all those useful things and put them in variables. That will be easy for me to get to tomorrow. So we want to get the sentence and then we want to parse it all right. Get the sentence, and then we want to parse it then, once we have parsed it, we also sort of want to save it right. We want to hang on to it because we know that we are going to want to use it later so I’m going to call this NN ea1, remember that was that string and then I’m going to make that equal to the variable GPS, dot. Last N and M PA, and do I need oh yeah, I got to put the openclose on this so right there you need to open closed parenthesis here.

You need open, close parenthesis. Okay, so I’m going to sit here and loop until I’ve read a good sentence. Then, once I have a good sentence, I am going to GPS dot parse that good sentence and then I’m going to save that good sentence in the variable in n e all right. So at this point I should have one good sentence. This is the tricky thing guys this data is coming in so fast at us. You cannot pause and do anything here. Whatever that first sentence is, you’ve got to go, read that other sentence, because that GGA sentence in that RMC sentence come right after each other and if you run off and check the temperature or check the time or get a cup of coffee or or do any Other command, that sentence is going to be in there and jammed up in your buffer before you know it, so we need to immediately read that next sentence, that’s, why we put it down here by itself. You have to read those two sentence right exactly together. You cannot even put a print statement here if you put a print statement in the time that you do that print. You have already jammed up that that that buffer and it’s overflowed and it’s corrupted. So the only way this works is, if you read sentence 1 and read: sentence 2 and don’t: do anything not even a print statement in between them. So what do we want to do? We want to read that second sentence, so we’re going to take this copy and we’re going to do it again.

Okay, only this time, so we have. While we look we’re reading the second sentence and this time, okay I’ve got it and now I’m going to parse. It and this time I will call it two right so now, I’ve got the first sentence and now I’ve got the second sentence. Alright I’ve got the two things I needed. I got my two sentences. I parsed them. Now I can relax. Now I can print them out, okay, so what am I going to do serial dot, right, Ln, MVA, one, okay and then I’m, going to put a serial dot print and I’m going to put in mp2 all right so I’m going to grab the first half grams Sicken and now that I have my two sentences now, I can casually print them and casually print them, but you can’t do anything because of the stream of data. You’Ve just got to read the two all together all right. I think this should give us two nameless sentences. Let’S download this let’s see where my ears. What did I do here? Oh up here forgot my colon: did you guys catch that when I did it forgot my semicolon at the end of that remember when you load libraries, you don’t put calm, you don’t put us in my cones when you load the library’s almost everywhere else. You do so let’s give this a new read: GPS, okay! Why does it not like that? We do three GPS that is going to be ah okay, so I’m reading the GPS.

Thank you, sir. I appreciate that. Okay, so I’m going to read the GPS and it says that that was not declared here: I’ve got I’m defining it. Let me look and see what could possibly be wrong here: read GPS and then in my void, loop and then down here, undo: I’m diff’ent. You guys probably see it already avoid. Oh, I don’t. I don’t want this okay, that, because this is a function I don’t for the semicolon there, okay, ah new name, were received. Okay let’s see what I did wrong there. Well, not GPS do aa little art. I’M. Sorry anima receive little R on Nemo received. Little are okay, alright, hopefully you’re up with me, I’m sorry for those little snafu, but I think that we have got it now. Okay, so let’s look at our serial monitor. We should see these Nemo sentences coming in and we don’t 115000 on the body right. Remember: let’s see what happens there. Okay, I’m. A serial print line Nemo one serial.print miney mo 2 m2 is let’s. Try it download it again: okay, we’re, on 115200 we’ve got that let’s. Take a look here, so we are reading our GPS. Why are we not happy? Okay? I found the mistake. I hope you guys saw this when I went through it. The baud rate should be 9600 and I said it at 96 thousand let’s download that whoo. That was a hard one, but things have to work if they don’t we’ve made a mistake.

This should work this time all right. I turn this on. Okay – and you can see that I’m getting these Nemeth sentences streaming to me, I’m – going to put an extra print statement in so I can see a little bit better. I want to see the one I wan na see the one two punch: okay, so serial dot print Ln I’m having problems today, spelling open the clothes by putting a blank line, so I can see them one after the other coming in and we download it. Okay, let’s see what happens all right, so let’s. Look here: I’m, gon na turn, the auto scroll off and let’s. Look look the first data that I’m getting is corrupt; okay, because that’s like I’m out doing all of this stuff, and then I go and I say: read the serial port and it’s already jammed all this stuff in on me, while I’m doing my setup and then I try to read: it now: read garbage well, then, I’m, coming in and I’m getting an A in a C and a and a C and a and a C it seems like it’s working pretty good after the first one. So we might say well ignore the first one because, as I’m coming down here, we’re getting a lot of good data – okay, I’m, seeing a lot of AC AC. So that looks good. The problem is, if I just ignore it, the other thing is imagine all I’m doing here is reading GPS, but remember eventually we want to pressure a sensor in a temperature sensor and an inertial measurement sensor, there’s going to be a lot going on, and so I Need to kind of simulate that other stuff going on what? If I put a delay of 250 milliseconds here that after I read the GPS, that leaves me, you know let’s, say I’m going out doing other sensors and stuff in that time.

What happens if I put that delay to simulate those other sensors, so if it’s just running flat out the first data is corrupt, but what, if I have a delay in there? What happens? Okay, that first data is corrupt, and then I get a CA, CA and it’s. Looking surprisingly good with at 250 milliseconds delay. First one it’s still bad and look this one’s bad too, because I’m missing the Chi things. Look pretty good at that point, but we got to kind of try random delay time. So let’s try 750 and see what happens because you don’t know all the things that you might be doing between GPS reads: we got to make sure that this core part of our program is robust so that we can add to it so that’s bad that’s, good Good, I get a CNN a, but now look at this I’m getting an A in an a and then a CA and an A in an a well this a and a won’t work, because I need to get both the MC and the GA. So what it’s doing is it’s reading like an old, a and then while I was away in that 250 or 750 milliseconds, it misses the our MC and then when it comes back there’s another a there. So you can see this is not going to work. This is not going to work because, while we’re away, I Jam up data in that buffer and then it’s old and it’s corrupt data.

So how do we handle that? This is how we handle it. We need a new function and down here in void, read GPS. When we read the GPS, the first thing we should do is we should clear GPS, so we’re going to create a new function. So when I tell it to read, the first thing I want to do is just go clear it so now I need to define a new function which is going to be void, and then this is going to be clear: GPS we’re, not returning any data, so It’S that, like that don’t make that mistake again: open curly, braket, close curly bracket, so here’s the function, and what do I want to do here? How do i clear so the thing is, while I’m out reading, one of the other sensors there’s all this data. That is jammed up in the buffer and it’s become old or corrupt. What do I want to do? Well, I just want to read it and discard it so I’m going to do like two reads on the GPS. I just want to do two quick reads to get all that old and corrupt data out, and then I want to just go back and continue in my function to do the real reads. So what do we want to do? We want to do this right here. We just want to read and parse the sentence I don’t want to save it. I just want to read it for the purpose of getting it out of there: okay, okay, so here we are going to loop until okay and what’s.

The purpose of this function – clear, old and corrupt data from serial, deport, okay and so I’ve, read it once and then I’m going to do it again because there may be, there could be say a couple of sentences worth of bad data there so I’m, just going To read it twice: throw the data away and then I’m going to come back up here after I’ve cleared it and then I’m going to grab the one I’m going to keep and I’m going to grab the one I’m going to keep. And I think this should work. I think this should even work on the first one, because we’re going out and we’re clearing that old data out of there downloading anyway let’s look I’ll. Look at that. I got a CNN a. I got an anus II, a CNN, a and anus II. I don’t care, if they’re in different orders, but look I’m, getting a complete a sentence and a complete C sentence: a complete C complete a that is looking good. That is looking good, the first ones good. They were all good how about let’s go back and let’s put like a short delay, because you got you got to try cuz, you don’t know how long these things are going to be that when you go do these other reads it could be span a wide Amount of time so we’ve got to really try this for different delays, to make sure that, for any delay that when you come back and want to do, it could GP it when you want to come back and do a GPS read that you’re going to get Good data, so this is just with a very small delay and look at that I’m getting an AC, AC, AC AC.

Look at that that is working okay, let’s go back to like 750, see how that works. You see you’re better off trying to break it. Now yourself and getting way into a project and then see that your algorithm is not very robust, but so far this is looking good. Okay. First then, it’s a CNN, a that’s good, an ans, see a CNN a and ans see I don’t care if they’re in different orders. I just need every time an A and a C and look at that I’m getting an A and a C that’s going to work. We just put something crazy, like a 12500 that should be like 12 seconds 12 and a half seconds. I just want to do that just to make sure that anything that we do is going to is going to still have this core part of the program working. I got a good. A I’ve got a good, see, wait twelve and a half seconds. Okay, ooh that one is a busted sentence. You see, that is a busted sentence, that one looks good so for ultra long delays of like ten or twelve sentence. I did get a busted sentence in there, so I am going to just to be safe, I’m going to read. You know the questions I’m, not sure how big that buffer is and maybe there’s enough room in there for three sentences, and so maybe, instead of reading two sentences, I need to read three sentences here so I’m going to take this copy and in this void clear I’M, going to I’m going to wait till I read three sentences and I’m going to throw it away and then I’m going to go, get the data and that certainly should clear up clear out that serial port.

I think this should work. Okay got an A and C it was the second one it missed up on last time. Cold and a half second seems like an eternity when you were waiting ah got a good one. Let’S, wait for one more I’m, pretty sure that the three has got to work. I think that this has just got to work. Kind of annecy got an ASC, got an ASC so that work, but let’s go back for the other ones, just to make sure let’s go to. Ah, where were we? Our delay is in right here: let’s go back to one second one and a quarter second see what happens see na AC AC AC. That is looking good. So this, I think, if we do three reads: we just completely flush out that serial port and we are in good shape. Okay, let’s go just twelve let’s, just just to try the other end, and this will be the last thing that we try ca, ACCA, ACCA, ACCA, look at that and we’re. Getting that mean that is coming in at a pretty good clip there. The data is coming in at a pretty good clip and everything’s good, so we went everything from like 12 seconds down to 12 milliseconds and in that range we got all good sentences, no busted, not no busted sentences, and so I think at this point this is Pretty robust now again we’re not getting actual coordinate data in those sentences because we’re inside what we’re going to do tomorrow is we are going to put an SD card on this and hook it up to a battery and I’m going to go, walk around outside and We’Re going to collect real data so tune in tomorrow for lesson number 23 and on that one we’ll complete the project to where you will have your very own, handy, dandy, portable gps, tracker, again, palma quarter thanks for tuning in subscribe to the channel.


Paul McWhorter arduino lesson 22 Video







Paul McWhorter arduino lesson 22 news








Paul McWhorter arduino lesson 22 Social






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.
safe image.php?d=AQB6YIkvOaOwGAQg&w=720&h=720& content%2Fuploads%2F2019%2F10%2FDSC00029 - Paul McWhorter arduino lesson 22

How fast can you run the 40-yard dash? Find out with your own wireless timing gate system.
safe image.php?d=AQDAnlSUYJivJY5S&w=720&h=720& mOWHBn2WBw - Paul McWhorter arduino lesson 22



(Visited 43 times, 1 visits today)

About The Author

You might be interested in

Comment (23)

  1. Are you still making GPS trackers?
    I am trying to find out how to build a very simple one. Essentially it would be capable of sending its location on demand. Any opinion? Do you think this hardware is out of date? Would you use anything else now?

  2. I’m totally new to this. What boards and connectors are required to make this work? I am starting totally from scratch.

  3. Why 1Hz ? Adafruit advertises the device for 10Hz. Is it not good enough to achieve that and remain stable? What kind of problems did you experience with 10Hz operation?

  4. A couple of comments in addition to the excellent comments by Unen44.

    The first parameter to SoftwareSerial is receive (rx) and the second is transmit (tx). If you switch the jumpers then you would switch the parameters or it won’t work.

    It’s also good practice to put those port numbers into const values so they’re less likely to get confused later on in your code. It also allows you to later move that pinout with only two const assignment changes rather than trying to chase down everywhere you’ve referenced pins 2 and 3:
    const byte txPin = 2;
    const byte rxPin = 3;
    SoftwareSerial mySerial (rxPin, txPin);

    GPA::parse checks to see if you got good data. It performs a checksum and returns a boolean (did the data pass the checksum or not). You should use that inside your loop instead of read() to determine whether you got garbage, else you should continue looping. GPS::read just reads a char from the serial port, unless I’m missing something that’s just wasted time in your cycle. Instead you should also be checking to see if you got good data and it’s the data you wanted rather than just taking what it gave you. In this instance I think do/while works better than while. And lastly on this loop, if you find yourself writing the same lines of code twice you should create a function, always, because if you wrote the same N lines twice you’re almost always going to write them again and if you find a need to make a change you will have to find and change every instance, which is always easier if there is only one instance. The code for loop until this should be a function that will simply return your data :

    boolean getSerialPortString(char *strStartsWith) {
    bDone = false;
    do { // do this until while criteria is true
    bDone = GPS.newNMEAreceived() && GPS.parse( GPS:lastNEMA()) && GPS::strStartsWith(strStartsWith); // check if we got data, it’s good data and it’s the data we want avoid garbage
    } while (!bDone); // if we got data and it’s good, we’re done
    return GPS:lastNEMA(); // return the data
    and call it as:
    NMEA1 = getSerialPortString(‘&GPGGA’);
    NMEA2 = getSerialPortString(‘&GPRMC’);

    This will also allow you to easily grab any other codes you might want to look for in the future. That was written ad hoc without having anything to test it against, so grain of salt. I just ordered this unit today and was looking around at videos with people using it.

    Looking at the code in the GPS library ( the buffer holds two lines, lastline and currentline, and only lastline is available to you. You aren’t getting old data, you’re just not getting the data you want.

    And all of that point and click killed me, I’m a linux kinda guy and that was just excruciating.

    1. My crazy idea folder is crazier than anyone’s crazy idea folder. You really do not want to see whats inside.

  5. if your using a MEGA 2560, then try using hardware serial instead of software serial. Change pins 3,2 to 19,18. Go to File–> Examples–> Adafruit GPS Library–> GPS_HardwareSerial_Parsing. Take a look at the code for setting up the hardware serial. Good luck.

  6. 17:45 – Pass-by-reference has a couple of benefits: better performance since it doesn’t have to copy the variable, and the ability for a function to “return” multiple items instead of just one using the normal return.

  7. in 17:48 the reason for using the & sign is to pass the memory address of the software serial object. this is done as it prevents making a duplicate of the software serial object Saving memory which is crucial on boards with very small memory (like arduino uno which has only 2kb of memory). I checked the adafruit’s library file and looked for the parameters(the thing which you passed in to create the object) and the constructor(the thing which creates the object) is looking for a pointer.

  8. If you want to use linux tools for parsing, a simple example to start when you have loaded a blank sketch and seeing all the GPS data in the serialmon, is to view that with socat in a terminal instead, then parse what you want with awk, which could then be sent to a text or data file using e.g. > RMCtext.txt at the end:
    socat stdio /dev/ttyACM0 | awk ‘/’GNRMC’/ {print }’
    this gives only RMC lines:
    stevee@quad ~ $ socat stdio /dev/ttyACM0 | awk ‘/’GNRMC’/ {print }’

    1. If you want both the values shown in the vid parsed :
      socat stdio /dev/ttyACM0 | awk ‘/’GNRMC’|’GNGGA’/ {print }’

  9. Hi there,
    I’ve been following current tutorial exactly the way it is, and everything is working the way it is supposed to be, but I am not getting two required NMEA sentence. It looks like programm sentence (GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); ) is not working at all. Could you, please, explain the way for managing such sentence.
    Thank you very much in advance for your tutorials.
    Have a good day.


Your email address will not be published. Required fields are marked *