Mega + Sainsmart TFT 320x240 very slow displaying bmp from SD card


I’m using an arduino Mega with the Sainsmart shield and TFT+touch screen 320x240.
I’ve seen many posts regarding an error with the shield mine is ok, it’s just a matter of using
#include <UTFT.h>
#include <SD.h>
UTFT myGLCD(ITDB32S,38, 39, 40, 41);
pinMode(53, OUTPUT);
SD.begin(53) // this is the SD_CS

I have a 320x240 24bit bimaps saved on the SD card that I want to display on the screen but loading the image is too slow for me to use it.

Is there a way of improving the rendering speed? Using some other library? Improving the code?

I’ve seen examples with the C_array conversion instead of bmp but these files were loaded as
extern unsigned int …;
const PROGMEM ={…}.

but I’m afraid it will have too many kB for the Mega memory.
Can I read C_array files from the SD card? how?

Kind regards

The code I have to read the bmp files from the SD card is similar to UTFT:

void setup()
myGLCD.InitLCD(); myGLCD.clrScr();


//there is here some usual code reading the file size and checking if the header is BM; //OFFSET TO DIMENSIONS, JUST IN CASE IT ISN’T 320x240
word heightBMP = read32(myFile);
word widthBMP = read32(myFile);

if ((int)widthBMP > (int)heightBMP) {
width = (int)widthBMP;
height = (int)heightBMP;
else {
width = (int)heightBMP;
height = (int)widthBMP;

if (bmHeader) //Check if header = BM
word BPP = read32(myFile);

if ( BPP == 0x18) { //CHECK IF 24bit for TFT
yoff = (int) ( HALF_HEIGHT - (float)height/2.0 );

Serial.println(“offset (upper left corner)”);
Serial.print(“x_off = “); Serial.print(xoff); Serial.print(”\t”);
Serial.print("y_off = "); Serial.println(yoff);; //OFFSET TO DATA OFFSET
word bitmapOffset = read32(myFile);; //SEEK TO READ POSITION

for (int y = height; y > 0 ; y–) {
for (int x = 0; x < width ; x++) {
byte b =;
byte g =;
byte r =;

uint32_t read32(File f)
uint32_t result;
((uint8_t *)&result)[0] =; // LSB
((uint8_t *)&result)[1] =;
((uint8_t *)&result)[2] =;
((uint8_t *)&result)[3] =; // MSB
return result;

Would the screen display faster if it were a 256 color bmp file in the SD card? I'd like to try it but I'm not sure how to do it... What's the code to read 1 byte from a file?

Something like this? byte colorByte =;

But there must be a library of some sort to link the byte to the colour of the pixel... myGLCD.setColor(colorbyte); instead of myGLCD.setColor(r, g, b);

Another question is I don't know how to read a c_array file from a SD card instead of loading the c file into memory like it happens on the UTFT logo.c and tux.c examples.

I'd appreciate any help. Thanks


Did you say that the Mega shield from Sainsmart 320x240 can read BMP files from its SD reader?? I cant even make it work with RAW FILES, can you please attach your libraries and a simple INO example?

Thanks a lot!!!!

The UTFT works this TFT no probLem as said by me and Others on other threads UTOUCH is not as reliable.

Large BMP I assume in the C array format are simply difficult to render ro screen, if you look at the code in UTFT for bitmapdisplay with its scalling etc., it can never have been optimosed and IMO the combination for an embededX solution is adequatem but obviously games would be poor and unresponsive

Its houses for courses…