The built-in 1 or 4 kilobyte EEPROM memory of an Arduino is quickly used up if you want to permanently store large amounts of data. So it makes sense to connect external mass storage devices in some cases. Fortunately there is already a library and various breakout modules available that allow to connect an SD card to the Arduino. But it is also possible (and not even difficult) to connect CompactFlash and even older hard drives, disk drives or CD- Rom drives to an Arduino Mega. This is due to the fact that CF cards are compatible with the parallel ATA (PATA) specification that was common until 2003. PATA compatible drives are also called IDE drives in common parlance. Unlike SD cards, IDE drives operate at 5V TTL level, so they can be directly connected to the Arduino´s IO Pins.
You can find the Arduino library files and examples on Github.
This allows you to do either low-level reads and writes on individual sectors or access files on FAT formatted volumes.
In this video I explain more in detail:
InstallationDownload the library and example files from Github and copy the files to your project or Arduino library folder. Wire the Arduino and hard disk as shown above. For CF Cards, PATA adapters are available.
Read and write raw dataDirectly read or write sectors of a hard disk or CF Card. See the "raw_io.ino" example in the example folder.
Read and write filesIf the SDFat library V2 from Bill Greiman is installed, data carriers formatted with FAT16 / 32 can also be read or written.
- Set #define SPI_DRIVER_SELECT 3 in SDFat/src/SdFatConfig.h
- Then uncomment "#define USE_FAT" in CFCard.h Most of the functions provided by the SDFat library should work with CF Cards and PATA drives as well. See the "file-io.ino" example.
- A downside of the SDFat library is however, that that it can only deal with volumes that have a master boot record (MBR). Compact Flash cards formatted with Windows don´t have an MBR, but Windows users need not despair. There is a free tool, called Rufus available that can format the drive so that it is accepted by the SdFat lib.
Comments