Arduino TFT 3.5inch module

From Evolution-plugins
Jump to: navigation, search

Tft1.jpg Tft2.jpg


This module was acquired via aliexpress.


There was no documentation available, no serial number to identify the module either.


All info (the only working code) I was able to find was here, it's merely a slow clrscreen function followed by the display of random empty(unfilled) rectangles.


This pointed me to the chip controlling the display ILI9327 running on 8 bits.


The next thing I found was the UTFT library, it's supposed to work with this shield but apparently did not.


There another info I could find here, it's in Russian, it was about different version of this shield as the shield was designed for the Arduino UNO or for Arduino MEGA, getting a shield designed for UNO to work on an Arduino MEGA was the trick!


From the initial program we're going to adapt Write Lcd_Writ_Bus() onto LCD_Writ_Bus8() for the 8bit mode.

Also LCD_Write_COM() and LCD_Write_DATA() need extra init sequence.

Prior to main InitLCD function we need to do extra init for this module.

As this module also uses digital pin 2-10 we will need to set them for output.

Lastly there is a define that enables certain fixups for this module's chip. (#define USE_UNO_SHIELD_ON_MEGA 1).


For convenience here's the patched library against latest git master (circa Sep 26 2014)

UTFT.cpp:

diff --git a/UTFT.cpp b/UTFT.cpp index a09ea9b..1474bde 100644 --- a/UTFT.cpp +++ b/UTFT.cpp @@ -163,16 +163,17 @@ UTFT::UTFT(byte model, int RS, int WR, int CS, int RST, int SER)

       }
}

-void UTFT::LCD_Write_COM(char VL) -{ +void UTFT::LCD_Write_COM(char VL) +{

       if (display_transfer_mode!=1)
       {
               cbi(P_RS, B_RS);
               LCD_Writ_Bus8(0x00,VL,display_transfer_mode);
        sbi(P_RS, B_RS);

- } - else + } else { + digitalWrite(A2,LOW);

               LCD_Writ_Bus8(0x00,VL,display_transfer_mode);

+ }

}

void UTFT::LCD_Write_DATA(char VH,char VL)

@@ -184,6 +185,7 @@ void UTFT::LCD_Write_DATA(char VH,char VL)

       }
       else
       {

+ digitalWrite(A2,HIGH);

               LCD_Writ_Bus8(0x01,VH,display_transfer_mode);
               LCD_Writ_Bus8(0x01,VL,display_transfer_mode);
       }

hardware/avr/HW_ATmega1280.h:

diff --git a/hardware/avr/HW_ATmega1280.h b/hardware/avr/HW_ATmega1280.h index a65bbcc..fc4f0ef 100644 --- a/hardware/avr/HW_ATmega1280.h +++ b/hardware/avr/HW_ATmega1280.h @@ -1,6 +1,8 @@

// *** Hardwarespecific functions ***
void UTFT::_hw_special_init()
{

+ pinMode(A0,OUTPUT); + digitalWrite(A0, HIGH);

}

void UTFT::LCD_Writ_Bus8(char VH,char VL, byte mode)

@@ -67,7 +69,7 @@ void UTFT::LCD_Writ_Bus8(char VH,char VL, byte mode)

               break;
       case 8:
#if defined(USE_UNO_SHIELD_ON_MEGA)

- PORTG &= ~0x20; + /*PORTG &= ~0x20;

               PORTG |= (VH & 0x10)<<1;
               PORTH &= ~0x18;
               PORTH |= (VH & 0xC0)>>3;

@@ -80,7 +82,29 @@


               PORTE |= (VL & 0x03) + ((VL & 0x0C)<<2) + ((VL & 0x20)>>2);

- pulse_low(P_WR, B_WR); + pulse_low(P_WR, B_WR);*/ +

+ data=VL; + + temp=(data&0x01); + + digitalWrite(i,HIGH); + + digitalWrite(i,LOW); + + } + for(i=2;i<=7;i++) { + temp=(data&0x01); + if(temp) + digitalWrite(i,HIGH); + else + digitalWrite(i,LOW); + data=data>>1; + } + + digitalWrite(A1,LOW); + digitalWrite(A1,HIGH);

#else
               PORTA = VL;
               pulse_low(P_WR, B_WR);

@@ -228,9 +252,13 @@ void UTFT::LCD_Writ_Bus16(char VH,char VL, byte mode)

void UTFT::_set_direction_registers(byte mode)
{
#if defined(USE_UNO_SHIELD_ON_MEGA)

+/*

       DDRH = 0x18;
       DDRG = 0x20;

- DDRE = 0x3B; + DDRE = 0x3B;*/ + for(int p=2;p<10;p++) { + pinMode(p,OUTPUT); + }

#else
       if (mode!=LATCHED_16)
       {

hardware/avr/HW_AVR_defines.h:

diff --git a/hardware/avr/HW_AVR_defines.h b/hardware/avr/HW_AVR_defines.h index 557778c..f775ac8 100644 --- a/hardware/avr/HW_AVR_defines.h +++ b/hardware/avr/HW_AVR_defines.h @@ -4,7 +4,7 @@

// ** Currently only available for 8bit display shields **
//
// Uncomment the following line to enable this feature

-//#define USE_UNO_SHIELD_ON_MEGA 1 +#define USE_UNO_SHIELD_ON_MEGA 1

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

// *** Hardwarespecific defines ***