This project is read-only.

Adafruit Fridgelogger

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
  • Red LED using pin D2
  • Green LED using pin D3
  • Light sensor using pin A0
  • Temperature Sensor using pin A1
  • Realtime clock using pins A4 and A5

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,light,temp");

// LEDs
OutputPort red = new OutputPort(Pins.GPIO_PIN_D2, false);
OutputPort green = new OutputPort(Pins.GPIO_PIN_D3, false);

// An analog light sensor
IADCPort light = new Netduino.ADC(Pins.GPIO_PIN_A0);
light.RangeSet(0, 1024);
// An analog temperature sensor
Tmp36 temperature = new Tmp36(new Netduino.ADC(Pins.GPIO_PIN_A1));

// Time module (comment out SetTime once, to set the clock)
DS1307 time = new DS1307();
/*time.SetTime(
    Day: 11,
    Month: 8,
    Year: 2012,
    Hour: 12,
    Minute: 0,
    Second: 0
);*/
time.Synchronize();

while (true)
{
    // Green status LED ON
    green.Write(true);

    // Builds the output
    string output = "";
    output += DateTime.Now.Ticks.ToString() + ", ";
    output += DateTime.Now.ToString() + ", ";
    output += light.RangeRead().ToString() + ", ";
    output += temperature.Temperature.ToString();

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

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

    // Green status LED OFF, Red status LED ON
    green.Write(false);
    red.Write(true);

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

    // Red status LED OFF
    red.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,light,temp")

' LEDs
Dim red As OutputPort = New OutputPort(Pins.GPIO_PIN_D2, False)
Dim green As OutputPort = New OutputPort(Pins.GPIO_PIN_D3, False)

' An analog light sensor
Dim light As IADCPort = New Netduino.ADC(Pins.GPIO_PIN_A0)
light.RangeSet(0, 1024)
' An analog temperature sensor
Dim temperature As Tmp36 = New Tmp36(New Netduino.ADC(Pins.GPIO_PIN_A1))

' Time module (comment out SetTime once, to set the clock)
Dim time As DS1307 = New DS1307()
'time.SetTime(
'    Day:=11,
'    Month:=8,
'    Year:=2012,
'    Hour:=12,
'    Minute:=0,
'    Second:=0
')
time.Synchronize()

Do
    ' Green status LED ON
    green.Write(True)

    ' Builds the output
    Dim output As String = ""
    output += DateTime.Now.Ticks.ToString() + ", "
    output += DateTime.Now.ToString() + ", "
    output += light.RangeRead().ToString() + ", "
    output += temperature.Temperature.ToString()

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

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

    ' Green status LED OFF, Red status LED ON
    green.Write(False)
    red.Write(True)

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

    ' Red status LED OFF
    red.Write(False)

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

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