Adafruit GPS Logger

This shield comes as a kit from Adafruit and works with Netduino.

Shield connections

The shield contains a few parts:
  • SD slot using pins D10 to D13
  • NMEA GPS module using pins D2 to D4
  • Red LED using pin D5
  • Green LED using pin D6

Sample code in C#

StorageDevice.MountSD("SD", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);

// Determines the filename
string filename = "";
int index = 0;
do
{
    filename = @"\SD\LOGGER" + Tools.ZeroFill(index, 2) + ".CSV";
    ++index;
}
while (File.Exists(filename));

// Starts writing to the file
FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);

// Writes file headers
writer.WriteLine("ticks,datetime,fix,latitude,longitude,altitude,satellites,kmh");

// The GPS unit is connected to COM2
NmeaGps gps = new NmeaGps("COM2");

// Lets power on the GPS unit (active: LOW)
OutputPort gps_enable = new OutputPort(Pins.GPIO_PIN_D4, false);

// LEDs are connected to pins 5 and 6
OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D5, false);
OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D6, false);

// Starts the GPS unit
gps.Start();

// Keeps on looping
while (true)
{
    // LED1 status ON
    led1.Write(true);

    // Builds the output
    string output = "";
    output += DateTime.Now.Ticks.ToString() + ", ";
    output += gps.GPSTime.ToString() + ", ";
    if (!gps.Fix)
        output += "0, 0, 0, 0, 0, 0";
    else
    {
        output += "1, ";
        output += gps.Latitude.ToString() + ", ";
        output += gps.Longitude.ToString() + ", ";
        output += gps.Altitude.ToString() + ", ";
        output += gps.Satellites.ToString() + ", ";
        output += gps.Kmh.ToString();
    }

    // Prints the output to the debugger
    Debug.Print(output);

    // Writes the output to the SD buffer
    writer.WriteLine(output);

    // LED1 status OFF, LED1 status ON
    led1.Write(false);
    led2.Write(true);

    // Flushes the buffers to the SD card
    writer.Flush();
    stream.Flush();

    // LED2 status OFF
    led2.Write(false);

    // Sleeps for a second
    Thread.Sleep(1000);
}

Sample code in VB

StorageDevice.MountSD("SD", SPI_Devices.SPI1, Pins.GPIO_PIN_D10)

' Determines the filename
Dim filename As String = ""
Dim index As Integer = 0
Do
    filename = "\SD\LOGGER" + Tools.ZeroFill(index, 2) + ".CSV"
    index = index + 1
Loop While File.Exists(filename)

' Starts writing to the file
Dim stream As FileStream = New FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)
Dim writer As StreamWriter = New StreamWriter(stream)

' Writes file headers
writer.WriteLine("ticks,datetime,fix,latitude,longitude,altitude,satellites,kmh")

' The GPS unit is connected to COM2
Dim gps As NmeaGps = New NmeaGps("COM2")

' Lets power on the GPS unit (active: LOW)
Dim gps_enable As OutputPort = New OutputPort(Pins.GPIO_PIN_D4, False)

' LEDs are connected to pins 5 and 6
Dim led1 As OutputPort = New OutputPort(Pins.GPIO_PIN_D5, False)
Dim led2 As OutputPort = New OutputPort(Pins.GPIO_PIN_D6, False)

' Starts the GPS unit
gps.Start()

Do
    ' LED1 status ON
    led1.Write(True)

    ' Builds the output
    Dim output As String = ""
    output += DateTime.Now.Ticks.ToString() + ", "
    output += gps.GPSTime.ToString() + ", "
    If Not gps.Fix Then
        output += "0, 0, 0, 0, 0, 0"
    Else

        output += "1, "
        output += gps.Latitude.ToString() + ", "
        output += gps.Longitude.ToString() + ", "
        output += gps.Altitude.ToString() + ", "
        output += gps.Satellites.ToString() + ", "
        output += gps.Kmh.ToString()
    End If

    ' Prints the output to the debugger
    Debug.Print(output)

    ' Writes the output to the SD buffer
    writer.WriteLine(output)

    ' LED1 status OFF, LED1 status ON
    led1.Write(False)
    led2.Write(True)

    ' Flushes the buffers to the SD card
    writer.Flush()
    stream.Flush()

    ' LED2 status OFF
    led2.Write(False)

    ' Sleeps for a second
    Thread.Sleep(1000)
Loop

Last edited Dec 29, 2012 at 7:36 AM by Garrcomm, version 2