arduino 1 code fits all tft lcd screen size?

ok so i am trying to make a code that will fit on all the tft lcd screens which are the 3.2" tft and the 7" tft screens....

for the 5" the resolution is the same as the 7" so i didnt mention it...

does anyone know how i can make this happen?

i currently have the size on a 3.2" tft screen but i wanted to make it workable on all the screens by enlarging the size to fit the 7" lcd screen...

this code here is for a 3.2" tft lcd that i want to be able to work with both the 3.2" and the 7" when changing a line under "//Change for Correct TFT LCD screen"

#include <UTFT.h>  // used to interface with the TFT display
//LCD TOUCH PANEL and ITDB02 MEGA SHIELD v1.1
//(Mega Shield utilizes pins 5V, 3V3, GND, 2-6, 20-41, & (50-53 for SD Card))
UTFT myGLCD(SSD1289,38,39,40,41);      //Uncomment this line for the 3.2" TFT Screen
//UTFT myGLCD(CTE70,38,39,40,41);      //Uncomment this line for the 7" TFT Screen



//Change for Correct TFT LCD screen
int x2 = ; // make this work for 7" TFT screen
int y2 = ; // make this work for 7" TFT screen
/*********************** MAIN SCREEN ********** dispScreen = 0 ************************/
void mainScreen()
{
     myGLCD.setColor(56, 142, 142);              //Draw Borders & Dividers Color
     myGLCD.drawRect(0, 0, 319, 239);            //Outside Border
  /*************************************** HEADER BOARDERS ******************************************/
     myGLCD.fillRect(1, 15, 318, 17);            //Bottom Header Divider
     myGLCD.fillRect(1, 47, 318, 50);            //Bottom Status indicator icon Divider
     myGLCD.drawRect(1, 18, 2, 46);              //Left Status indicator icon Divider
     myGLCD.drawRect(317, 18, 318, 46);          //Right Status indicator icon Divider
  /*************************************** HARDWARE COOLING BOARDERS ******************************************/  
     myGLCD.drawRect(0, 68, 150, 70);          //"Hardware cooling" bottom Horizontal Divider
     myGLCD.drawRect(0, 125, 150, 127);        //Horizontal Bottom Hardware Cooling Status Divider
  /*************************************** Center Split BOARDER ******************************************/  
     myGLCD.drawRect(150, 15, 152, 127);         //Vertical Center Divider
  /*************************************** TEMPERATURE MONITORS BOARDER ******************************************/
     myGLCD.drawRect(152, 68, 319, 70);          //"Temperature Monitors" bottom Horizontal Divider  
     myGLCD.drawRect(156, 92, 315, 94);          //Horizontal Top Temperature Status Divider
     myGLCD.drawRect(205, 88, 207, 125);         //Vertical Temperature Divider #1
     myGLCD.drawRect(265, 88, 267, 125);         //Vertical Temperature Divider #2
     myGLCD.drawRect(152, 125, 319, 127);        //Horizontal Bottom Temperature Divider
  /*************************************** TIME/DATE BOARDERS ******************************************/   
     myGLCD.drawRect(0, 224, 319, 226);          //Top Time/Date Divider
     
     myGLCD.drawRect(133, 127, 135, 224);        //Left Vertical "Dosage left" Divider
     
     myGLCD.drawRect(228, 127, 230, 180);        //Left Vertical Humidity Divider
     
     myGLCD.drawRect(228, 180, 319, 182);        //Settings icon top Horizontal Divider
     myGLCD.drawRect(228, 182, 230, 224);        //Left Settings icon Vertical Divider
     
     myGLCD.setColor(64, 64, 64);            
     myGLCD.fillRect(1, 1, 318, 14);             //Hearer Bar rect filled - Gray
     
}
/******************************** END OF MAIN SCREEN **********************************/

/*********************** Settings SCREEN ********** dispScreen = 1 ************************/
void setup() 
{
  Serial.begin(9600);
  

  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  
       
  mainScreen();
}

void loop() 
{
                    mainScreen();
                      
                    
}

Each of those coordinates is a certain percentage on the screen. What you need to do is check the screens resolution with the getDisplayXSize() and getDisplayYSize() functions from the UTFT library.

Once you map out the percentages and know the screen resolution, the buttons will/should automatically adjust to fit the screen.

Its a lot of math, but it should work if you do it correctly.

i know the screen resolution already,

the 3.2" tft is
x = 0-319
y = 0-239

the 5" and 7" lcd are
x = 0-799
y = 0-479

not sure how i would make it work with my sketch tho i tryed multiplying but it never ends up working correctly even with the math right...

Show me your math for your Bottom Header Divider. Keep in mind int vs float.

bryanmc1988:
i know the screen resolution already,

the 3.2" tft is
x = 0-319
y = 0-239

the 5" and 7" lcd are
x = 0-799
y = 0-479

not sure how i would make it work with my sketch tho i tryed multiplying but it never ends up working correctly even with the math right...

In both screens:

xmax = TFT_DISPLAYWIDTH
ymax = TFT_DISPLAYHEIGHT

Solution: select case

case 1: // 3.2"
   xmax = 319
   ymax = 239

case 2: // 5" or 7"
   xmax = 799
   ymax = 479

In the sketch for example:

myGLCD.drawCircle(xmax/2, ymax/2, ymax/14)

PD:

HazardsMind:
...Its a lot of math, but it should work if you do it correctly.

Example:
myGLCD.fillRect(1, 15, 318, 17);

Now find the percentages based on your screen size.
X Axis = (1, 318)
Y Axis = (15, 17);

Percentages:
0.003125 = 1 / 320(X axis of display, depending on Landscape or portrait mode)
0.99375 = 318 / 320.
0.0625 = 15 / 240(Y axis)
0.07083 = 17 / 240.

float Xmax = myGLCD.getDisplayXSize();
float Ymax = myGLCD.getDisplayYSize();
myGLCD.fillRect(0.003125 * Xmax, 0.0625 * Ymax, 0.99375 * Xmax, 0.07083 * Ymax)

well this is what i am doing and it seems to work out but i'm sure there is a much cleaner and less memory space up take...

//Change for Correct TFT LCD screen
//float x = 1;  //For TFT 3.2" 320x240
//float y = 1;  //For TFT 3.2" 320x240
float x = 2.504702194357367;  // For TFT 5"-7" 800x480
float y = 2.00418410041841;   // For TFT 5"-7" 800x480

/*********************** MAIN SCREEN ********** dispScreen = 0 ************************/
void mainScreen()
{
     myGLCD.setColor(56, 142, 142);              //Draw Borders & Dividers Color
     myGLCD.drawRect(0, 0, 319*x, 239*y);            //Outside Border
  /*************************************** HEADER BOARDERS ******************************************/
     myGLCD.fillRect(1, 15*y, 318*x, 17*y);            //Bottom Header Divider
     myGLCD.fillRect(1, 47*y, 318*x, 50*y);            //Bottom Status indicator icon Divider
  /*************************************** HARDWARE COOLING BOARDERS ******************************************/  
     myGLCD.drawRect(0, 68*y, 150*x, 70*y);          //"Hardware cooling" bottom Horizontal Divider
     myGLCD.drawRect(0, 125*y, 150*x, 127*y);        //Horizontal Bottom Hardware Cooling Status Divider
  /*************************************** Center Split BOARDER ******************************************/  
     myGLCD.drawRect(150*x, 50*y, 152*x, 127*y);         //Vertical Center Divider
  /*************************************** TEMPERATURE MONITORS BOARDER ******************************************/
     myGLCD.drawRect(152*x, 68*y, 319*x, 70*y);          //"Temperature Monitors" bottom Horizontal Divider  
     myGLCD.drawRect(156*x, 92*y, 315*x, 94*y);          //Horizontal Top Temperature Status Divider
     myGLCD.drawRect(205*x, 88*y, 207*x, 125*y);         //Vertical Temperature Divider #1
     myGLCD.drawRect(265*x, 88*y, 267*x, 125*y);         //Vertical Temperature Divider #2
     myGLCD.drawRect(152*x, 125*y, 319*x, 127*y);        //Horizontal Bottom Temperature Divider

i am having the issue with the "loadbitmap" now... my image is for a 3.2" tft but how do i multiply the pixel to get it to work on a 7" tft? or will i have to have 2 image with different size?

i know that with the "drawBitmap" you can set a multiplier at the end like so... myGLCD.drawBitmap(291, 150, 24, 24, Weather, 1);
as the 1 in the end is the pixel multiplier

so how would you do it with the "loadbitmap" ?

so after looking into the .cpp and the .h files of the UTFT and the UTFT_tinyFAT. i found out that what i was talking about above is called "Scaling"

now i'm not an expert but how would you combine the "Scaling" option of the UTFT into the UTFT_tinyFAT?

here is both .cpp and .h files of both parts dealing with the "Scaling" part, i hope you guys can combine these together to have it working for me as i have no clue on how to get it combine and working on the UTFT_tinyFAT with the Scaling option.

see below for the cpp and h files

UTFT Lib .cpp

void UTFT::drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale)
{
	unsigned int col;
	int tx, ty, tc, tsx, tsy;

	if (scale==1)
	{
		if (orient==PORTRAIT)
		{
			cbi(P_CS, B_CS);
			setXY(x, y, x+sx-1, y+sy-1);
			for (tc=0; tc<(sx*sy); tc++)
			{
				col=pgm_read_word(&data[tc]);
				LCD_Write_DATA(col>>8,col & 0xff);
			}
			sbi(P_CS, B_CS);
		}
		else
		{
			cbi(P_CS, B_CS);
			for (ty=0; ty<sy; ty++)
			{
				setXY(x, y+ty, x+sx-1, y+ty);
				for (tx=sx-1; tx>=0; tx--)
				{
					col=pgm_read_word(&data[(ty*sx)+tx]);
					LCD_Write_DATA(col>>8,col & 0xff);
				}
			}
			sbi(P_CS, B_CS);
		}
	}
	else
	{
		if (orient==PORTRAIT)
		{
			cbi(P_CS, B_CS);
			for (ty=0; ty<sy; ty++)
			{
				setXY(x, y+(ty*scale), x+((sx*scale)-1), y+(ty*scale)+scale);
				for (tsy=0; tsy<scale; tsy++)
					for (tx=0; tx<sx; tx++)
					{
						col=pgm_read_word(&data[(ty*sx)+tx]);
						for (tsx=0; tsx<scale; tsx++)
							LCD_Write_DATA(col>>8,col & 0xff);
					}
			}
			sbi(P_CS, B_CS);
		}
		else
		{
			cbi(P_CS, B_CS);
			for (ty=0; ty<sy; ty++)
			{
				for (tsy=0; tsy<scale; tsy++)
				{
					setXY(x, y+(ty*scale)+tsy, x+((sx*scale)-1), y+(ty*scale)+tsy);
					for (tx=sx-1; tx>=0; tx--)
					{
						col=pgm_read_word(&data[(ty*sx)+tx]);
						for (tsx=0; tsx<scale; tsx++)
							LCD_Write_DATA(col>>8,col & 0xff);
					}
				}
			}
			sbi(P_CS, B_CS);
		}
	}
	clrXY();
}

void UTFT::drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy)
{
	unsigned int col;
	int tx, ty, newx, newy;
	double radian;
	radian=deg*0.0175;  

	if (deg==0)
		drawBitmap(x, y, sx, sy, data);
	else
	{
		cbi(P_CS, B_CS);
		for (ty=0; ty<sy; ty++)
			for (tx=0; tx<sx; tx++)
			{
				col=pgm_read_word(&data[(ty*sx)+tx]);

				newx=x+rox+(((tx-rox)*cos(radian))-((ty-roy)*sin(radian)));
				newy=y+roy+(((ty-roy)*cos(radian))+((tx-rox)*sin(radian)));

				setXY(newx, newy, newx, newy);
				LCD_Write_DATA(col>>8,col & 0xff);
			}
		sbi(P_CS, B_CS);
	}
	clrXY();
}

UTFT Lib .h

class UTFT
{
	public:
		UTFT();
		UTFT(byte model, int RS, int WR, int CS, int RST, int SER=0);
		void	InitLCD(byte orientation=LANDSCAPE);
		void	clrScr();
		void	drawPixel(int x, int y);
		void	drawLine(int x1, int y1, int x2, int y2);
		void	fillScr(byte r, byte g, byte b);
		void	fillScr(word color);
		void	drawRect(int x1, int y1, int x2, int y2);
		void	drawRoundRect(int x1, int y1, int x2, int y2);
		void	fillRect(int x1, int y1, int x2, int y2);
		void	fillRoundRect(int x1, int y1, int x2, int y2);
		void	drawCircle(int x, int y, int radius);
		void	fillCircle(int x, int y, int radius);
		void	setColor(byte r, byte g, byte b);
		void	setColor(word color);
		word	getColor();
		void	setBackColor(byte r, byte g, byte b);
		void	setBackColor(uint32_t color);
		word	getBackColor();
		void	print(char *st, int x, int y, int deg=0);
		void	print(String st, int x, int y, int deg=0);
		void	printNumI(long num, int x, int y, int length=0, char filler=' ');
		void	printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
		void	setFont(uint8_t* font);
		uint8_t* getFont();
		uint8_t	getFontXsize();
		uint8_t	getFontYsize();
		void	drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale=1);
		void	drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy);
		void	lcdOff();
		void	lcdOn();
		void	setContrast(char c);
		int		getDisplayXSize();
		int		getDisplayYSize();
		void	setBrightness(byte br);
		void	setDisplayPage(byte page);
		void	setWritePage(byte page);

/*
	The functions and variables below should not normally be used.
	They have been left publicly available for use in add-on libraries
	that might need access to the lower level functions of UTFT.

	Please note that these functions and variables are not documented
	and I do not provide support on how to use them.
*/
		byte			fch, fcl, bch, bcl;
		byte			orient;
		long			disp_x_size, disp_y_size;
		byte			display_model, display_transfer_mode, display_serial_mode;
		regtype			*P_RS, *P_WR, *P_CS, *P_RST, *P_SDA, *P_SCL, *P_ALE;
		regsize			B_RS, B_WR, B_CS, B_RST, B_SDA, B_SCL, B_ALE;
		byte			__p1, __p2, __p3, __p4, __p5;
		_current_font	cfont;
		boolean			_transparent;

		void LCD_Writ_Bus(char VH,char VL, byte mode);
		void LCD_Write_COM(char VL);
		void LCD_Write_DATA(char VH,char VL);
		void LCD_Write_DATA(char VL);
		void LCD_Write_COM_DATA(char com1,int dat1);
		void _hw_special_init();
		void setPixel(word color);
		void drawHLine(int x, int y, int l);
		void drawVLine(int x, int y, int l);
		void printChar(byte c, int x, int y);
		void setXY(word x1, word y1, word x2, word y2);
		void clrXY();
		void rotateChar(byte c, int x, int y, int pos, int deg);
		void _set_direction_registers(byte mode);
		void _fast_fill_16(int ch, int cl, long pix);
		void _fast_fill_8(int ch, long pix);
		void _convert_float(char *buf, double num, int width, byte prec);
};

UTFT_tinyFAT .cpp:

#include "UTFT_tinyFAT.h"

UTFT_tinyFAT::UTFT_tinyFAT(UTFT *ptrUTFT)
{
	_UTFT = ptrUTFT;
}

word UTFT_tinyFAT::loadBitmap(int x, int y, int sx, int sy, char *filename)
{
	int res;
	int cx, cy, cp;
	word temp, result;
	byte r,g,b;

	res=file.openFile(filename, FILEMODE_BINARY);
	if (res==NO_ERROR)
	{
		cbi(_UTFT->P_CS, _UTFT->B_CS);
		cx=0;
		cy=0;
		result=512;
		if (_UTFT->orient==PORTRAIT)
		{
			_UTFT->setXY(x, y, x+sx-1, y+sy-1);
		}
		while (result==512)
		{
			result=file.readBinary();
			switch(result)
			{
				case ERROR_WRONG_FILEMODE:
					return ERROR_WRONG_FILEMODE;
					break;
				case ERROR_NO_FILE_OPEN:
					return ERROR_NO_FILE_OPEN;
					break;
				default:
					if (_UTFT->orient==PORTRAIT)
					{
						for (int i=0; i<result; i+=2)
							_UTFT->LCD_Write_DATA(file.buffer[i],file.buffer[i+1]);
					}
					else
					{
						cp=0;
						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->LCD_Write_DATA(file.buffer[cp+i],file.buffer[cp+i+1]);
								cx+=((result-cp)/2);
								cp=result;
							}
							else
							{
								_UTFT->setXY(x+cx, y+cy, x+sx-1, y+cy);
								for (int i=sx-cx-1; i>=0; i--)
									_UTFT->LCD_Write_DATA(file.buffer[cp+(i*2)],file.buffer[cp+(i*2)+1]);
								cp+=(sx-cx)*2;
								cx=0;
								cy++;
							}
						}
					}
					break;
			}              
		}
		file.closeFile();
		_UTFT->setXY(0,0,_UTFT->getDisplayXSize()-1,_UTFT->getDisplayYSize()-1);
		sbi(_UTFT->P_CS, _UTFT->B_CS);
		return 0;
	}
	else
	{
		return res;
	}
}

word UTFT_tinyFAT::loadBitmap(int x, int y, int sx, int sy, String filename)
{
	char buf[filename.length()+1];

	filename.toCharArray(buf, filename.length()+1);
	loadBitmap(x, y, sx, sy, buf);
}

UTFT_tinyFAT .h:

#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...
#endif
#include "tinyFAT.h"

class UTFT_tinyFAT
{
	public:
		UTFT_tinyFAT(UTFT *ptrUTFT);

		word loadBitmap(int x, int y, int sx, int sy, char *filename);
		word loadBitmap(int x, int y, int sx, int sy, String filename);

protected:
		UTFT *_UTFT;
};

#endif

Loadbitmap doesn't give you the option to have a scale, you see the image as is.

true but what i am asking is to combine it with the UTFT and code them together so that the tinyFAT has that option too....

To do that, you would need to rewrite the library.

You have both libraries, now compare and contrast them. What do you need to add to have your images scalled?

thats where i dont know how to do... and i need help on doing that... :cry:

Perhaps instead of modifying the library, you could search for other alternative libraries.
http://forum.arduino.cc/index.php?topic=288767.75

Read reply #79. Do a search for this library UTFT_SdRaw, and see what you get.

ok so i seems to have gotten the UTFT_SdRaw to load the image,

#include <UTFT.h>  // used to interface with the TFT display
#include <tinyFAT.h> // used to acess the SD card
//#include <UTFT_tinyFAT.h>  // used to read .raw images from the SD card
#include <UTFT_SdRaw.h>
#include <SdFat.h>
#include <SPI.h>

//LCD TOUCH PANEL and ITDB02 MEGA SHIELD v1.1
//(Mega Shield utilizes pins 5V, 3V3, GND, 2-6, 20-41, & (50-53 for SD Card))
//UTFT myGLCD(SSD1289,38,39,40,41);      //Uncomment this line for the 3.2" TFT Screen
UTFT myGLCD(CTE70,38,39,40,41);      //Uncomment this line for the 7" TFT Screen


//UTFT_tinyFAT myFiles(&myGLCD);  // start up an instance to read images from the SD card
UTFT_SdRaw myFiles(&myGLCD);
#define SD_CHIP_SELECT  53  // SD chip select pin
SdFat sd;

//Change for Correct TFT LCD screen
float x = 1;  //For TFT 3.2" 320x240
float y = 1;  //For TFT 3.2" 320x240
//float x = 2.504702194357367;  // For TFT 5"-7" 800x480
//float y = 2.00418410041841;   // For TFT 5"-7" 800x480
bool mysd = 0;
/*********************** MAIN SCREEN ********** dispScreen = 0 ************************/
void mainScreen()
{
     myGLCD.setColor(56, 142, 142);              //Draw Borders & Dividers Color
     myGLCD.drawRect(0, 0, 319*x, 239*y);            //Outside Border
  /*************************************** HEADER BOARDERS ******************************************/
     myGLCD.fillRect(1, 15*y, 318*x, 17*y);            //Bottom Header Divider
     myGLCD.fillRect(1, 47*y, 318*x, 50*y);            //Bottom Status indicator icon Divider
  /*************************************** HARDWARE COOLING BOARDERS ******************************************/  
     myGLCD.drawRect(0, 68*y, 150*x, 70*y);          //"Hardware cooling" bottom Horizontal Divider
     myGLCD.drawRect(0, 125*y, 150*x, 127*y);        //Horizontal Bottom Hardware Cooling Status Divider
  /*************************************** Center Split BOARDER ******************************************/  
     myGLCD.drawRect(150*x, 50*y, 152*x, 127*y);         //Vertical Center Divider
  /*************************************** TEMPERATURE MONITORS BOARDER ******************************************/
     myGLCD.drawRect(152*x, 68*y, 319*x, 70*y);          //"Temperature Monitors" bottom Horizontal Divider  
     myGLCD.drawRect(156*x, 92*y, 315*x, 94*y);          //Horizontal Top Temperature Status Divider
     myGLCD.drawRect(205*x, 88*y, 207*x, 125*y);         //Vertical Temperature Divider #1
     myGLCD.drawRect(265*x, 88*y, 267*x, 125*y);         //Vertical Temperature Divider #2
     myGLCD.drawRect(152*x, 125*y, 319*x, 127*y);        //Horizontal Bottom Temperature Divider
  /*************************************** TIME/DATE BOARDERS ******************************************/   
     myGLCD.drawRect(0, 224*y, 319*x, 226*y);          //Top Time/Date Divider
     
     myGLCD.drawRect(133*x, 127*y, 135*x, 224*y);        //Left Vertical "Dosage left" Divider
     
     myGLCD.drawRect(228*x, 127*y, 230*x, 180*y);        //Left Vertical Humidity Divider
     
     myGLCD.drawRect(228*x, 180*y, 319*x, 182*y);        //Settings icon top Horizontal Divider
     myGLCD.drawRect(228*x, 182*y, 230*x, 224*y);        //Left Settings icon Vertical Divider
     
     myGLCD.setColor(64, 64, 64);            
     myGLCD.fillRect(1, 1, 318*x, 14*y);             //Hearer Bar rect filled - Gray
     
    
     myFiles.load(6*x, 18*y, 28, 28, "Cool.raw", 1, 0);
}
/******************************** END OF MAIN SCREEN **********************************/

/*********************** Settings SCREEN ********** dispScreen = 1 ************************/
void setup() 
{
  Serial.begin(9600);

  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  
  file.setSSpin(53);                  // init SD card
  file.initFAT(SPISPEED_VERYHIGH);
  
  while (!mysd)
  {
    if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
      Serial.println(F("Card failed, or not present"));
      Serial.println(F("Retrying...."));
    }
    else
    {
      mysd = 1;
    }
  }
  
  mainScreen();
}

void loop() 
{
                      
                    
}

only issue is i cant seem to get it to scale out to be larger.... any idea on how to get it to work?

You would need to talk to the creator of the library.