Datalogger - SD interface test

The SD interface test was carried out on 13 January 2011 and was the second test conducted towards integrating the datalogger hardware. The SD card is intended as the primary data storage media for the datalogger.


The code used is shown below. This is the simplest test case for the SD interface using the SDFileSystem library. The TextLCD library was also used for debug output.

Import programSDFileSystem

Allow SD Cards to be accessed as a standard filesystem

Import libraryTextLCD

TextLCD library for controlling various LCD panels based on the HD44780 4-bit interface


#include "mbed.h"
#include "SDFileSystem.h"
#include "TextLCD.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
SDFileSystem sd(p5, p6, p7, p8, "sd");
TextLCD lcd(p21, p22, p23, p24, p25, p26);

int main() {
    led1 = 1;
    lcd.printf("Opening... ");

    FILE *fp = fopen("/sd/sdtest.txt", "w");
    if(fp == NULL) {
    led2 = 1;
    lcd.printf("OK\nWriting... ");
    fprintf(fp, "This is text in a file\n");
    led3 = 1;



The SD card socket and connections are built into the CoolComponents Workshop Development board (link). I used version 2 of the board, but there is no difference with regard to the SD interface.


The result of a successful run:



  • With no SD card inserted, the program hangs trying to open the file. This needs to be investigated.

Please log in to post comments.