Design and organization are the really tricky part of software development. While small projects work well without it, they never live long nor can they be extended in a easy way. This is especially true if your resources are limited.

The software of this project has to overcome some limitations of the hardware. I planed playing samples at 22.1kHz, which is feasible using a controller running at 16MHz. The really tricky part was simultaneously accessing the SD-Card while writing the samples to the DAC.

While there are many libraries out there to access SD-Cards, even read and write FAT file systems, none of them had the required simple timing necessary to stream large amounts of data to the DAC. Therefore I wrote a class which is optimized for simple and fast SD-Card access. I will explain this class later in detail.

Most libraries I found reading the files from a FAT-16 or FAT-32 file system. This is comfortable for the user, because he can simple copy files from his computer to the SD-Card, but at the end it is unnecessary complex to have a FAT file system on the SD-Card if your only goal is to stream some data from it.

A minimal file system.I solved this by creating a very simple own “file system”, which just allows to have a number of files with a defined name copied on the card. To make things simple, I write a script, which converts a directory with some files in it, into a special image file which I can simply copy on the SD-Card. I will explain this simple file system and the script to create it later in more detail.

All other parts are encapsulated into own classes like a class to handle the sensor, a class to access the DAC and even one to control the status LED. There are also some small helper classes for timing.

Keep things as simple as possible.I kept everything as simple as possible, therefore I do not use interrupts which are simple not necessary to create the software for this device. Because software development for the Arduino platform was quite new to me, I had a look in so many other projects and source codes to see how things are done. But because I have more than 20 year experience in software development, especially in C++, I was a little disturbed how slovenly most code was written. Often it has no structure, with an unnecessary overuse of macros and looked like throw away code, written once to use once and forget. I hope to show that this is not really necessary, good and fast code do not have to look like an unstructured mess.

In the next pages I will first explain the interface of the class, how to use it, and second how everything is implemented. If you are only interested how to use the class, copy it, read the into and use it.

Where to get the Source Code

You will find all source code of the prototype on GitHub at this location:

https://github.com/LuckyResistor/CatProtect

While it is possible I already published further development of this software, I marked the version I discuss on this pages with the tag v1.0. You can jump directly to this release using this URL:

https://github.com/LuckyResistor/CatProtect/releases/tag/v1.0

There you can download the version of the source code discussed on this pages.

Continue here: Access the SD-Card