GPS Logging
When I decided to build a multi-rotor, I knew I that I wanted to track its flight path, as I would be flying several hundred yards once I had the FPV setup going. I spent weeks searching for and reading up on small-scale GPS Data Loggers that were simple to use and easy to program. Then one day, I stumbled upon an article on Make.com that was exactly what I was looking for, and I had everything already on hand to build it.
You might remember a review I did on the TinyCircuit's Arduino-compatible development kit a few months back. Turns out that the hardware used in the Make.com article utilized this same hardware, and was in fact, written by the founder of TinyCircuits. So with hardware in hand, and the code pre-existing, I had a quick head start to get this small sub-project off the ground.
Included in the kit I received was a fully functional micro-GPS shield that was not much larger than a quarter, an SD card shield, and an Arduino. When stacked together, the entire package is about 1-inch cubed, which makes the stack the perfect size for attaching to RC aircraft. With everything I needed to develop my GPS logger, I sat down at my bench to get the party started.
The GPS data logging project I found on Make.com was designed to track the author's cat, but the code I needed to get my project off the ground would do the job whether it was tracking a cat or tracking the flight path of my quad copter.
The TinyDuino series is pretty cool because you have a full Arduino Pro / Pro Mini packed onto a board the size of a quarter. I won't go into great detail about the boards and what makes them so special, but if you would like further information on them, check out the full overview I wrote that is located here on TweakTown. Below is a list of everything you need to create a simple GPS Data Logger of your own using the TinyCircuits hardware. You can find all of the code and needed files on the Github Repository I made for this sub-project. I will eventually update the QuadCopter repository to include these files as well.
- TinyDuino
- TinyShield microSD
- TinyShield GPS
- TinyShield USB & ICP
- TinyDuino Mounting Kit
- 3D Printed Case
- Code
- Class 4 or higher 4GB microSD Card
There really is not much to building the GPS Data Logger other than stacking the shields in the correct order, uploading the code to the Arduino, and then getting outside and logging some data. The stack should be built-in the following order. The bottom most board should be the TinyDuino, which should then be followed by the TinyShield microSD board. Up next would be the TinyShield GPS, which is followed by the TinyShield USB and ICP.
I chose to power my GPS Logger using an 18650 powered USB cellphone charger instead of the CR2023 or JST methods that the TinyDuino also supports. If you chose to go this route, you will need to arrange your stack with the TinyShield USB & ICP board placed between the TinyDuino and TinyShield GPS; I chose this route because I had several spare USB cellphone chargers laying around.
With everything stacked together, let's prepare the TinyDuino for coding. Plug a microUSB cable into the TinyShield USB & ICP board, then select the appropriate USB port that the TinyDuino is now connected to. Once the correct port has been selected, we need to set the Arduino IDE to recognize the correct Arduino-compatible board. Since we are using a TinyDuino, we need to select Arduino Pro or Pro Mini (3.3V, 8MHz) w/ ATmega328. Once finished, we should be ready to import some test code to the TinyDuino to test that everything is working correctly.
Before we upload any code, we will need to make a minor change to the SoftwareSerial library in the Arduino IDE. You will need to replace the SoftwareSerial.cpp and SoftwareSerial.h Library files with the ones found in the GitHub repo for this tutorial. Replacing the files is quite easy, and you simply need to navigate to Arduino>libraries>SoftwareSerial and rename the existing files to SoftwareSerial_cpp.bak and SoftwareSerial_h.bak and then download the new files into this directory.
Now that that is complete, let's upload some test code to make sure that everything was configured correctly and the TinyShield GPS module is sending raw NMEA data to the Tiny Duino. Upload the code that is embedded below (also found in the Git repo titled GPS_Test_Firmware.ino and then open the serial terminal in Arduino and set the baud rate to 9600. You should see some weird strings that look like the pasted code below the GPS Test Firmware code.
If the data that appears in the serial terminal does not look like this, then you will need to re-upload the SoftwareSerial files and upload the test code again.
Now that everything is working fine, we need to upload the actual GPS Data Logging code to the TinyDuino. I have pasted the code below, and remember to insert a properly formatted microSD (read how to do this here) card into the TinyShield microSD.
GPS Logging Continued
Once the code is finished uploading, you should see the LED on the TinyDuino blink once every second. This is an indication that the TinyShield GPS is doing its job and polling its location every second and writing that point to the microSD card. Now is the time to venture out into the world and capture some data. Do this by unplugging the GPS Data Logger stack from your PC and powering up the board by a CR2023, JST connected battery, or via the TinyShield USB & ICP like I have done. If you placed the TinyShield USB & ISP board on top of the stack, you will need to remove it now to ensure that the GPS antenna gets a strong signal. If you need this board to power your stack, then move it to a position between the TinyDuino and TinyShield GPS.
When you are finished recording data, head to your nearest PC and open the SD card to view the files stored inside. If you correctly formatted the SD card, then you should only see one file that is titled gps.txt. Make sure you have extensions visible if using Windows, and then rename the file to gps.nmea. The current SD library can only write extensions up to three characters in length and is why the file is saved as a .txt instead of nmea.
Once you have the file renamed, open Google Earth and navigate to Tools>GPS and click GPS. There will be an option to upload a gps file. You can simply browse to the gps.nmea file you renamed, upload that file, and Google Earth will plot the exact path that your GPS Logger took when it was gathering data. There are several other programs that can be used to visualize this data, but I will not list them here as a simple Google Search will give you pages of information on them.
Now that we have the GPS Data Logger working, we need to secure the stack together using the TinyDuino Mounting Kit. This will ensure that the stack stays securely connected during any impacts that might occur during flight.
With everything secure, we also need to enclose the stack inside the case so that it is safe from static discharges, moisture, and debris. You can head over to Thingiverse or Github to download the custom enclosure I designed to house this project.
It is designed to be affixed to a quad-copter or any other half-inch surface using nothing but Velcro straps that are commonly used to bind computer cables together. It could also be secured using zipties as well.
I know that not everyone will have a 3D Printer on hand, and this enclosure could easily be built out of foam board or card board or even polymer clay. For those who do have the option of 3D Printing the enclosure, here is how it works.
The GPS Data Logger fits slightly loose inside the case I printed, and to stop it from rattling around, I used a piece of foam mounting tape to add some pressure. Just a single piece of tape is enough.
Place the tape in the center of the lid and firmly press it into the 3D printed surface. This will ensure a strong bond between the tape's adhesive and the plastic lid.
Now place one end of the lid into the top opening of the enclosure. I designed this case to secure its lid via a friction fit. With the lid aligned correctly, press down and snap the lid onto the enclosure's top.
With everything buttoned up, now would be a good time to use an extra piece of clear tape or electrical tape to add additional protection to the lid. I do not think it will come loose during flight, but it's always better to be safe than sorry, especially when dealing with $100 worth of electronics that is the same size as a quarter.
Now thread some common Velcro PC Cable Ties through the holes in the mounting tabs and secure it to one of the copter's wooden dowel arms. That will finish up this installment of Project M.A.R.V. Next time, we will tackle building the copter's frame and readying things for the electronics. Stay tuned to TweakTown for more awesome Maker and DIY guides just like this one.