The Micro-SD Shield and ArduinOO Code

I bought the excellent micro-SD shield for Arduino from the awesome folks at Little Bird Electronics for the miserly sum of $27.91 including pin-headers and freight. So far, great! Only after that did I download the applicable FAT16 library to run the SD card. Ugh! It's all C code. Well, mostly. Anyway, I've soldered on. Specifically, I first soldered on the pin-headers, then found a 256MB micro-SD in a failed Nokia phone, then whacked the shield on my Duemilanove, unzipped the libraries and ran the example project. Sweet, it all works.

Now back to the code. Having never really used C, looking at this code helps me think about the benefits of C++ and how I've just gone straight into writing what I'm now calling ArduinOO code. OO is just more logical, isn't it? I have read interesting things about "pure C" in the ┬ÁC space and some people's opinions on how pure C is "more dense" (produces smaller programs to achieve the same functionality). Others, obviously of the C++ persuasion, argue equally vigorously that C++ is "just as dense". Regardless of the high-level source, it all boils down to op-codes, registers and addresses anyway - so the two approaches could even produce identical machine code. Of course with the appropriate work this is all provable, but I'm not going to do it. Is it just a matter of taste? Or to put it better, is it more a matter of familiarity - do you just code the style you're used to?

So it leaves me to pick from two options. On the one hand I can incorporate these C libraries into my project and just have one foot in each camp. That's fine until I need to make any changes to, or heaven forfend, make corrections to the FAT16 library; then I'm rolling up my sleeves and working in pure C land. The alternative is to stick with the ArduinOO philosophy and write my own FAT16 library. I am an OO purist! I bringing the message of OO salvation to these simple Arduino folk who code in C! I will go forth and succeed! Then I looked at the includes:

#include <byteordering.h>
#include <fat.h>
#include <fat_config.h>
#include <partition.h>
#include <partition_config.h>
#include <sd-reader_config.h>
#include <sd_raw.h>
#include <sd_raw_config.h>

... and then I opened these files and read the pages of what for me, right now, is impenetrable C code. Dang. I'll need to put the "purist" aspirations on hold.

It's not that I haven't covered this ground before. When I didn't like the SoftwareSerial (all C) library for my GPS I wrote my own C++ class (OO) library to replace it. I didn't like the WString library and wrote my own C++ String class. But the micro-SD thing just requires so much hardware-level knowledge I just know it's going to be weeks of work. So I'm sitting on the fence until I really decide what to do. I think I'll go and write my LCD class while I think about it.

That is all.


Post a Comment