Storing array in SDcard to store Image


I’m trying to store an array in a .txt file in an SDcard, to store an image to be printed on a LCD (84X48 Nokia 5110 LCD Module).

As long as I store the array directly in the Arduino, all works fine, but since I want to store many diferent images, it simply does not have enough memory…

So, I created a TXT file that look like this:

0x00,0x00,0x80,0xE0,0xF0,0x78,0x38,0x1C.... etc....

But could not make it work, since I can´t manage to convert each read value (ex: 0x00) into a byte to be printed.

So with the help of a Forum member, I managed to convert my byte array into a decimal array:

0,0,128,224,240,120,56,28.... etc....

Now the image is being printed, but too slow, since I can actualy see each byte being printed, while if I use a array store in memory, it’s instantaneous.

Here is my code:

#include <SPI.h>
#include <SD.h>

char TXTletter;
String LCDsymbol;

void setup(void){

File dataFile ="test.txt");
      TXTletter =;
      if (TXTletter != ' '){
          LCDsymbol += TXTletter;
      } else {
        LCDWrite(LCD_DATA, LCDsymbol.toInt());
        LCDsymbol = "";


I don’t believe this will be useful but here is my LCDWrite() function:

void LCDWrite(byte data_or_command, byte data) {
  digitalWrite(PIN_DC, data_or_command); //Tell the LCD that we are writing either to data or a command

  //Send the data
  digitalWrite(PIN_SCE, LOW);
  shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
  digitalWrite(PIN_SCE, HIGH);

any idea how to make this work properly?
that is, making the image appear as if it was stored in flash memory?

But could not make it work, since I can´t manage to convert each read value (ex: 0x00) into a byte to be printed.

There really is NO reason to write the data to the file with the leading 0x or to write the data in any base other than 10.

Now the image is being printed, but too slow

No kidding. Quit using the String class. All that memory allocation/deallocation IS going to take time.

Learn to read the data faster than one character at a time. There are methods in the SD class (or classes that it derives from) for reading an entire record at once. They will be MUCH faster.

Using NULL terminated char arrays, strtok(), atoi(), and reading more than one character at a time MIGHT improve the speed enough.

Thanks for your answer.

I'm googleing to try to understand what you mean with "strtok(), atoi()", but with no luck until now.

I'm also trying to find a way to read 2 character simultaneously... no luck ether...

Could you please give a simple example on how to approach both situation?

Write the array as raw bytes, much faster, no processing needed. This is a clear case for a binary file.

could you please give me an example of such array?

You alread use such an array. You mean "such a file".

You just read and write bytes to it. Raw bytes, no ASCII at all.

You already must have noticed by now that I'm a complete NOOB on this matter... but learning every day.

Could you please give me an example of how to create a RAW Byte file that will replicate the image I want to store, and how to read it later on?

I really appreciate all your help.

BMP format will solve this. You can manipulate it as an image on the PC (eg Paint) and the Arduino can read it easily. Make sure you save it as "uncompressed" as you don't need or want compression. There's lots of libraries out there that read BMPs. Most of them are written for other LCDs but the basic BMP functions can be copied. The trick is to know the offsets into the header to jump to the pixel data.

Thanks MorganS those where exelent guide lines.

I've been searching for this libraries, but most of them are for TFT and not for LCD, but I did found several for OLED. Since I'm waiting for one now, I'll hold and try with the OLED.

Thanks again all of you ;)