NEW TFTLCD library to MEGA project, faster, added new features

Hello, since TFTLCD is somewat broken when using 2.4" touchscreen display with Arduino Mega 2560 I started to poke with TFTLCD library.

Mike stated that he has modified the lib to include MEGA support, I downloaded it in order to get my shield to work. But it did not. I had eniteirely white screen only but touchscreen worked.

He has used the same display:

Since Mike talked of delays, I took 7h trip at night in order to get the library work with MEGA R3 board. The first new thing that I added were SPEED_DELAY define with informative comments. I needed to add 1 microsecond delay more to the library in order to get my display working.

Project and downloadable library here: TFTLCD2MEGA

Those who wonder lcd not working I confirm that the new library works with MEGA:

I am doing overwhouling the code to support direct port handling to speed up the writing's of the libray.

We were fed up to the slowness of MEGA which we taught to be superior combared to UNO, so our desing stage took last minute decision to move lcd display few point to away from mega pins and get 8bits for lcd from DIGTIAL PORTC. This will allow us to use direct port manipulation and be able to drive even faster than UNO the display. Because this movement, we needed the TFTLCD to adapt for the port manipulation change. So I tought, it needed new functions that allow code desinger to switch output port on the go. This needed only switch case to the write and read commands in order to read directly the 8 bits from ports. So:

If using MEGA I have added outputPort(char portletter) function and switch case statements on write commands. If using UNO, this function is not available because on UNO there is no full 8bit register available.

Usage:

void setup() {
   tft.initDisplay();
   tft.outputPort('C');
   //Instead of default shield pinout, all printing is done directly 8bit to PORTC for fast controller mode
   tft.outputPort('');
   //Default shield option is used again for printing.
   tft.outputPort('K');
   //Now direct printing to PORTK
}

As code are suggesting, you can now control many displays in loops what ever.

Supported PORT letters are: A, B, C, E, F, H, J, K, L

Ports D and G are not supported for limited pins atleast on MEGA. We leave board desinger the obtion to use D or G port to control the display or what ever other ports as long if desinger wants to use PORTA for lcd writes.

For next commit, I expect 4 times faster write commands in microsecond level or even more. Currently I am doing adding port manipulation to code, thus removing the DUE compliance, since DUE needs library of own. I am thinking that I may write also library for DUE doing direct DUE PORTA,B,C 32bit handling.

Great news! TFTLCD library has gotten blazing speed in UNO, also MEGA speed is improved a lot with UNO shields. Mega is slower tho becase 11 more sift register instructions per write to the ports. This all have made possible because shift to the portmanipulation. All reads and writes are now direct port commands instead of digitalWrites. This movement allowed to kill all delays in read and write because of cleanier signal when using port commands rather than digitalWrite which has quite a ugly rounded shape square wave.

Mega users will enjoy new function available. Either use second intializing function, where is char outputport added or use on the fly how you want output port changing with tft.outputPort('J'); till example.

Since I don't see the reson for give option for users to define ports with tft(cs, cd, wr, rd, reset) I am implelemting port manipulation mode to make cs, cd,wr and rd pinns default in same port, which means the same pins used by most Arduino shields. This enables direct port manipulation in controller code, to speed up the lcd control. Because image rendering speed matters, not code writing, the movement is right choice.

Hi,

Which version of Arduino you're using? The latest 1.6.2 can't translate something in that:

C:\Users\Zone\Documents\Arduino\libraries\TFTLCD\glcdfont.c:9:23: error: variable 'font' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char  font[] PROGMEM = {
                       ^
Virhe käännettäessä.

Fixed the error. NEW 1.6 avr-gcc needs const PROGMEM variables. SO changed the glcd font to const.

Some day I will add extended ascii font to the lib. Because atm no äöå letters.

Hello again, took my hard decision but I am forced to it since C is so old language, and by the char in 8 bits is really 7 bit caraghters with EOF -1. Since native exteneded ascii needs full 8bits to be able to get visible native special caraghters I have forced to change input chars to unsigned chars. This means not able to input to drawString anymore dirctly "myString" since c tryis to then add const char* to the function and will not compile. For this you must use global unsigned char textArray[100] like this:

unsigned char nativeText[] = "onko \x94ikein tam\x84?";
tft.drawString(10, 100, nativeText, WHITE, 2);

Here you cannot input directly öäåÖÄÅ and other language letters because arduino IDE does not support MSDOS font and instead all text is handled as UTF-8 so all greater than 127 letters are handled from extended ascii perspective wrongly.

Here is the extended ascii available to use with the library:

	0x1E,	0xA1,	0xA1,	0x61,	0x12,	 //  128	Ç	 
	0x3A,	0x40,	0x40,	0x20,	0x7A,	 //  129	ü	 
	0x38,	0x54,	0x54,	0x55,	0x59,	 //  130	é	 
	0x21,	0x55,	0x55,	0x79,	0x41,	 //  131	â	 
	0x21,	0x54,	0x54,	0x78,	0x41,	 //  132	ä	 
	0x21,	0x55,	0x54,	0x78,	0x40,	 //  133	à	 
	0x20,	0x54,	0x55,	0x79,	0x40,	 //  134	å	 
	0x0C,	0x1E,	0x52,	0x72,	0x12,	 //  135	ç	 
	0x39,	0x55,	0x55,	0x55,	0x59,	 //  136	ê	 
	0x39,	0x54,	0x54,	0x54,	0x59,	 //  137	ë	 
	0x39,	0x55,	0x54,	0x54,	0x58,	 //  138	è	 
	0x00,	0x00,	0x45,	0x7C,	0x41,	 //  139	ï	 
	0x00,	0x02,	0x45,	0x7D,	0x42,	 //  140	î	 
	0x00,	0x01,	0x45,	0x7C,	0x40,	 //  141	ì	 
	0xF0,	0x29,	0x24,	0x29,	0xF0,	 //  142	Ä	 
	0xF0,	0x28,	0x25,	0x28,	0xF0,	 //  143	Å	 
	0x7C,	0x54,	0x55,	0x45,	0x00,	 //  144	É	 
	0x20,	0x54,	0x54,	0x7C,	0x54,	 //  145	æ	 
	0x7C,	0x0A,	0x09,	0x7F,	0x49,	 //  146	Æ	 
	0x32,	0x49,	0x49,	0x49,	0x32,	 //  147	ô	 
	0x32,	0x48,	0x48,	0x48,	0x32,	 //  148	ö	 
	0x32,	0x4A,	0x48,	0x48,	0x30,	 //  149	ò	 
	0x3A,	0x41,	0x41,	0x21,	0x7A,	 //  150	û	 
	0x3A,	0x42,	0x40,	0x20,	0x78,	 //  151	ù	 
	0x00,	0x9D,	0xA0,	0xA0,	0x7D,	 //  152	ÿ	 
	0x39,	0x44,	0x44,	0x44,	0x39,	 //  153	Ö	 
	0x3D,	0x40,	0x40,	0x40,	0x3D,	 //  154	Ü	 
	0x3C,	0x24,	0xFF,	0x24,	0x24,	 //  155	¢	cent
	0x48,	0x7E,	0x49,	0x43,	0x66,	 //  156	£	pound
	0x2B,	0x2F,	0xFC,	0x2F,	0x2B,	 //  157	¥	yen
	0xFF,	0x09,	0x29,	0xF6,	0x20,	 //  158	₧	peseta
	0xC0,	0x88,	0x7E,	0x09,	0x03,	 //  159	ƒ	function
	0x20,	0x54,	0x54,	0x79,	0x41,	 //  160	á	 
	0x00,	0x00,	0x44,	0x7D,	0x41,	 //  161	í	 
	0x30,	0x48,	0x48,	0x4A,	0x32,	 //  162	ó	 
	0x38,	0x40,	0x40,	0x22,	0x7A,	 //  163	ú	 
	0x00,	0x7A,	0x0A,	0x0A,	0x72,	 //  164	ñ	 
	0x7D,	0x0D,	0x19,	0x31,	0x7D,	 //  165	Ñ	 
	0x26,	0x29,	0x29,	0x2F,	0x28,	 //  166	ª	 
	0x26,	0x29,	0x29,	0x29,	0x26,	 //  167	º	 
	0x30,	0x48,	0x4D,	0x40,	0x20,	 //  168	¿	 
	0x38,	0x08,	0x08,	0x08,	0x08,	 //  169	⌐	 
	0x08,	0x08,	0x08,	0x08,	0x38,	 //  170	¬	 
	0x2F,	0x10,	0xC8,	0xAC,	0xBA,	 //  171	½	 
	0x2F,	0x10,	0x28,	0x34,	0xFA,	 //  172	¼	 
	0x00,	0x00,	0x7B,	0x00,	0x00,	 //  173	¡	 
	0x08,	0x14,	0x2A,	0x14,	0x22,	 //  174	«	 
	0x22,	0x14,	0x2A,	0x14,	0x08,	 //  175	»	 
	0xAA,	0x00,	0x55,	0x00,	0xAA,	 //  176	░	 
	0xAA,	0x55,	0xAA,	0x55,	0xAA,	 //  177	▒	 
	0x00,	0x00,	0x00,	0xFF,	0x00,	 //  178	▓	 
	0x00,	0x00,	0xFF,	0x00,	0x00,	 //  179	│	 
	0x10,	0x10,	0x10,	0xFF,	0x00,	 //  180	┤	 
	0x14,	0x14,	0x14,	0xFF,	0x00,	 //  181	╡	 
	0x10,	0x10,	0xFF,	0x00,	0xFF,	 //  182	╢	 
	0x10,	0x10,	0xF0,	0x10,	0xF0,	 //  183	╖	 
	0x14,	0x14,	0x14,	0xFC,	0x00,	 //  184	╕	 
	0x14,	0x14,	0xF7,	0x00,	0xFF,	 //  185	╣	 
	0x00,	0x00,	0xFF,	0x00,	0xFF,	 //  186	║	 
	0x14,	0x14,	0xF4,	0x04,	0xFC,	 //  187	╗	 
	0x14,	0x14,	0x17,	0x10,	0x1F,	 //  188	╝	 
	0x10,	0x10,	0x1F,	0x10,	0x1F,	 //  189	╜	 
	0x14,	0x14,	0x14,	0x1F,	0x00,	 //  190	╛	 
	0x10,	0x10,	0x10,	0xF0,	0x00,	 //  191	┐	 
	0x00,	0x00,	0x00,	0x1F,	0x10,	 //  192	└	 
	0x10,	0x10,	0x10,	0x1F,	0x10,	 //  193	┴	 
	0x10,	0x10,	0x10,	0xF0,	0x10,	 //  194	┬	 
	0x00,	0x00,	0x00,	0xFF,	0x10,	 //  195	├	 
	0x10,	0x10,	0x10,	0x10,	0x10,	 //  196	─	 
	0x10,	0x10,	0x10,	0xFF,	0x10,	 //  197	┼	 
	0x00,	0x00,	0x00,	0xFF,	0x14,	 //  198	╞	 
	0x00,	0x00,	0xFF,	0x00,	0xFF,	 //  199	╟	 
	0x00,	0x00,	0x1F,	0x10,	0x17,	 //  200	╚	 
	0x00,	0x00,	0xFC,	0x04,	0xF4,	 //  201	╔	 
	0x14,	0x14,	0x17,	0x10,	0x17,	 //  202	╩	 
	0x14,	0x14,	0xF4,	0x04,	0xF4,	 //  203	╦	 
	0x00,	0x00,	0xFF,	0x00,	0xF7,	 //  204	╠	 
	0x14,	0x14,	0x14,	0x14,	0x14,	 //  205	═	 
	0x14,	0x14,	0xF7,	0x00,	0xF7,	 //  206	╬	 
	0x14,	0x14,	0x14,	0x17,	0x14,	 //  207	╧	 
	0x10,	0x10,	0x1F,	0x10,	0x1F,	 //  208	╨	 
	0x14,	0x14,	0x14,	0xF4,	0x14,	 //  209	╤	 
	0x10,	0x10,	0xF0,	0x10,	0xF0,	 //  210	╥	 
	0x00,	0x00,	0x1F,	0x10,	0x1F,	 //  211	╙	 
	0x00,	0x00,	0x00,	0x1F,	0x14,	 //  212	╘	 
	0x00,	0x00,	0x00,	0xFC,	0x14,	 //  213	╒	 
	0x00,	0x00,	0xF0,	0x10,	0xF0,	 //  214	╓	 
	0x10,	0x10,	0xFF,	0x10,	0xFF,	 //  215	╫	 
	0x14,	0x14,	0x14,	0xFF,	0x14,	 //  216	╪	 
	0x10,	0x10,	0x10,	0x1F,	0x00,	 //  217	┘	 
	0x00,	0x00,	0x00,	0xF0,	0x10,	 //  218	┌	 
	0xFF,	0xFF,	0xFF,	0xFF,	0xFF,	 //  219	█	 
	0xF0,	0xF0,	0xF0,	0xF0,	0xF0,	 //  220	▄	 
	0xFF,	0xFF,	0xFF,	0x00,	0x00,	 //  221	▌	 
	0x00,	0x00,	0x00,	0xFF,	0xFF,	 //  222	▐	 
	0x0F,	0x0F,	0x0F,	0x0F,	0x0F,	 //  223	▀	 
	0x38,	0x44,	0x44,	0x38,	0x44,	 //  224	α	Lowercase alpha
	0x7C,	0x2A,	0x2A,	0x3E,	0x14,	 //  225	ß	Lowercase beta
	0x7E,	0x02,	0x02,	0x06,	0x06,	 //  226	Γ	Uppercase gamma
	0x02,	0x7E,	0x02,	0x7E,	0x02,	 //  227	π	Lowercase pi
	0x63,	0x55,	0x49,	0x41,	0x63,	 //  228	Σ	Uppercase sigma
	0x38,	0x44,	0x44,	0x3C,	0x04,	 //  229	σ	Lowercase sigma
	0x40,	0x7E,	0x20,	0x1E,	0x20,	 //  230	µ	Lowercase mu
	0x06,	0x02,	0x7E,	0x02,	0x02,	 //  231	τ	Lowercase tau
	0x99,	0xA5,	0xE7,	0xA5,	0x99,	 //  232	Φ	Uppercase phi
	0x1C,	0x2A,	0x49,	0x2A,	0x1C,	 //  233	Θ	Uppercase theta
	0x4C,	0x72,	0x01,	0x72,	0x4C,	 //  234	Ω	Uppercase omega
	0x30,	0x4A,	0x4D,	0x4D,	0x30,	 //  235	δ	Lowercase delta
	0x30,	0x48,	0x78,	0x48,	0x30,	 //  236	∞	Infinity
	0xBC,	0x62,	0x5A,	0x46,	0x3D,	 //  237	φ	Lowercase phi
	0x3E,	0x49,	0x49,	0x49,	0x00,	 //  238	ε	Lowercase epsilon
	0x7E,	0x01,	0x01,	0x01,	0x7E,	 //  239	∩	 
	0x2A,	0x2A,	0x2A,	0x2A,	0x2A,	 //  240	≡	 
	0x44,	0x44,	0x5F,	0x44,	0x44,	 //  241	±	plus minus
	0x40,	0x51,	0x4A,	0x44,	0x40,	 //  242	≥	 
	0x40,	0x44,	0x4A,	0x51,	0x40,	 //  243	≤	 
	0x00,	0x00,	0xFF,	0x01,	0x03,	 //  244	⌠	 
	0xE0,	0x80,	0xFF,	0x00,	0x00,	 //  245	⌡	 
	0x08,	0x08,	0x6B,	0x6B,	0x08,	 //  246	º	 
	0x36,	0x12,	0x36,	0x24,	0x36,	 //  247	≈	 
	0x06,	0x0F,	0x09,	0x0F,	0x06,	 //  248	°	 
	0x00,	0x00,	0x18,	0x18,	0x00,	 //  249	∙	 
	0x00,	0x00,	0x10,	0x10,	0x00,	 //  250	·	 
	0x30,	0x40,	0xFF,	0x01,	0x01,	 //  251	√	radical
	0x00,	0x1F,	0x01,	0x01,	0x1E,	 //  252	ⁿ	 
	0x00,	0x19,	0x1D,	0x17,	0x12,	 //  253	²	 
	0x00,	0x3C,	0x3C,	0x3C,	0x3C,	 //  254	■	Black box 
	0X14,	0x3E,	0x55,	0x45,	0x41,	 //  255	€	Euro

So in order to find correct letter of your choice you must convert integer value to hex with your windows calcullator in programmer mode and exchange the letter like in example.

Hello again, I added to the extended ascii letters € symbol. I replaced 255 full color box with € so you can use \xFF to input € symbol to the output text.

Currently, the fast display code for MEGA and UNO renders touchScreen library unusable somewhat. I am looking the issue. On UNO some of our code works but some code parts do not and with MEGA direct port writes cause touch not work at all. LCD library is tho blazing fast in MEGA PORTC.

Jeroi:
We were fed up to the slowness of MEGA which we taught to be superior compared to UNO...

The UNO and Mega are much more capable than is often believed. The Mega is only really "better" than the UNO because it has more storage (RAM and FLASH), and more I/O pins. Processing power (Millions of instructions per second) is no different and it is still an 8 bit device. It is usually the software that lets it down.

I have an Arduino Mega (and TFT with 16 bit interface) running the entire UTFT_demo sketch 320 x 240 pixels in 3 seconds.... clearly the multi seconds delay() has to be taken out from between the tests for this.

The only "cheat" is plotting the 10,000 pixels at a fixed location because it takes about 3 seconds for the Mega to generate the 30,000 random 16 bit numbers required. I think this fair as who wants to generate 30,000 random numbers and plot 10,000 pixels!

320 x 480 raw pixel full colour image can be pulled of SD card AND fully displayed in 1.07 seconds.

320 x 480 full screen can be cleared to a single colour in 84 milliseconds (average 1.83 Megapixels per second) since we just need to generate write strobes in a tight loop.

See videos at bottom of Step 2 here, these show a humble UNO running the Adafruit graphicstest and UTFT demo with an SPI display.

Looks like you are doing a great job on your code by the way.

Hello, I have solved the touch issue. It was wrong Touch communication pins settings because LCD library is using PORTC instead the original pins.

Also we fixed the LCD module problem of flickering. The Display has filckering issues and it is because LM1117-3.3V regulator used onboard to add 3.3V for the display from 5V without onboard caps altought there is planned pads for them. The producer removed caps from the regulator so we soldered 10uF ceramics to there:

How ever 5V cap is not suited to UNO because USB port is so high that the cap touch the USB connector and therefore display pins are not able to connect to the ports. 5V cap needs mod. Also the board needs Arduin 3.3V mod. 10 uF regulator to 3.3V line is needed to added because it has noise and multimeter reads 3.9V from 3V3 Arduino pin after lcd module installed:

Now the Arduino 3V3 is stable indeed mutlimeter reading 3.29V stable.

Also the 5V cap joints are needed to shield with electrical tape anyway to prevent display get shorted to the ground via touching the usb connector.

Final mods:

Since 3.3V for the display makes U-type long line with 3 vias I added to end of the lines couble caps to make sure that display gets clean 3.3v. Not much improved tho.