Software

Once you've assembed the hardware you'll need to load an Arduino sketch for the project.  If you're new to Arduino it will help to first familiarize yourself with using it by reading:

Make sure you have the latest version of the Arduino IDE installed (version 1.6.5 as of the time of this guide writing).

Next you'll need to load a few libraries depending on which version of the project you're building.  Remember you can use the library manager to search for and install these libraries right from the Arduino IDE.

For the GPS shield version load these libraries:

For the FONA808 shield version load these libraries:

If you already have any of the libraries above installed, make sure to update them to their latest versions.  In particular the FONA library needs to be at version 1.2.0 or higher or else it won't work to grab GPS data.

Now download the code this project from its home on GitHub by clicking the button below:

Unzip the file that was downloaded and you should see two sketches:

  • Track_Your_Treats - This is the version of the project that uses the GPS shield to log location data to a SD card.
  • Track_Your_Treats_FONA808 - This is the version of the project that uses the FONA808 shield to log location data to Adafruit IO.

Load the appropriate sketch in the Arduino IDE, then follow the steps below depending on your hardware.

Track Your Treats - GPS Shield

For the GPS shield version of the project load the Track_Your_Treats sketch from the download, you should see something like the following:

You don't need to change anything and are ready to load it on the hardware.  However you can skim the #define values at the top of the sketch to see values that change how the sketch works.

To load the sketch on the hardware first make sure you have a microSD card inserted in the GPS shield's microSD card holder.  The card should 'click' into place and be held firmly by the card holder.

Then connect the Arduino to your computer using a USB cable.  In the Tools -> Board menu of the Arduino IDE make sure the Arduino Uno board is selected.  In the Tools -> Port menu make sure the right serial port is selected for the Arduino (it should say Arduino Uno next to it).  Click the Sketch -> Upload command to upload the sketch to the Arduino.

Once the sketch uploads open the Tools -> Serial Monitor to see serial output from the hardware.  Make sure the baud is set to 115200 in the lower right corner.  You should see serial output similar to the following:

Track your Treats - Ultimate GPS Shield
Using log file: GPSLOG24.CSV
Ready!

The log file name will automatically increment every time the hardware is powered up or reset.  Once the hardware is ready to receive GPS signals it will print Ready! and wait for a GPS location fix to be made.

While the hardware is waiting to get a GPS location fix you should see the button LED blink every second.  Once a location fix is made the LED will stay solidly lit.  You might need to move the hardware outside where it has a clear view of the sky in order for it to get a GPS fix (it can even take up to 30 minutes in some cases!).

If something goes wrong the button LED will blink quickly (around 5 times a second).  Look in the serial monitor to see if an error message is displayed, like for example if a microSD card isn't found and the log file can't be created.

Once the hardware has a GPS fix it will start periodically logging location to the file on the microSD card.  Every 15 seconds the location will be logged (but you can change this with the #defines at the top of the sketch).  

If you press the button the current location will be logged and noted to have good candy, then the LED will blink 5 times to acknowledge the button press.  Note you can't log locations with the button if the GPS doesn't have a fix (i.e. the button is blinking every second).  Wait until the GPS has a fix and the button stays lit solidly before pressing the button.

That's all there is to using the track your treats GPS shield sketch!  Walk around and press the button a few times to get sample data, then power down the Arduino and jump to the Google Maps page to learn how to view the tracker data.

Track Your Treats - FONA808 & Adafruit IO

For the FONA808 & Adafruit IO version of the project load the Track_Your_Treats_FONA808 sketch, you should see something like the following:

At the top of the sketch are #define values which configure how the code will behave.  There are a few values you will need to change:

  • FONA_APN - Set this to the APN that your cellular network provider requires for accessing their data network.  With a Ting SIM card in the US the value "wholesale" is what you want, but for other providers you might need to contact their support to get the value.
  • FONA_USERNAME & FONA_PASSWORD - If your cellular network provider requires a username and password to access their data network then put those values here.  If they aren't required then just leave the default blank values.
  • AIO_USERNAME - This needs to be set to your Adafruit account username, which you can find at https://accounts.adafruit.com/ under the Username field.
  • AIO_KEY - This needs to be set to your Adafruit IO key, which you can find from the Adafruit IO settings page for your account at https://io.adafruit.com/settings by clicking View AIO Keys.

The other configuration values don't necessarily need to be changed, but it's a good idea to skim them to see what they do.

To load the sketch on the hardware first make sure the hardware is ready.  You must have a cellular antenna and GPS antenna connected to the FONA808 shield.  In addition you need a LiPoly battery connected to the FONA808 shield so it can power the cellular modem.

Then connect the Arduino to your computer using a USB cable.  In the Tools -> Board menu of the Arduino IDE make sure the Arduino Uno board is selected.  In the Tools -> Port menu make sure the right serial port is selected for the Arduino (it should say Arduino Uno next to it).  Click the Sketch -> Upload command to upload the sketch to the Arduino.

Once the sketch uploads open the Tools -> Serial Monitor to see serial output from the hardware.  Make sure the baud is set to 115200 in the lower right corner.  You should see serial output similar to the following:

Track your Treats - FONA808 & Adafruit IO
Initializing FONA....(may take 10 seconds)
FONA is OK
Checking for network...
Disabling GPRS
Enabling GPRS
Connected to Cellular!
MQTT Connected!

While the hardware is waiting to get a GPS location fix you should see the button LED blink every second.  Once a location fix is made the LED will stay solidly lit.  You might need to move the hardware outside where it has a clear view of the sky in order for it to get a GPS fix (it can even take up to 30 minutes in some cases!).

If something goes wrong the button LED will blink quickly (around 5 times a second).  Look in the serial monitor to see if an error message is displayed, like for example a cellular data connection can't be made (check your SIM card and cell account has data access), or if the MQTT/Adafruit IO connect fails (check your AIO username and key values).

Once the hardware has a GPS fix it will start periodically logging location to Adafruit IO.  Every 15 seconds the location will be logged (but you can change this with the #defines at the top of the sketch).

If you press the button the current location will be logged and noted to have good candy, then the LED will blink 5 times to acknowledge the button press.  It takes a few moments for the location to be logged after pressing the button so be sure to hold it down until it starts blinking 5 times.  Also note you can't log locations with button if the GPS doesn't have a fix (i.e. the button is blinking every second).  Wait until the GPS has a fix and the button stays lit solidly before pressing the button.

Once the sketch is running walk around and press the button a few times to get sample data, then jump to the Adafruit IO page to learn how to view the tracker data on Adafruit IO.

Last updated on 2015-10-12 at 04.07.46 PM Published on 2015-10-12 at 04.08.21 PM