Playing (SD) Cards on Hardware Mountain
The first thing I tried out on the shield adapter was the little nokia LCD on a prototyping shield. Next up is an SD card shield on sale at Radio Shack for $9.95.
The hardware connection is simple – it only wants the SPI connections: MISO, MOSI, and SCK, and a single slect pin which is hardwired to the Arduino digital pin 10 (which is my parallel output port bit 7). Unfortunately the software required is really gruesome. If you just wanted to read and write the card it’s simple enough – you can read or write 512 byte sectors to arbitrary byte addresses on the card using a protocol called MMC (for multi media card) over SPI. If you want to be able to share files with a PC though, you have to deal with it as a disk drive. I think Mike Riley did this in assembler (http://www.elf-emulation.com/) but I went my usual route of finding C++ code for arduino and converting it to C.
The code I converted is called tinyFat (http://www.henningkarlsen.com/electronics/library.php?id=37). It includes read and write support and directory manipulation for SD cards up to 2GB. The conversion was not terribly hard but it was tedious so I satisfied myself with getting file opening and reading working. The converted code lets you put files on the SD card with a PC and read them on the olduino. The image below shows the directory of an SD card and the contents of a text file. The code snippet is the part of the olduino program that does the directory listing.
The next picture shows the SD card shield on top of the shield adapter on top of the olduino on top of the membership card.
To return to the hardware mountain theme the next pictures show the nokia lcd with its own adapter on top of a protoshield on top of the SD card shield on top of the shield adapter on top of the olduino on top of the membership card – are we having fun yet? I haven’t actually tried the two shields together but they should work. The SPI bus is shared between all the slaves but each one has its own “slave select” signal(7 for the SD card and 4 for the LCD). The Olduino can address either one by driving its select pin low.
Despite the clunky hardware performance is really limited by the software. A raw sector read is taking about 350 ms which is about 1500 bytes/sec or 12,000 bits per second. The olduino is clocking the bus at 100,000 bits per second so there is huge overhead. Looking at the read sector routine I can see it would be trivially easy to improve it so I’ll do some of that before I try anything like animation.
Next up though, is a faster SPI clock and the ethernet shield again – stay tuned.