Step 1: Parts You Need
Adafruit Proto Shield for Arduino Kit
Adafruit Ultimate GPS Breakout Kit
Adafruit MicroSD card Breakout Board
TSL2561 Digital Luminosity/Lux/Light Sensor
Half-size breadboard
CR1220 Coin Cell Battery – also available at drug stores, other online resellers
MicroSD Card – you can also repurpose one from an old mobile phone
9V Battery clip
9V Battery
The parts for each device cost about $90, not including the Arduino Uno.
Step 2: Solder Your Breakout Boards and Kits
Next, attach and solder the header pins to the GPS module, MicroSD breakout board, and the TSL2561 light sensor. You may want to tape them if they aren’t staying put as you solder. To attach the coin cell battery holder to the back of the Ultimate GPS module, heat the pads on either side of the battery holder with the tip of your soldering iron. Once they’re hot enough, let solder flow on top and hold the battery holder in place until the solder hardens.
After you have soldered all your header pins, you are ready to start connecting the modules together. Follow the steps in the Proto Shield tutorial, and break off the sides of the half-sized breadboard. Then peel the adhesive backing off the back of the breadboard and attach it to the top of the Proto Shield.
Once you have all the modules put together, it’s time to connect the wiring.
Step 3: Set up the GPS Module
Find the line that starts with $GPRMC. The first section is GMT (Greenwich Mean Time), next is the letter A which means the GPS module is Active (as opposed to V which would be void). Then next four values are the Geolocation data. In Brooklyn, NY my location data reads: 4041.3198,N,07357.5915,W. This translates to (Latitude 40 degrees, 41.3198 decimal minutes North and Longitude 73 degrees, 57.5915 decimal minutes West). To check this against google maps, you’d covert it into degrees of latitude and longitude that google understands. I typed in +40 41.3198 ,- 73 57.5915, and it was able to find the correct location. If you’re getting readings with lots of zeros, try placing the GPS further on the window ledge.
Next, you’ll want to wire the GPS to your Arduino. Change the wiring so that the GPS Module’s RX pin is connected to Arduino pin2, and it’s TX pin is connected to pin3. Adafruit has a GPS library, but we’ll be using the TinyGPS library by Mikal Hart. Download the latest version of the library and put the folder inside Documents –> Arduino –> libraries. Make sure it’s called TinyGPS. Open the simple test example sketch. Notice how the serial monitor is set to a baud rate of 115200. Also, where it says
ss.begin(4800); change that to be ss.begin(9600); since the Ultimate GPS Module samples at a 9600 rate. Save your changes and upload it to the Arduino.
Once the sketch is uploaded, open your serial monitor. If you see a bunch of weird characters, change the baud rate to 115200. Then you should be able to see the data being printed to the serial monitor. If you’re not seeing any GPS data, you may have to put your module on the window ledge again since it’s most likely not receiving any new GPS signals.
If your GPS module is working correctly and you’ve been able to run the TinyGPS library code, the next step is adding the MicroSD breakout board to the Arduino, and seeing if we can save our GPS data to a text file on the MicroSD card.
Step 4: Set up the MicroSD Breakout Board
–5V pin to Arduino 5V pin
–Ground to Arduino Ground pin
–Clock pin to Arduino’s pin13
–DO pin to Arduino pin12
–DI pin to Arduino pin11
–CS pin to Arduino pin10
Now you’ll want to open an example from the SD card library, which comes with Arduino. We’ll be checking whether our MicroSD breakout board is wired up properly, and if the SD card is formatted correctly using the CardInfo sketch. Before you upload the code to the Arduino, make sure you change one line of code. The chipSelect pin should be set to 10, not 4.
const int chipSelect = 10;
Upload the code to the Arduino and turn on the serial monitor. If your serial monitor gives you a message that it can’t initialize the card, try reformatting it to FAT32 or FAT16 using your Disk Utility application. If you have further problems, follow the steps in the Adafruit tutorial.
Next let’s see if we can write files to our SD card. Open the Files example from the SD library. Make sure to change chipSelect to equal 10, not 4. Upload the code and turn on the serial monitor. If it successfully creates and removes the example.txt file then congratulations, you’re able to write to an SD card.
Next we want to see if we can get the Arduino to save our GPS readings to the SD card. Disconnect your Arduino from the computer. Put the GPS module back in place. In order to connect both the GPS and MicroSD card breakout board to 5V and Ground on the Arduino, we’ll want to bring the power and ground to the breadboard, and then connect it to each module.
Now, upload the following code to your Arduino. It’s best if the Arduino is back out on your window ledge so you can get a GPS reading. You can check to see what’s happening by opening the serial monitor, but make sure to change the baud rate to 115200 or else the characters won’t make much sense. You should be seeing rows of three values. First the longitude coordinate, next the latitude coordinate, and finally the unix timestamp.
#include “Wire.h”
#include “SD.h”
#include “SoftwareSerial.h”
#include “TinyGPS.h”
#include “RTClib.h”
const int chipSelect = 10;
RTC_Millis RTC;
File dataFile;
TinyGPS gps;
SoftwareSerial ss(3, 4);
void setup()
{
Serial.begin(115200);
Serial.print(“Initializing SD card…”);
ss.begin(9600);
pinMode(chipSelect, OUTPUT);
RTC.adjust(DateTime(__DATE__, __TIME__));
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
// don’t do anything more:
while (1) ;
}
Serial.println(“card initialized.”);
// Open up the file we’re going to log to!
dataFile = SD.open(“GPStest.txt”, FILE_WRITE);
if (! dataFile) {
Serial.println(“error opening GPStest.txt”);
// Wait forever since we cant write data
while (1) ;
}
}
void loop()
{
DateTime now = RTC.now();
bool newData = false;
for (unsigned long start = millis(); millis() – start < 1000;)
{
while (ss.available())
{
char c = ss.read();
// Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flat, flon;
unsigned long age;
int year;
byte month, day, hour, minute, second, hundredths;
gps.f_get_position(&flat, &flon, &age);
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
char sz[32];
sprintf(sz, “%02d/%02d/%02d, %02d:%02d:%02d, “,
month, day, year, hour, minute, second);
Serial.print(“”);
Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(“, “);
Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(“, “);
Serial.println(now.unixtime());
dataFile.print(“”);
dataFile.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
dataFile.print(“, “);
dataFile.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
dataFile.print(“, “);
dataFile.println(now.unixtime());
}
dataFile.flush();
delay(500);
}
Now unplug your Arduino and eject the MicroSD card from the breakout board. Find the SD card adapter and insert it into your computer, either with a card reader or directly if you have an SD card slot. See if there is a text file called GPSTEST.TXT. If there is, yay! If not, then I’d try reformatting your card and trying to write to it again. Open the text file and make sure the data has been written. Sometimes the file gets created but no data gets saved, and if this is your case, check your wiring, and try following LadyAda’s SD card tutorials.