TFT-lcd Display improve output speed

Hi , I’m korean student.
I’m working on my project that tft-LCD display saved-image from SDcard. But display output speed very slow.
I use arduino mega, 7 inch tft -lcd and mega -lcd shield.

So, I want to know this : On the condition using the “myGLCD.drawPixelLine()” function, how to improve image output speed
Please help me?

void LoadImage(File& file)
  for (int y = 0; y < SCREEN_HEIGHT && file.available(); y++) {
    uint16_t buf[SCREEN_WIDTH];
    for (int x = SCREEN_WIDTH - 1; x >= 0; x--) {
      byte h =;
      byte l =;
      buf[x] = ((uint16_t)h << 8) | l;
    myGLCD.drawPixelLine(0, y, SCREEN_WIDTH, buf);


Hi brosman,

I did something similar some time ago, as you say, it is painfully slow when done that way. One way of speeding things up is read blocks of data from SD card, not repeated single byte reads as you are doing.

The way I did it was to modify UTFT_tinyFAT to utilize sdfatlib. My UTFT_tinyFAT.cpp looks something like this :-

#include "UTFT_tinyFAT.h"
#include <SdFat.h>
#include <SdFatUtil.h>
SdFile dataFile;

	_UTFT = ptrUTFT;

word UTFT_tinyFAT::loadBitmap(int x, int y, int sx, int sy, char *filename)
	char buffer[2*sx];
	int cx, cy, cp;
	word result;
	if (
		cbi(_UTFT->P_CS, _UTFT->B_CS);
		if (_UTFT->orient==PORTRAIT)
			_UTFT->setXY(x, y, x+sx-1, y+sy-1);
		for(int n=0;n<sy;n++)
			if (_UTFT->orient==PORTRAIT)
				for (int i=0; i<result; i+=2)
				while (cp<result)
					if (((result-cp)/2)<(sx-cx))
						_UTFT->setXY(x+cx, y+cy, x+cx+((result-cp)/2)-1, y+cy);
						for (int i=(result-cp)-2; i>=0; i-=2)
						_UTFT->setXY(x+cx, y+cy, x+sx-1, y+cy);
						for (int i=sx-cx-1; i>=0; i--)
		sbi(_UTFT->P_CS, _UTFT->B_CS);
		return 0;
		return 99;

Useage :- myGLCD.loadBitmap(x coordinate, y coordinate, x size, y size, filename);

This is almost certainly not the best way of doing it, as I am sure the Brattain’s and Edison’s will confirm, but it works well for me and is significantly faster than your method.

One point to mention!! If you have converted your images to .raw using Henning’s convertor, my routine has swapped the LSB and MSB, so the displayed images will have bad colour!! The reason I did that, was because I have lots of images, and I needed to be able to view them on PC before shifting to Arduino, and irfanview shows my images correctly, but not Henning’s.

Hope this helps! Any questions, feel free to ask.



Thank you for answer! :slight_smile:

But, I have a few questions. I try to modify UTFT_tinyFAT to utilize sdfatlib. And then,I tried to include it in the code.
However, The result is compile errors… =(

In file included from C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:18:
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\/UTFT_tinyFAT.h:30: error: expected `)' before '*' token
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\/UTFT_tinyFAT.h:36: error: ISO C++ forbids declaration of 'UTFT' with no type
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\/UTFT_tinyFAT.h:36: error: expected ';' before '*' token
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:22: error: 'SdFile' does not name a type
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:24: error: expected `)' before '*' token
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp: In member function 'word UTFT_tinyFAT::loadBitmap(int, int, int, int, char*)':
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:34: error: 'dataFile' was not declared in this scope
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:36: error: '_UTFT' was not declared in this scope
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:40: error: 'PORTRAIT' was not declared in this scope
C:\Users\brosman\Downloads\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\libraries\UTFT_tinyFAT\UTFT_tinyFAT.cpp:47: error: 'PORTRAIT' was not declared in this scope

I think that problem is both “SdFat.h” and “SdFatUtil.h” included “UTFT_tinyFAT.h”.
Because , “SD lib” and “SdFat lib” can’t co-exist in the same code. I use these : “UTFT1.h” , “SD.h”.
The two is needed in my code. So, Is there another way? :sweat_smile:

Hi brosman,


First of all i stopped using Arduino 1.0x a long time ago.......

Secondly, I suspect you don't have sdfatlib ? Get it here

I will get Arduino 1.0.5, and try it for you.




Looking at your errors, it is nothing to do with what version etc, you clearly have other problems…

  UTFT_tinyFAT.h - Add-on library to integrate UTFT and tinyFAT
  Copyright (C)2010-2013 Henning Karlsen. All right reserved
  Basic functionality of this library are based on the demo-code provided by
  ITead studio. You can find the latest version of the library at

  If you make any modifications or improvements to the code, I would appreciate
  that you share the code with me so that I might include it in the next release.
  I can be contacted through

  This library is free software; you can redistribute it and/or
  modify it under the terms of the CC BY-NC-SA 3.0 license.
  Please see the included documents for further information.

#ifndef UTFT_tinyFAT_h
#define UTFT_tinyFAT_h

#include <UTFT.h>
#if ((!defined(UTFT_VERSION)) || (UTFT_VERSION<241))
	#error : You will need UTFT v2.41 or higher to use this add-on library...
//#include "Arduino.h"
//#include "tinyFAT.h"

class UTFT_tinyFAT
		UTFT_tinyFAT(UTFT *ptrUTFT);

		word loadBitmap(int x, int y, int sx, int sy, char *filename);
//		word panBitmap(int x, int y, int sx, int sy, unsigned long offsetx, unsigned long offsety, unsigned long sizex, unsigned long sizey, char *filename);
//		word panBitmap(int x, int y, int sx, int sy, unsigned long offsetx, unsigned long offsety, unsigned long sizex, unsigned long sizey, char *filename, byte scale);



Why would you need SD if you have SdFat? Rewrite your code to entirely use SdFat? Since speed was your original complaint, SdFat is the better option over SD any day…



Aaah~ I was treated as a comment to this statement.

 //#if ((!defined(UTFT_VERSION)) || (UTFT_VERSION<241))
	//#error : You will need UTFT v2.41 or higher to use this add-on library...

I have SdFat library. And, SdFat lib and UTFT_tinyFAT lib are placed under the same folder.
As you said, I can use SdFat instead of SD. But ,If I use Sdfat , lcd image output is impossible. haha =(

Any way, I’ll do my best.
Your reply is very helpful !Thank you ! :slight_smile:


But ,If I use Sdfat , lcd image output is impossible. haha smiley-cry

How do you figure that then? Do you not think that is EXACTLY what I am doing?? SdFatlib + UTFT + UTOUCH + UTFT_tinyFat?



Hi again,

I just did some speed tests here, using DUE/CTE Shield/CPLD display, my modified UTFT_tinyFat library, and SdFatlib. It can draw a 240x240 raw image in 172ms, and a 440x440 raw image in 619ms.

I must admit I am not so happy with the 440X440 image speed.............if anybody else could step into this thread with any other ideas I am sure brosman and I would both appreciate it!



Hi brosman,

I forgot you initially said you are using a mega, sorry!

I found my mega2560, and coupled up my 5" display to do some tests for you.

The mega does not have enough ram to use a large buffer, so the only comparison I could do for you, was a buffer of 10*x and an image of 240x240 which takes 603ms and image of 440x440 takes 2047ms.

Apologies if this is not much better than what you had originally. =(

I now remember this is why I stopped developing my GPS app on the mega........ due to slow screen draw, and that was only using a 320*240 display! Now I have a 800*480 display, I cannot believe how slow it is :astonished: ask santa for a DUE ;)