Comment faire fonctionner écran TFT avec Arduino Mega 2560 et librairie UTFT ?

Bonjour, je possède un Arduino Mega 2560 et un écran TFT 2.4" Touch Shield de chez iTead (modèle ITDB24E). Il s'insère directement sur les pins 3.3 V à Vin d'un coté et D0 à AREF de l'autre. Je ne comprends pas comment utiliser la librairie UTFT (qui par défaut fait utiliser les pins 19,18,17,16 ou 38,39,40,41 ; qui ne sont pas branchés avec ce shield) ...

Voici le modèle que je possède :

http://shop.boxtec.ch/touch-shield-p-40559.html?language=en

En essayant de modifier les pins dans le code ... je ne suis pas parvenu à afficher le moindre texte, ni la moindre forme ... Seulement un écran blanc qui refuse de bouger.
Merci d'avance pour votre aide, car je bloque vraiment ...

Bonjour

as-tu essayé le code de démonstration fourni sur le site que tu as sité dans ta demande?

Oui et j'en ai même testé plusieurs. Un des exemples est celui-ci :

// UTFT_Textrotation_Demo (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the textrotation-functions.
//
// This demo was made for modules with a screen resolution 
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

#include <UTFT.h>

// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];


UTFT myGLCD(ITDB24E_8,A5,A4,A3,A2);   // Remember to change the model parameter to suit your display module!

void setup()
{
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
}

void loop()
{
    myGLCD.print("Text rotation", 0, 0);
    myGLCD.setColor(0, 0, 255);
    myGLCD.print("0 degrees", 0, 16, 0);
    myGLCD.print("90 degrees", 319, 0, 90);
    myGLCD.print("180 degrees", 319, 239, 180);
    myGLCD.print("270 degrees", 0, 239, 270);

    myGLCD.setFont(SevenSegNumFont);
    myGLCD.setColor(0, 255, 0);
    myGLCD.print("45", 90, 100, 45);
    myGLCD.print("90", 200, 50, 90);
    myGLCD.print("180", 300, 200, 180);

  while (true) {};
}

J'ai changé le modèle pour mettre le mien (enfin je ne sais pas si je dois l'utiliser en 8 ou en 16 bits ... normalement pour pouvoir utiliser le tactile et la carte SD, je suis obligé de l'utiliser en 8 bits), et j'ai également mis les pins que je pensais être bon par rapport au map pin. Toujours écran blanc

Je parlais du code démo présent sur la page du vendeur

http://shop.boxtec.ch/pub/iteadstudio/DC_IM120417012_Arduino_2.4eTFT_shield.rar

Oui je l'ai testé aussi, mais je ne comprends pas comment ce code utilise la librairie SdFat pour afficher des données à l'écran. Et je comprends encore moins pourquoi ce programme associe des pins pour RST, T_CLK, T_IRQ, qui n'existent pas dans le map pin du constructeur celui-même qui fournit ce code ...

Ervann:
. Et je comprends encore moins pourquoi ce programme associe des pins pour RST, T_CLK, T_IRQ, qui n'existent pas dans le map pin du constructeur celui-même qui fournit ce code ...

tout est dans la doc

T_CLK, T_IRQ, T_CS, T_DIN et T_DOUT permettent de gérer l'écran tactile

Mets l'interrupteur en position 5V car tu utilise un arduino mega

Mais parcontre est-ce que ce code de démonstration donne des résultats ou écran blanc?

Ecran blanc ... Tous mes essais se sont soldés par un écran blanc.
Pourquoi dans le code de démonstration, on trouve un define pour le pin CS et un autre pour le pin T_CS alors que dans la doc, seul le TFT_CS existe ?

Si on ce refaire à la doc il y a une incoérence pour la connexion avec une mega 2560:

Arduino (doc du tft) -> Arduino MEGA -> TFT Shield
Gestion du TFT
D0 ->D0 -> DB8
D1 -> D1 -> DB9
D2 -> D2 -> DB10
D3 -> D3 -> DB11
D4 -> D4 -> DB12
D5 -> D5 -> DB13
D6 -> D6 -> DB14
D7 -> D7 -> DB15
A3 -> A2 -> TFT_CS
A4 -> A1 -> TFT_WR
A5 -> A0 -> TFT_RS

Gestion du tactil
D8 -> Touch_Dout
D9 -> Touch_IRQ
A0 -> A5 -> Touch_Din
A1 -> A4 -> Touch_CLK

Gestion de la carte SD en SPI
D10 -> SD_CS
D11 -> SD_MOSI
D12 -> SD_MISO
D13 -> SD_SCK

Déjà tu ne pourras pas utiliser ta carte SD car les broches SPI d'un Arduino MEGA 2560 sont en 50 à 53 contre 10 à 13 pour le UNO

Essaye ce code :

/**********************************************
Pay an attention!

This code is designed for Arduino Mega board.

**********************************************/
//#include <SdFat.h>
//Sd2Card card;
/**********************************************
Define zone
**********************************************/
#define RS A0
#define WR A1
#define CS A2
#define RST A3 //(a vérifier)



#define T_CLK 15
#define T_CS 20
#define T_DIN 14
#define T_DOUT 8
#define T_IRQ 9

#define X_CONST 240
#define Y_CONST 320

#define PREC_TOUCH_CONST 10

#define PixSizeX	13.78
#define PixOffsX	411

#define PixSizeY	11.01
#define PixOffsY	378

#define WINDOW_XADDR_START	0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END	0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START	0x0052 // Vertical Start Address Set
#define WINDOW_YADDR_END	0x0053 // Vertical End Address Set
#define GRAM_XADDR		    0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR		    0x0021 // GRAM Vertical Address Set
#define GRAMWR 			    0x0022 // memory write

/* LCD color */
#define White          0xFFFF
#define Black          0x0000
#define Blue           0x001F
#define Blue2          0x051F
#define Red            0xF800
#define Magenta        0xF81F
#define Green          0x07E0
#define Cyan           0x7FFF
#define Yellow         0xFFE0

/**********************************************
Val Zone
**********************************************/
int TP_X,TP_Y;


/**********************************************
Standard C functions zone
**********************************************/

void Write_Command(unsigned int c)
{
    digitalWrite(RS,LOW);//LCD_RS=0; 
	digitalWrite(CS,LOW);//LCD_CS =0;	 
	PORTD = c>>8; //LCD_DataPortH=DH>>8;
	digitalWrite(WR,LOW);//LCD_WR=0;
	digitalWrite(WR,HIGH);//LCD_WR=1;	
	PORTD = c;//LCD_DataPortH=DH;		
	digitalWrite(WR,LOW);//LCD_WR=0;
	digitalWrite(WR,HIGH);//LCD_WR=1;
	digitalWrite(CS,HIGH);//LCD_CS =0;
}


void Write_Data(unsigned int c)
{
    digitalWrite(RS,HIGH);//LCD_RS=0;
	digitalWrite(CS,LOW);//LCD_CS =0;	 
	PORTD = c>>8; //LCD_DataPortH=DH>>8;
	digitalWrite(WR,LOW);//LCD_WR=0;
	digitalWrite(WR,HIGH);//LCD_WR=1;	
	PORTD = c;//LCD_DataPortH=DH;		
	digitalWrite(WR,LOW);//LCD_WR=0;
	digitalWrite(WR,HIGH);//LCD_WR=1;
	digitalWrite(CS,HIGH);//LCD_CS =0;
}

void Write_Command_Data(unsigned int cmd,unsigned int dat)
{
	Write_Command(cmd);
	Write_Data(dat);
}

void Lcd_Init()
{
	pinMode(RS,OUTPUT);
	pinMode(WR,OUTPUT);
	pinMode(CS,OUTPUT);
	pinMode(RST,OUTPUT);
	
	DDRD = 0xFF;
  
	digitalWrite(RST,HIGH);
    delay(1);	
	digitalWrite(RST,LOW);
	delay(1);
	
	digitalWrite(RST,HIGH);
	digitalWrite(CS,HIGH);
	digitalWrite(WR,HIGH);
	delay(20);

	
	Write_Command_Data(0x0011,0x2004);		
    Write_Command_Data(0x0013,0xCC00);		
    Write_Command_Data(0x0015,0x2600);	
	Write_Command_Data(0x0014,0x252A);	
//	Write_Command_Data(0x14,0x002A);		
	Write_Command_Data(0x0012,0x0033);		
	Write_Command_Data(0x0013,0xCC04);		
	//delayms(1); 
	Write_Command_Data(0x0013,0xCC06);		
	//delayms(1); 
	Write_Command_Data(0x0013,0xCC4F);		
	//delayms(1); 
	Write_Command_Data(0x0013,0x674F);
	Write_Command_Data(0x0011,0x2003);
	//delayms(1); 	
	Write_Command_Data(0x0030,0x2609);		
	Write_Command_Data(0x0031,0x242C);		
	Write_Command_Data(0x0032,0x1F23);		
	Write_Command_Data(0x0033,0x2425);		
	Write_Command_Data(0x0034,0x2226);		
	Write_Command_Data(0x0035,0x2523);		
	Write_Command_Data(0x0036,0x1C1A);		
	Write_Command_Data(0x0037,0x131D);		
	Write_Command_Data(0x0038,0x0B11);		
	Write_Command_Data(0x0039,0x1210);		
	Write_Command_Data(0x003A,0x1315);		
	Write_Command_Data(0x003B,0x3619);		
	Write_Command_Data(0x003C,0x0D00);		
	Write_Command_Data(0x003D,0x000D);		
	Write_Command_Data(0x0016,0x0007);		
	Write_Command_Data(0x0002,0x0013);		
	Write_Command_Data(0x0003,0x0003);		
	Write_Command_Data(0x0001,0x0127);		
	//delayms(1); 
	Write_Command_Data(0x0008,0x0303);		
	Write_Command_Data(0x000A,0x000B);		
	Write_Command_Data(0x000B,0x0003);   
	Write_Command_Data(0x000C,0x0000);   
	Write_Command_Data(0x0041,0x0000);    
	Write_Command_Data(0x0050,0x0000);   
	Write_Command_Data(0x0060,0x0005);    
    Write_Command_Data(0x0070,0x000B);    
	Write_Command_Data(0x0071,0x0000);    
	Write_Command_Data(0x0078,0x0000);    
	Write_Command_Data(0x007A,0x0000);   
	Write_Command_Data(0x0079,0x0007);		
	Write_Command_Data(0x0007,0x0051);   
	//delayms(1); 	
	Write_Command_Data(0x0007,0x0053);		
	Write_Command_Data(0x0079,0x0000);

	Write_Command(0x0022);
	
}
void SetXY(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
  Write_Command_Data(0x0046,(x1 << 8)| x0);
  //Write_Command_Data(0x0047,x1);
  Write_Command_Data(0x0047,y1);
  Write_Command_Data(0x0048,y0);
  Write_Command_Data(0x0020,x0);
  Write_Command_Data(0x0021,y0);
  Write_Command (0x0022);//LCD_WriteCMD(GRAMWR);
}
void Pant(unsigned int color)
{
	int i,j;
	SetXY(0,239,0,319);

    for(i=0;i<320;i++)
	 {
	  for (j=0;j<240;j++)
	   	{
         Write_Data(color);
	    }

	  }		
}
void LCD_clear()
{
    unsigned int i,j;
	SetXY(0,239,0,319);
	for(i=0;i<X_CONST;i++)
	{
	    for(j=0;j<Y_CONST;j++)
		{    
          	Write_Data(0x0000);
		}
	}
}

void Touch_Init(void)
{
	pinMode(T_CLK,  OUTPUT);
    pinMode(T_CS,   OUTPUT);
    pinMode(T_DIN,  OUTPUT);
    pinMode(T_DOUT, INPUT);
    pinMode(T_IRQ,  INPUT);

	digitalWrite(T_CS,  HIGH);
	digitalWrite(T_CLK, HIGH);
	digitalWrite(T_DIN, HIGH);
	digitalWrite(T_CLK, HIGH);
}

void Touch_WriteData(unsigned char data)
{
	unsigned char temp;
	unsigned char nop;
	unsigned char count;

	temp=data;
	digitalWrite(T_CLK,LOW);

	for(count=0; count<8; count++)
	{
		if(temp & 0x80)
			digitalWrite(T_DIN, HIGH);
		else
			digitalWrite(T_DIN, LOW);
		temp = temp << 1; 
		digitalWrite(T_CLK, LOW);                
		nop++;
		digitalWrite(T_CLK, HIGH);
		nop++;
	}
}

unsigned int Touch_ReadData()
{
	unsigned char nop;
	unsigned int data = 0;
	unsigned char count;
	for(count=0; count<12; count++)
	{
		data <<= 1;
		digitalWrite(T_CLK, HIGH);               
		nop++;
		digitalWrite(T_CLK, LOW);
		nop++;
		if (digitalRead(T_DOUT))
			data++;
	}
	return(data);
}
void Touch_Read()
{
	unsigned long tx=0;
	unsigned long ty=0;

	digitalWrite(T_CS,LOW);                    

	for (int i=0; i<PREC_TOUCH_CONST; i++)
	{
		Touch_WriteData(0x90);        
		digitalWrite(T_CLK,HIGH);
		digitalWrite(T_CLK,LOW); 
		ty+=Touch_ReadData();

		Touch_WriteData(0xD0);      
		digitalWrite(T_CLK,HIGH);
		digitalWrite(T_CLK,LOW);
		tx+=Touch_ReadData();
	}

	digitalWrite(T_CS,HIGH);

	TP_X=tx/PREC_TOUCH_CONST;
	TP_Y=ty/PREC_TOUCH_CONST;
}

char Touch_DataAvailable()
{
  char avail;
  avail = !digitalRead(T_IRQ);
  return avail;
}

int Touch_GetX()
{
	int value;
	value = ((TP_X-PixOffsX)/PixSizeX);
	if (value < 0)
		value = 0;
	return value;
}
int Touch_GetY()
{
	int value;
	value = ((TP_Y-PixOffsY)/PixSizeY);
	if (value < 0)
		value = 0;
	return value;
}
/**********************************************
Arduino functions zone
**********************************************/
void setup()
{ 
  
  Lcd_Init();
  /*if (!card.init(SPI_EIGHTH_SPEED, 10))
  {
    while(1)
    {
      Pant(0xffff);
      Pant(0x0000);
    }
  }*/
  Touch_Init();
  LCD_clear();
	Pant(0xf800);
	Pant(0x07e0);
	Pant(0x001f);
	Pant(0xffff);
	Pant(0x0000);
}

void loop()
{
    unsigned int  i,j;
   	while(Touch_DataAvailable() == 1)
	{
		Touch_Read();
		i = Touch_GetX();
		j = Touch_GetY();
		SetXY(i,i,j,j);
		Write_Data(0xFFFF);
	}
 
  
}

J'ai testé mais écran blanc ...
par contre je ne comprends pas pourquoi tu attribues les pins 14 15 et 20 alors que le shield n'est branché sur aucun de ceux la.