Tuesday, 27 December 2011

Arduino GPS Live Tracker

This Christmas vacation, I have been spending some time working on a small personal project. An Arduino powered Position Tracker.
The Arduino Mega 2560 Board

There are similar other projects online, but most of them use 2 shields; one for GSM and the other for GPS. The other options I have seen are using just a GPS Shield and a cheap 2G phone. Both these options make the project bulky. Hence I decided to use a shield that does both the work.

I found a GSM GPRS GPS shield  on http://shieldlist.org.This shield has an ultra sensitive Origin ORG1318 GPS module and a Telit GE864-QUAD GSM module. The GSM part of the module can be controlled via the Serial interface, but the GPS communication is over the SPI interface which seemed a bit tricky at first, but once you understand the workings it is easy.
The GSM/GPRS/GPS shield from Antrax.de
The manufacturer does supply a software library for controlling the shield, but it does half the job. The library is designed only for the basic GSM Call and Text feature and the GPS feature. It had no function or example of how to use the GPRS functionality and it was using a custom SPI Library, instead of using a standard Arduino SPI Library. To add to the complexity, the Serial Communication with the GSM is done over the same Serial Line which is used on the Mega for printing debug lines to the console. Without a breadboard, it did seem to be a bit tricky to handle this situation, especially when trying to get the GPRS working. Most of the GSM/GPRS examples available online using other shields were using 2 other Digital Pins for Serial Communication and thus they were using the SoftwareSerial Library or the NewSoftSerial Library.

After researching a bit I found a library that worked partly for me. This blog post was using a Telit GM862-GPS module which is similar to the Telit Module that I have except for an additional built in GPS capability. It needed a bit of fixing to make it work with the new Arduino IDE and my unique problem of a conflicting Serial/debug port. My first test with this library was checking that the GPRS functionality was working with my setup. I setup my Linux Laptop as a DMZ with a php script that would except a GET data and dump it into a plain text file. The first issue I hit was that the code was complaining that I was not able to connect to the network. A bit of extra debug code showed out that the library was looking for a character at the wrong index. The next road block came when although HTTP connections were being made to the apache server, it was always resulting in a failure. I then realized that the library had many Serial.print statements which were interfering with my HTTP Stream thus corrupting my requests.  Commenting them solved the issues.

The Second stage was to add my working GPS code and club it into the above test code. This was easy task and I was able to successfully store the data on the server side. I further modified the code to activate GPRS and send data only when we have a GPS fix and approximately every 2 minutes.

The only thing I haven't been able to do is take this gizmo out for a drive.

It was a good learning experience though and I will upload the final code up later after I have further trimmed the library.