Arduino indexed messages

Recently I hand the need with an Arduino project to show lots of different messages on a graphical display. The storage of these messages would have far exceeded the available memory on my Arduino board.

Thankfully the graphical display I was using included an SD card slot that was accessible to the Arduino board.

After many hours of experimentation and frustration with the poorly documented SDFat library, I reverted to the inbuilt Arduino SD library.

The example code below shows a bare-bones function for retrieving these messages. It will look for a file named STRINGS.TXT in the root folder of the SD card and search through it line by line.

The first two characters on each line are the message code, and the rest of the line is the message (excluding newline). It is assumed that Linux line endings (\n) are used, rather than Windows line endings (\r\n), however you can achieve this on Windows by using a programming editor such as Notepad++ and selecting Edit -> EOL Conversion -> Unix (LF).

As usual, this is available on my Github repository.

To get a message, first create a char instance to contain it, and then pass that to the getMessage function – see below:

char msg[32];
getMessage("01", msg);

If you want to get longer messages, simply change the size of the char array allocated to message, and update the call to toCharArray for message.

Use with caution, as no error handling or debugging has been included in this example.

Leave a Reply

Your email address will not be published. Required fields are marked *