Arduino Mega 2560 And 2.8 ITDB02 Shield

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am really struck hard with integrating Arduino Mega 2560 board and 2.8 ITDB02 Shield.

 

The shield is connected to board such that the SD cad slot with it is on the USB connector side. I believe that shield is properly plugged in at least. The first 2 pins (on USB connector) of Arduino is not used

 

Right Side                                Left Side
Reset                                           13
............                                   .....
A5                                              0 
 

Now I am using ITDB02 library where the first thing I have to initialize the data pins and others:

 

ITDB02::ITDB02(int D8,int D9, int D10,int D11, int D12,int D13, int D14,int D15,int RS, int WR,int CS, int RST)

 

So in my code I have something like below:

 

ITDB02 lcd(0,1,2,3,4,5,6,7,A2, A1, A3, A4);

Cause https://github.com/Smoke-And-Wir... states:

 

// Smoke And Wires 2.4 Shield pin usage:
// LCD Data Bit : 7 6 5 4 3 2 1 0
// Digital pin #: 7 6 5 4 3 2 9 8
// Uno port/pin : PD7 PD6 PD5 PD4 PD3 PD2 PB1 PB0
// Mega port/pin PH4 PH3 PE3 PG5 PE5 PE4 PH6 PH5
#define LCD_CS A3 // Chip Select
#define LCD_CD A2// Command/Data
#define LCD_WR A1// LCD Write
#define LCD_RD A0// LCD Read
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

Further I have to initialize the touch screen PINS, which as per document:

 


void ITDB02::Touchpin(int tclk,int tcs,int din,int dout, int irq)

I am a bit confused here about the PINS I have to use but as mentioned the TFT shield is connected properly to Arduino - my first aim is to print a char on screen - so:

 

//lcd.Touchpin(6,5,4,3,2);

I have commented it cause I understand that it is wrong.

 

Uploading the program does not displays simple text on screen - which makes me understand that the lcd() params are wrong:

 

ITDB02 lcd(0,1,2,3,4,5,6,7,A2, A1, A3, A4);

 

Please let me know what should be my params fof the ITDB02::ITDB02(int D8,int D9, int D10,int D11, int D12,int D13, int D14,int D15,int RS, int WR,int CS, int RST) constructor and Touchpin(int tclk,int tcs,int din,int dout, int irq) methods - it has been two days I am struggling to find unfortunately the screen is not displaying any text out put.

 

I believe that if I have these two method rightly set my display function will print character cause above are the methods to initialize and use the TFT.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looking on the ITEAD site http://imall.iteadstudio.com/im120417024.html the photos show a MEGA with a Mini-USB female connector.

 

Are you saying that the Shield does not fit correctly on a regular MEGA board with the standard USB connector ?

 

I would guess that you got example sketches with your shield.   Do they not work?

 

Most TFT libraries have examples for ITEAD displays and adaptors.

e.g. UTFT and Adafruit.

 

Can you post a link to your actual 2.8" module?

Not only do you have to match the Arduino pin numbers,   you need the correct TFT controller too !

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well please find the pics of the device - note how the TFT shield is little lifted at the USB connector side:

 

 

 

 

#include <ITDB02.h>
#define BOXWHL 50
#define VERTICAL 'V'
#define HORIZONTAL 'H'

ITDB02 lcd(0,1,2,3,4,5,6,7,A2, A1, A3, A4);

void Drawline(int startx, int starty, int endpos, char directions)
{
//Draw a line
}

void DrawSqBox(int startx, int starty, const int boxwhl, const char val)
{
//Square Box    
}

void CleanGUIScr()
{
  lcd.CleanLCD();
}

void InitGUI()
{
  randomSeed(analogRead(0));
  lcd.Initial(ITDB24);
  //lcd.Touchpin(6,5,4,3,2);
  lcd.CleanLCD();
  //lcd.TouchInitial();
}

void CreateGUI()
{
//Data Init
}

void GUIEvent()
{
     if(lcd.TouchIRQ() == 0 && EnableIRQ == 1)
     {
         //Screen touched
     }
     delay(200);
  }
}


void setup()
{
    InitGUI();
}

void loop()
{
    CreateGUI();
    GUIEvent();
    CleanGUIScr(); 
    ValidatePassWord();
    CleanGUIScr();   
}

 

Last Edited: Mon. Nov 3, 2014 - 01:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah-ha.    Someone a IteadStudio did an almighty cock-up !

 

I just looked at a typical 2.4" UNO shield e.g. http://www.ebay.co.uk/itm/2-4-Inch-2-4-TFT-LCD-Shield-Touch-Panel-Module-TF-Micro-SD-For-Arduino-UNO-R3-C-/131231342388?pt=LH_DefaultDomain_0&hash=item1e8dff5f34

 

The MicroSD socket fits neatly between the USB and Power-Jack.   So the Shield mates snugly on both UNO or MEGA.    And you can change MicroSD cards easily!

 

It look as if Itead does not sell your Shield any more.    They seem to just sell adapter Shields and regular non-shield TFTs.

 

Personally,    I would just buy a cheap Shield from Ebay.    Or you could remove the monster SDCard socket.

 

All the same,   I suspect that you will make good enough contact with your Itead shield.    So it comes down to matching the MEGA pin-out.    First off test it with a UNO.     Then compare the Itead schematic with the horrible MEGA pin-mapping.

 

From memory,   the MEGA has not got SPI on D10-D13.   So your SDCard will be very SLOW.    And all the D0-D7 pins are on different ports.    So the TFT will be pretty slow too.

 

David.

Last Edited: Mon. Nov 3, 2014 - 02:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Finally I found a solution but a couple of things that one should take care. I am sharing all the details so that anybody else can make use of my research work.

 

1. Sample and working Code provided by ITED technical support team:

 

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

This code is designed for Arduino board.

**********************************************/

/**********************************************
Define zone
**********************************************/
#define RS 59
#define WR 58
#define CS 57
#define RST 56

#define T_CLK 55
#define T_CS 60
#define T_DIN 54
#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;	 
	unsigned char value;

        value = (unsigned char) (c>>8);
        for(int i=0;i<8;i++)
        {
          if(value & 0x01)
          {
           switch(i)
           {
              case 0: PORTE|= 0x01;break;
              case 1: PORTE|= 0x02;break;
              case 2: PORTE|= 0x10;break;
              case 3: PORTE|= 0x20;break;
              case 4: PORTG|= 0x20;break;
              case 5: PORTE|= 0x08;break;
              case 6: PORTH|= 0x08;break;
              case 7: PORTH|= 0x10;break;
           }
          }
          else
          {
           switch(i)
           {
              case 0: PORTE&= ~0x01;break;
              case 1: PORTE&= ~0x02;break;
              case 2: PORTE&= ~0x10;break;
              case 3: PORTE&= ~0x20;break;
              case 4: PORTG&= ~0x20;break;
              case 5: PORTE&= ~0x08;break;
              case 6: PORTH&= ~0x08;break;
              case 7: PORTH&= ~0x10;break;
           }            
          }

          value=value>>1;
        }
	digitalWrite(WR,LOW);//LCD_WR=0;
	digitalWrite(WR,HIGH);//LCD_WR=1;
        value = (unsigned char) c;
        for(int i=0;i<8;i++)
        {
          
if(value & 0x01)
          {
           switch(i)
           {
              case 0: PORTE|= 0x01;break;
              case 1: PORTE|= 0x02;break;
              case 2: PORTE|= 0x10;break;
              case 3: PORTE|= 0x20;break;
              case 4: PORTG|= 0x20;break;
              case 5: PORTE|= 0x08;break;
              case 6: PORTH|= 0x08;break;
              case 7: PORTH|= 0x10;break;
           }
          }
          else
          {
           switch(i)
           {
              case 0: PORTE&= ~0x01;break;
              case 1: PORTE&= ~0x02;break;
              case 2: PORTE&= ~0x10;break;
              case 3: PORTE&= ~0x20;break;
              case 4: PORTG&= ~0x20;break;
              case 5: PORTE&= ~0x08;break;
              case 6: PORTH&= ~0x08;break;
              case 7: PORTH&= ~0x10;break;
           }            
          }

          value=value>>1;
        }	
		
	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;	 
	unsigned char value;
        value = (unsigned char) (c>>8);
        for(int i=0;i<8;i++)
        {
          
if(value & 0x01)
          {
           switch(i)
           {
              case 0: PORTE|= 0x01;break;
              case 1: PORTE|= 0x02;break;
              case 2: PORTE|= 0x10;break;
              case 3: PORTE|= 0x20;break;
              case 4: PORTG|= 0x20;break;
              case 5: PORTE|= 0x08;break;
              case 6: PORTH|= 0x08;break;
              case 7: PORTH|= 0x10;break;
           }
          }
          else
          {
           switch(i)
           {
              case 0: PORTE&= ~0x01;break;
              case 1: PORTE&= ~0x02;break;
              case 2: PORTE&= ~0x10;break;
              case 3: PORTE&= ~0x20;break;
              case 4: PORTG&= ~0x20;break;
              case 5: PORTE&= ~0x08;break;
              case 6: PORTH&= ~0x08;break;
              case 7: PORTH&= ~0x10;break;
           }            
          }

          value=value>>1;
        }
	digitalWrite(WR,LOW);//LCD_WR=0;
	digitalWrite(WR,HIGH);//LCD_WR=1;
        value = (unsigned char) c;
        for(int i=0;i<8;i++)
        {
          
          if(value & 0x01)
          {
           switch(i)
           {
              case 0: PORTE|= 0x01;break;
              case 1: PORTE|= 0x02;break;
              case 2: PORTE|= 0x10;break;
              case 3: PORTE|= 0x20;break;
              case 4: PORTG|= 0x20;break;
              case 5: PORTE|= 0x08;break;
              case 6: PORTH|= 0x08;break;
              case 7: PORTH|= 0x10;break;
           }
          }
          else
          {
           switch(i)
           {
              case 0: PORTE&= ~0x01;break;
              case 1: PORTE&= ~0x02;break;
              case 2: PORTE&= ~0x10;break;
              case 3: PORTE&= ~0x20;break;
              case 4: PORTG&= ~0x20;break;
              case 5: PORTE&= ~0x08;break;
              case 6: PORTH&= ~0x08;break;
              case 7: PORTH&= ~0x10;break;
           }            
          }

          value=value>>1;
        }	
		
	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;
        for(int a=0;a < 8;a++)
        {
            pinMode(a,OUTPUT);
        }
  
	digitalWrite(RST,HIGH);
      delay(1);	
	digitalWrite(RST,LOW);
	delay(1);
	
	digitalWrite(RST,HIGH);
	digitalWrite(CS,HIGH);
	digitalWrite(WR,HIGH);
	delay(20);

	
	Write_Command_Data(0x0001,0x0100); 
	Write_Command_Data(0x0002,0x0700); 
	Write_Command_Data(0x0003,0x1030); 
	Write_Command_Data(0x0004,0x0000); 
	Write_Command_Data(0x0008,0x0207);  
	Write_Command_Data(0x0009,0x0000);
	Write_Command_Data(0x000A,0x0000); 
	Write_Command_Data(0x000C,0x0000); 
	Write_Command_Data(0x000D,0x0000);
	Write_Command_Data(0x000F,0x0000);
	//power on sequence VGHVGL
	Write_Command_Data(0x0010,0x0000);   
	Write_Command_Data(0x0011,0x0007);  
	Write_Command_Data(0x0012,0x0000);  
	Write_Command_Data(0x0013,0x0000); 
	//vgh 
	Write_Command_Data(0x0010,0x1290);   
	Write_Command_Data(0x0011,0x0227);
	//delays(100);
	//vregiout 
	Write_Command_Data(0x0012,0x001d); //0x001b
	//delays(100); 
	//vom amplitude
	Write_Command_Data(0x0013,0x1500);
	//delays(100); 
	//vom H
	Write_Command_Data(0x0029,0x0018); 
	Write_Command_Data(0x002B,0x000D); 

	//gamma
	Write_Command_Data(0x0030,0x0004);
	Write_Command_Data(0x0031,0x0307);
	Write_Command_Data(0x0032,0x0002);// 0006
	Write_Command_Data(0x0035,0x0206);
	Write_Command_Data(0x0036,0x0408);
	Write_Command_Data(0x0037,0x0507); 
	Write_Command_Data(0x0038,0x0204);//0200
	Write_Command_Data(0x0039,0x0707); 
	Write_Command_Data(0x003C,0x0405);// 0504
	Write_Command_Data(0x003D,0x0F02); 
	//ram
	Write_Command_Data(0x0050,0x0000); 
	Write_Command_Data(0x0051,0x00EF);
	Write_Command_Data(0x0052,0x0000); 
	Write_Command_Data(0x0053,0x013F);  
	Write_Command_Data(0x0060,0xA700); 
	Write_Command_Data(0x0061,0x0001); 
	Write_Command_Data(0x006A,0x0000); 
	//
	Write_Command_Data(0x0080,0x0000); 
	Write_Command_Data(0x0081,0x0000); 
	Write_Command_Data(0x0082,0x0000); 
	Write_Command_Data(0x0083,0x0000); 
	Write_Command_Data(0x0084,0x0000); 
	Write_Command_Data(0x0085,0x0000); 
	//
	Write_Command_Data(0x0090,0x0010); 
	Write_Command_Data(0x0092,0x0600); 
	Write_Command_Data(0x0093,0x0003); 
	Write_Command_Data(0x0095,0x0110); 
	Write_Command_Data(0x0097,0x0000); 
	Write_Command_Data(0x0098,0x0000);
	Write_Command_Data(0x0007,0x0133);
}
void SetXY(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
  Write_Command_Data(WINDOW_XADDR_START,x0);
  Write_Command_Data(WINDOW_XADDR_END,x1);
  Write_Command_Data(WINDOW_YADDR_START,y0);
  Write_Command_Data(WINDOW_YADDR_END,y1);
  Write_Command_Data(GRAM_XADDR,x0);
  Write_Command_Data(GRAM_YADDR,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();

  
  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);
                 Write_Data('A');
	}
 
  
}

// UTFT_ViewFont (C)2014 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the included fonts.
//
// This demo was made for modules with a screen resolution 
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

2. They ITDB people advise to make use of UTFT library, though one can also make use of ITDB library, however the support for ITDB library has been replaced by UTFT lib. In case one has old ITDB library note the pins config mentioned in sample code above.

 

3. UTFT code can be downloaded from this website - http://henningkarlsen.com/electr... . I used this one so letting you know, maybe there can be an advanced or other versions too.

 

4. Note to make use of UTFT code the first un-comment the line in below header file:

 

Arduino\libraries\UTFT\hardware\avr\HW_AVR_defines.h file when you use with 2.8 shield.

//#define USE_UNO_SHIELD_ON_MEGA 1

5. Next you need to define the type of controller you are working with when using UTFT library. So the first line of you application code should contain:

 

#define __AVR__

 

If you are using Arduino Mega 2560.

 

6. Working code using UTFT library after un-commenting the line as mentioned in point 4:

 

#define __AVR__
#include <UTFT.h>

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

// Set the pins to the correct ones for your development shield
// ------------------------------------------------------------
// Arduino Uno / 2009:
// -------------------
// Standard Arduino Uno/2009 shield            : <display model>,A5,A4,A3,A2
// DisplayModule Arduino Uno TFT shield        : <display model>,A5,A4,A3,A2
//
// Arduino Mega:
// -------------------
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Mega      : <display model>,38,39,40,41
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB24,59,58,57,56);

void setup()
{
  myGLCD.InitLCD();

  myGLCD.clrScr();
}

void loop()
{
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);

  myGLCD.setFont(BigFont);
  myGLCD.print(" !\"#$%&'()*+,-./", CENTER, 0);
  myGLCD.print("0123456789:;<=>?", CENTER, 16);
  myGLCD.print("@ABCDEFGHIJKLMNO", CENTER, 32);
  myGLCD.print("PQRSTUVWXYZ[\\]^_", CENTER, 48);
  myGLCD.print("`abcdefghijklmno", CENTER, 64);
  myGLCD.print("pqrstuvwxyz{|}~ ", CENTER, 80);

  myGLCD.setFont(SmallFont);
  myGLCD.print(" !\"#$%&'()*+,-./0123456789:;<=>?", CENTER, 120);
  myGLCD.print("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", CENTER, 132);
  myGLCD.print("`abcdefghijklmnopqrstuvwxyz{|}~ ", CENTER, 144);

  myGLCD.setFont(SevenSegNumFont);
  myGLCD.print("0123456789", CENTER, 190);

  while(1) {};
}

 

Last Edited: Tue. Nov 4, 2014 - 07:15 AM