Category Archives: Arduino

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 5: Finishing our Virtual Reality Example

This Lesson finishes the work that was begun in Python with Arduino LESSON 4. In that lesson we built the circuit and programmed the arduino to measure the distance to a target and the color of the target. The program then output that data to the serial port. In today’s lesson we will use python to read that data stream, and use the data to dynamically update a virtual world we create.

You will need to start with the work in LESSON 4 to get your circuit working, and your arduino programmed up. Once you have done that, you are ready to use Python to program up your virtual world. Remember you will need to have the pyserial and the vPython libraries loaded. We showed how to install the software in Python with Arduino LESSON 2.

In the video we will go through the process step-by-step to create a virtual world. The code we end up with is posted below. You should not copy and paste the code, but just glance at it if you get stuck. In the end, you should develop your own virtual world and just use mine as a guide if you need more help.

 The video explains each line of the code.  Play around and tweak the values and see the effect on your virtual scene. Now your assignment is to take what you have learned here, and continue to expand your virtual world. Add objects to your virtual scene. Perhaps build an object for the breadboard, color sensor and arduino. I will give you several days to do this, and then when I come around for a project grade, I will want to see who has built the most impressive virtual scene. You should go well beyond the simple demonstration I have done here.

Python with Arduino LESSON 4: Expanding your Virtual World

In this lesson we will expand the virtual world we created in Python with Arduino LESSON 3. We will be creating a virtual world that will track a simple scene in the real world. In this project, the virtual world will track both the position and the color of a target in the real world. This lesson requires that you have the Python software and libraries installed, which we explained in LESSON 2.

Arduino Circuit
This is our circuit with the HC-SR04 ultrasonic sensor and the TCS230 Color Sensor

This Lesson will be a bit more involved, and I will take you through it step-by-step. I will need to break things into two parts. In today’s lesson we will cover the Arduino side. We will develop the software that will measure distance and color, and then send those numbers over the serial port. Then in tomorrows lesson, we will develop the Python software to create a really cool virtual graphic to display the data in a virtual world.

For this project you will need the HC-SR04 ultrasonic sensor, the TCS230 Color Sensor, the Arduino Microcontroller, and some male/female jumper wires to connect to the color sensor.

The Ultrasonic Sensor can be attached per the schematic below:

Ultrasonic Sensor Circuit
Simple Circuit for Measuring Distance

Detailed tutorial on using this sensor was described in Arduino LESSON 18, so we will not go through all the details of using the sensor here. Review that lesson if you need more help. Key point here is to connect it as seen in diagram above.

You will also need to connect up the Color Sensor.

Connecting the Color Sensor to the Arduino

Color Sensor Pin
Arduino Pin
S0GND
S15V
S2pin 7
S3pin 8
OUTpin 4
VCC5V
GNDGND

Use of the color sensor was described in detail in Arduino LESSON 15.  You should be able to develop to write the software yourself based on earlier lessons to make measurements from both the Color Sensor, and Ultrasonic Sensor, but if you get stuck, you can glance at my code below. Again, it is important for you to write your own code and not copy and paste mine. Mine is just a reference if you get stuck.

The key point to notice with this code is the print statements, summarized below:

 Notice that we are printing  our color strengths and distance on one line separated by commas. It is important to note the order of the data. When we read this in Python, we will read it in as one line of text, and then we will parse it into its individual values. So, we must make note and remember the order the data is arranged in in this line.

Remember when you have your python program reading this data, you must have your serial monitor closed. For now though, run your program and look at the serial monitor to verify you are getting correct data in the expected format.

In the next Lesson, LESSON 5, we will build the Python program to create a virtual world from this data.