Writing to SD card on the Arch GPRS V2

Seeing as the Arch GPRS V2 board has an SD card, I thought it would be a good idea to set up some logging on it. This will be the Grove measurements in a CSV file, as well as system events in a log file.

Over the years, I have used emFile and FatFs to manage and write to SD cards…

This time, I decided to use the mbed SD Card File System, because it’s more convenient for me, trying new things is fun, and emFile costs money. The SDFileSystem library actually inherits the FATFileSystem library (FatFs), which is synced with the master on GitHub.

The SD Card File System information page on mbed has a short example, which has been made adapted in an example by Seeed, using the pin assignments for Seeeduino Arch and Seeeduino Arch Pro.

I found the pin assignment for the Seeeduino Arch was almost identical to the Arch GPRS V2. The correct pins can be read from the pinout provided on the product’s wiki.

Arch GPRS V2 pinout
Pinout for Arch GPRS V2. Note the SD card pins bottom left.

Using this, I initialised the file system object as follows.

#define PIN_MOSI        P1_22
#define PIN_MISO        P1_21
#define PIN_SCK         P1_20
#define PIN_CS          P1_23 
SDFileSystem sd(PIN_MOSI, PIN_MISO, PIN_SCK, PIN_CS, "sd");

I simply used the hello world example to actually write to a file.

mkdir("/sd/mydir", 0777); // 0777 ensures permissions
FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
if(fp == NULL) 
    myled1 = 1;    // error
fprintf(fp, "Hello fun SD Card World!");

After loading and running, I removed the SD card and found it had been successful.

SD test directory
Test file and directory on SD card used in Arch GPRS V2
Contents of SD test file
Contents of test file on SD card used in Arch GPRS V2

One thing I changed after checking the fopen documentation, and I recommend it, is to use "a" instead of "w". This will cause the file to append, rather than start again. Even though it says it appends, it will also create the file if it does not yet exist, so it can be used under any condition.

More information and experimentation will occur on this, and there are some other things in the documentation that I would like to draw attention to, but for now, this is enough of a demonstration of the concept.

One thought on “Writing to SD card on the Arch GPRS V2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s