LESSON 23: Arduino GPS with Data Logger

In this lesson we will extend what we did in lesson 22 to include a data logger with our GPS. You should be sure and do lesson 22 first, as that shows you how to hook up and program the GPS. In this project we will connect an SD Card Reader/Writer, and will power the whole thing with a 9 Volt battery. With this, you can walk around, and the device will constantly monitor and log your position. You can then bring it back inside, and look at where you have been using Google Earth.

GPS Data Logger
Arduino connected to Adafruit ultimate GPS and a n SD card Data Logger

To start with, lets talk about what you will need to do this project. As described earlier, you need to start by doing lesson 22 which will get you going on the GPS hookup and initial software. Now, to move forward, you will need an Arduino, Adafruit Ultimate GPS, Virtuabotix SD card reader, and a Battery Clip to power the arduino during your mobile jaunts.  You will need a 9V battery. If you are going to be doing a lot of mobile work, it is probably worth it to invest in a good 9v Rechargable battery system.

When you get your gear gathered up, you will be ready to get this project going. First, hook the GPS up to the arduino as we did in lesson 22:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS PinArduino Pin
Vin5V
GNDGND
RXPin 2
TXPin 3

You also need to hook up the SC Card Reader/Writer. You should be familiar with this from lesson 21.

Connecting the SD Card Reader
Sd Card Reader PinArduino PinDetails
GNDGNDCommon Ground
3.3 V – (NOT USED)
+55VPower
CS4Chip Select
MOSI11SPI Data
SCK13Clock
MISO12SPI Data
GNDGNDCommon Ground

Remember that this SD card reader has two rows of pins. Don’t let that confuse you, both rows are equivalent. You can connect to either row.

Most of the code has already been written in Lesson  22. In this lesson, the main thing we will be doing is to write the GPS data to the SD card. This way, as we walk around outside, it will log our positions to the SD card.  We will create two files. One will hold the raw NMEA sentences, and the other our location data, as parsed by the adafruit GPS library. You should be able to figure most of this out from what you already know from lesson 22 and lesson 21. In the video above, we take you through this code step-by-step, so watch the video to understand what we are doing. If you get stuck, you can look at the code below.

 

LESSON 22: Build an Arduino GPS Tracker

OK, it is time for us to take our projects up to that next level. We are going to build a GPS tracker from scratch. This is going to take several lessons to complete, but it will build on what you already know, and is really not going to be that difficult of a project. We will be using the most excellent Adafruit Ultimate GPS module. This is an excellent GPS. I like it because it is affordable, easy to use, and is one of the few that will work at extreme elevations, making it ideal for our Edge of Space/High Altitude Balloon work.

Arduino GPS
We are using the Adafruit Ultimate GPS

This unit is pretty easy to hook up, as you can see in the Table below:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS PinArduino Pin
Vin5V
GNDGND
RXPin 2
TXPin 3

Our goal in this lesson is to get the GPS connected, and get it reading NMEA sentences. NMEA is a data format used by GPS and mapping devices and software to keep track of position coordinates. There are lots of different NMEA sentences, but the two that contain the most useful information are the $GPRMC and $GPGGA sentences.

Our interest is in creating a location tracker for our High Altitude Balloon work, and the $GPRMC and $GPGGA sentences contain all the information and data we would need for that work. These sentences contain the lattitude, longitude, time, altitude, and velocity.

The GPS modules are pretty easy to work with. When you apply power to the GPS, it immediately starts spitting out NMEA sentences to its serial port. Our job on the arduino side is to simply read these data strings, and then parse them into useful data. The thing that is a challenge is that they constantly spit out data, whether you want it, or whether you are ready for it or not. In developing the software, we have to be mindful the the data is always spewing out of the GPS. Typically, we will have other components on our package, like temperature, pressure and inertial sensors. While our arduino is out making measurements on these other sensors, data continues to stream in from the GPS, likely overflowing our serial buffer. When we return to make a GPS measurement, it is very likely that the serial buffer will have old or corrupt GPS data in it. Hence,  we must be mindful to deal with this issue in developing our software.

The video above takes you step-by-step through connecting and reading the NMEA sentences step-by-step. Then in the next lesson we will parse and log the data to create a portable GPS tracker. The code below is explained in the video. You need to watch the video to understand this code, and so you will be able to begin to work with this code to create a portable GPS tracker.

In order for this software to work, you need to download and install the Adafruit GPS Library.

 

Arduino LESSON 21: Log Sensor Data to an SD Card

In most of our work so far, we have just watched our data go by on the Serial Monitor. In most cases, you will want to have some means to store your data. The easiest way to do this is to use a simple SD card reader. For this example, we use the Virtuabotix SD Card Reader.

SD Card Reader
Arduino connected to a BMP180 pressure sensor and an SD Card Reader

In this tutorial, we will need to have some sensor hooked up so we will have some data to store. We will be using the BMP 180 Pressuer and Temperature sensor from adafruit.  We have a complete tutorial on this sensor  HERE.  You will need to go to that lesson and get the sensor hooked up, the library installed, and the software done. All this is explained step-by-step in the LESSON.

The BMP180 is connected to the arduino as follows:

Connecting Up the BMP180 Pressure and Temperature Sensor
BMP180 PinArduino Pin
Vin5V
GNDGND
SCLA5
SDAA4

Once you have the BMP180 connected, test and make sure your code is working, and you are getting good pressure and temperature readings. Once that is working, you are ready to connect your SD card Reader/Writer.

The SD card reader should be connected as follows:

Connecting the SD Card Reader
Sd Card Reader PinArduino PinDetails
GNDGNDCommon Ground
3.3 V – (NOT USED)
+55VPower
CS4Chip Select
MOSI11SPI Data
SCK13Clock
MISO12SPI Data
GNDGNDCommon Ground

In the video we will show step-by-step how to develop the software. You should follow along in the video, and not copy and paste the code below. You will never learn to program if you do not write your own code. The code below is to help you in case you get stuck.

If you have the BMP180 and the SD card connected correctly,  this should create a file called PTData.txt on the card, and write comma delimited data to the file. Note that if the file does not exist on the card, the command:

will create the file. If the file already exists, this command will append data to the existing file. If you want to start with a clean new data set, erase the old PTData file.

When you run the program, you end up with a PTData.txt file on the SD card. When you have finished logging your data, you can pop the card out, put it into your PC, and then import the data into excel. You should now be able to plot, graph or analyze the data using all the powerful features of Excel.

Python with Arduino LESSON 13: Calculating Height from Pressure measurements from BMP180 Pressure Sensor.

It is time to bring together a lot of things we have learned in our earlier lessons to create a Height-O-Meter, which will plot how high our BMP180 pressure sensor is above the floor. For this lesson we make simplifying assumption of constant temperature. When we use the sensor for our space probe or other high altitude experiments we will need to derive the equation again to take into account changing temperature. We went through the math of calculating height from changing pressure in LESSON 12.

In this lesson, we start with the software we developed in LESSON 11 for measuring, streaming, and plotting pressure and temperature data from the BMP180 sensor.

Remember, we connect the sensor to the Arduino as follows:

Connecting Up the BMP180 Pressure and Temperature Sensor
BMP180 PinArduino Pin
Vin5V
GNDGND
SCLA5
SDAA4

 

The software we are using on the arduino side is shown below, from LESSON 11.

We modify the Python code from LESSON 11 as explained in the video above to get this code for the Python side.

 Please go through video for complete description of this software. Remember this is only valid for small changes in height over which temperature is constant.

Python with Arduino LESSON 12: Approximating Changes in Height from Changes in Pressure

In LESSON 9 we learned how to hook up a BMP180 Pressure Sensor and make pressure and temperature readings. Then in LESSON 11 we learned how to stream that data to Matplotlib and create live graphs and charts of our data that update in real time. We could see that as we moved the pressure sensor up and down, we could see the pressure change, as the pressure decreases with increasing elevation.

This leads to the interesting question of whether we can use our circuit developed in LESSON 9 to create a Height-O-Meter . . . a simple device that will measure the height above the floor.

The math to calculate altitude vs. pressure turns out to be very complex. Particularly, if we wanted something for our high altitude balloon flights, or for model rocketry. It turns out that for the case of measuring height inside and for relatively small changes in height we can make simplifying assumptions that make things much easier. The assumption we will make is that temperature does not change much over the range of our experiment. With this assumption, we can create our own Height-O-Meter. To do this though, we do need to to through some math. I show my math below, and go through it step-by-step in the video. Remember, this simplified approach is only valid for playing around with small changes in height. We will have to do the more complicated math when we make our high altitude balloon probe. For now though, this math will work pretty well.

Height and Pressure
Calculate Changes in Height from Changes in Pressure

We can rearrange the equation to solve for height as a function of pressure.

Height Pressure
Calculating Height from Pressure Changes