Hello I have made a small game using and Arduino Uno and a Nokia 5110 screen. I use bitmaps to draw the images onto the screen. The problem is that bitmaps take up a lot of space and I can only use up to three bitmaps before running out of space. Is it possible to use an SD card to store the bitmaps on and have a method in the Arduino code to load a bitmap at a certain time, like when a button is pushed?
Typically a bitmap for the Nokia 5110 (PCD8544) requires 504 bytes of memory (48*84/8). A bitmap as a initiated global variable will be stored in program memory, transfered to data memory on startup and then to the device (when drawn). Three bitmaps will use up 1.5 Kbyte. This is the limit for the Arduino Uno as an additional bitmap will require all data memory.
void * memcpy_P (void *, const void *, size_t)
The second trick is to transfer the bitmap directly from the program memory to the device. This may be supported by the library. If not the bitmap draw function will need to be updated to explicitly read program memory.
The upper limit for the bitmaps is now the size of the program memory (30 Kbyte, 60 bitmaps).
Yes, it is possible, but is it practical?
There's basically two ways of doing it:
- Load the entire bitmap into RAM for displaying multiple times
- Display the bitmap direct from the SD card.
As the Uno only has 2KiB of RAM that rather limits the size of bitmap that can be loaded into it. As you currently can have 3 bitmaps in flash (max 32KiB) I will assume they are considerably bigger than 2KiB each, so loading them into RAM is not really going to be doable on the Uno.
So the second option - drawing it direct from the SD card - is really the only practical way. The problem with that is reading from the SD card is considerably slower than reading from the internal Flash. That means that your screen updates could be really slow, which would seriously impact the playability of your game.
All that happens when you draw a bitmap normally is that a loop iterates through the data and interprets each bit of each byte as a pixel being on or off and sets the relevant pixel to be on or off on the screen. Instead of reading data from flash you just read bytes from the SD card and interpret them in exactly the same way. If you take a look at the bitmap drawing routine in your LCD library you will see how simple it is - replacing the Flash access with SD card reading should be a simple enough matter to implement in your own copy of the routine.
A much better option would be to use a more powerful Arduino - one that has considerably more flash, such as the Mega2560.