ILI9327 3.5" LCD TFT with Arduino

Hi,

I need your help please.

I got an lcd tft screen from aliexpress. But I get only white screen when testing the UTFT exemple

// 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.
//

#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
// ------------------------------------------------------------
// My chipKit Uno32/uC32 shield                : <display model>,38,39,40,41
// My chipKit Max32 shield                     : <display model>,82,83,84,85
// AquaLEDSource All in One Super Screw Shield : <display model>,82,83,84,85
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB32S,82,83,84,85);

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) {};
}

lcd is here:

http://fr.aliexpress.com/item/3-5-inch-TFT-Touch-LCD-Screen-Display-Module-For-Arduino-UNO-R3-HIGH-QUALITY-NEW/1863849423.html

May I know why please?

Thanks

Your code

UTFT myGLCD(ITDB32S,82,83,84,85);

The topic and the advertisement refer to ILI 9327, which is the controller for the model ITDB32WC but your code refers the model ITDB32S which uses the SSD 1289 controller.

I assume you are using a

My chipKit Max32 shield

or a

AquaLEDSource All in One Super Screw Shield

Hi,
Thanks for you reply.

Yah the seller sent me details of an ILI9327, there is no details on the lcd board.

Well I changed model to ITDB32WC , but still white.

I use Arduino UNO

code based on
http://www.henningkarlsen.com/electronics/projects.php
works

You do not mention the shield you use - if any. Your code

UTFT myGLCD(ITDB32S,82,83,84,85);

refers to pin numbers on a shield, and a Uno does not have that many pins. It doesn't have the pins for code

My chipKit Uno32/uC32 shield                : <display model>,38,39,40,41

either.

The display looks like it might fit direct on a Uno without a shield, in which case you might be able to make it work, possibly at the exclusion of everything else. This will mean you will have to nominate a new set of pins, starting with SDA SCL being on A4,A5. It also means knowing which pins do what on the display.

I found you don't do any damage by quoting the wrong controller. My 240x400 got best results using CTE32HR and then shifting all the coordinates 40 left, but at least I had the proper shield for the job.

Ok,

This code works well:

// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// This demo code returns raw readings, public domain

#include <stdint.h>
#include "TouchScreen.h"

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  // a point object holds x y and z coordinates
  TSPoint p = ts.getPoint();
  
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > ts.pressureThreshhold) {
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
  }

  delay(100);
}

This code works welle too

//   ic:ili9327  
#define LCD_RD   A0
#define LCD_WR   A1     
#define LCD_RS   A2        
#define LCD_CS   A3       
#define LCD_REST A4

void Lcd_Writ_Bus(char VH)
{
  unsigned char i,temp,data; 
  data=VH;
  for(i=8;i<=9;i++)
  {
    temp=(data&0x01);
    if(temp)
      digitalWrite(i,HIGH);
    else
      digitalWrite(i,LOW);
    data=data>>1;
  }	
  for(i=2;i<=7;i++)
  {
    temp=(data&0x01);
    if(temp)
      digitalWrite(i,HIGH);
    else
      digitalWrite(i,LOW);
    data=data>>1;
  }	 

  digitalWrite(LCD_WR,LOW);
  digitalWrite(LCD_WR,HIGH);
}


void Lcd_Write_Com(char VH)  
{   
  digitalWrite(LCD_RS,LOW);
  Lcd_Writ_Bus(VH);
}

void Lcd_Write_Data(char VH)
{
  digitalWrite(LCD_RS,HIGH);
  Lcd_Writ_Bus(VH);
}

void Lcd_Write_Com_Data(int com,int dat)
{
  Lcd_Write_Com(com);
  Lcd_Write_Data(dat);
}

void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
  Lcd_Write_Com(0x2a); // Set_column_address 4 parameters
  Lcd_Write_Data(x1>>8);
  Lcd_Write_Data(x1);
  Lcd_Write_Data(x2>>8);
  Lcd_Write_Data(x2);

  Lcd_Write_Com(0x2b); // Set_page_address 4 parameters
  Lcd_Write_Data(y1>>8);
  Lcd_Write_Data(y1);
  Lcd_Write_Data(y2>>8);
  Lcd_Write_Data(y2);

  Lcd_Write_Com(0x2c); // Write_memory_start								 
}

void Lcd_Init(void)
{
  digitalWrite(LCD_REST,HIGH);
  delay(5); 
  digitalWrite(LCD_REST,LOW);
  delay(15);
  digitalWrite(LCD_REST,HIGH);
  delay(15);

  digitalWrite(LCD_CS,HIGH);
  digitalWrite(LCD_WR,HIGH);
  digitalWrite(LCD_CS,LOW);  //CS

  Lcd_Write_Com(0xE9);
  Lcd_Write_Data(0x20);

  Lcd_Write_Com(0x11); //Exit Sleep
  delay(100);

  Lcd_Write_Com(0xD1);
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x71);
  Lcd_Write_Data(0x19);

  Lcd_Write_Com(0xD0);
  Lcd_Write_Data(0x07);
  Lcd_Write_Data(0x01);
  Lcd_Write_Data(0x08);

  Lcd_Write_Com(0x36);
  Lcd_Write_Data(0x48);

  Lcd_Write_Com(0x3A);
  Lcd_Write_Data(0x05);

  Lcd_Write_Com(0xC1);
  Lcd_Write_Data(0x10);
  Lcd_Write_Data(0x10);
  Lcd_Write_Data(0x02);
  Lcd_Write_Data(0x02);

  Lcd_Write_Com(0xC0); //Set Default Gamma
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x35);
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x01);
  Lcd_Write_Data(0x02);

  Lcd_Write_Com(0xC5); //Set frame rate
  Lcd_Write_Data(0x04);

  Lcd_Write_Com(0xD2); //power setting
  Lcd_Write_Data(0x01);
  Lcd_Write_Data(0x44);

  Lcd_Write_Com(0xC8); //Set Gamma
  Lcd_Write_Data(0x04);
  Lcd_Write_Data(0x67);
  Lcd_Write_Data(0x35);
  Lcd_Write_Data(0x04);
  Lcd_Write_Data(0x08);
  Lcd_Write_Data(0x06);
  Lcd_Write_Data(0x24);
  Lcd_Write_Data(0x01);
  Lcd_Write_Data(0x37);
  Lcd_Write_Data(0x40);
  Lcd_Write_Data(0x03);
  Lcd_Write_Data(0x10);
  Lcd_Write_Data(0x08);
  Lcd_Write_Data(0x80);
  Lcd_Write_Data(0x00);

  Lcd_Write_Com(0x2A); 
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0xeF);

  Lcd_Write_Com(0x2B); 
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x00);
  Lcd_Write_Data(0x01);
  //  Lcd_Write_Data(0x3F);
  Lcd_Write_Data(0x8F); // on internet

  Lcd_Write_Com(0x29); //display on      

  Lcd_Write_Com(0x2C); //display on 

  digitalWrite(LCD_CS,HIGH);
}

void H_line(unsigned int x, unsigned int y, unsigned int l, unsigned int c)                   
{	
  unsigned int i,j;
  Lcd_Write_Com(0x02c); //write_memory_start
  digitalWrite(LCD_RS,HIGH);
  digitalWrite(LCD_CS,LOW);
  l=l+x;
  Address_set(x,y,l,y);
  j=l*2;
  for(i=1;i<=j;i++)
  {
    Lcd_Write_Data(c);
  }
  digitalWrite(LCD_CS,HIGH);   
}

void V_line(unsigned int x, unsigned int y, unsigned int l, unsigned int c)                   
{	
  unsigned int i,j;
  Lcd_Write_Com(0x02c); //write_memory_start
  digitalWrite(LCD_RS,HIGH);
  digitalWrite(LCD_CS,LOW);
  l=l+y;
  Address_set(x,y,x,l);
  j=l*2;
  for(i=1;i<=j;i++)
  {
    Lcd_Write_Data(c);
  }
  digitalWrite(LCD_CS,HIGH);   
}

void Rect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c)
{
  H_line(x  , y  , w, c);
  H_line(x  , y+h, w, c);
  V_line(x  , y  , h, c);
  V_line(x+w, y  , h, c);
}

void Rectf(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c)
{
  unsigned int i;
  for(i=0;i<h;i++)
  {
    H_line(x  , y  , w, c);
    H_line(x  , y+i, w, c);
  }
}

void LCD_Clear(unsigned int j)                   
{	
  unsigned int i,m;
  Lcd_Write_Com(0x02c); //write_memory_start
  digitalWrite(LCD_RS,HIGH);
  digitalWrite(LCD_CS,LOW);
  Address_set(0,0,479,399);

  for(i=0;i<480;i++)
    for(m=0;m<400;m++)
    {
      Lcd_Write_Data(j);
    }
  digitalWrite(LCD_CS,HIGH);   
}

void setup()
{
  for(int p=2;p<10;p++)
  {
    pinMode(p,OUTPUT);
  }
  pinMode(A0,OUTPUT);
  pinMode(A1,OUTPUT);
  pinMode(A2,OUTPUT);
  pinMode(A3,OUTPUT);
  pinMode(A4,OUTPUT);
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(A3, HIGH);
  digitalWrite(A4, HIGH);
  Lcd_Init();
  LCD_Clear(0x00);
}

void loop()
{  

  for(int i=0;i<1000;i++)
  {
    Rect(random(300),random(300),random(300),random(300),random(65535)); // rectangle at x, y, with, hight, color
  }
  LCD_Clear(0x00);
}

Is there a way to print "hello world" to screen using a simple code without library?

I found this library

http://www.spelecshop.com/1402480/563382/Touch-Panel-Display-for-Arduino.html

the lcd shield is like this, but mine is a 3.5" . I test it, SD card work but lcd look to response but i still cant get text or draws.

#define LCD_CS A3    
#define LCD_CD A2    
#define LCD_WR A1   
#define LCD_RD A0    
#define LCD_RESET A4

#define	BLACK           0x0000
#define	BLUE            0x001F
#define	RED             0xF800
#define	GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0 
#define WHITE           0xFFFF

#include "TFTLCD61505.h"
#include <SD.h>
const int chipSelect = 10;
byte count;

TFTLCD61505 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

void setup(void) 
{
  Serial.begin(9600);
  Serial.println("8 Bit LCD test!");
  Serial.print("Initializing SD card...");
  
  if (!SD.begin(chipSelect)) {
  Serial.println("Card failed, or not present");
  
  tft.reset();
  tft.initDisplay();
  carderror(RED);
  delay(2000);
  return;
  }
    Serial.println("card initialized.");
  tft.reset();
  tft.initDisplay();
  testtext(GREEN);
  delay(2000);
}

void loop(void) {
  String dataString = "";
  for (int analogPin = 0; analogPin < 5; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 4) {
      dataString += ","; 
    }
  }
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {    
    dataFile.println(dataString);
    dataFile.close();
    Serial.println(dataString); 
       
       if(count > 32 ){
       count = 0;
       testtext(RED);
       delay(2000);
       }
       else{
         
       delay(100);
       tft.setTextSize(1);
       tft.setTextColor(GREEN);
       tft.println(dataString);
       delay(100);
       count++;
       } 
    
     }

  else {
    Serial.println("error opening datalog.txt");
  }  
}
void testtext(uint16_t color) {
  tft.fillScreen(BLACK);
  tft.setCursor(85,0);
  tft.setTextColor(RED);
  tft.setTextSize(4);
  tft.println("S");
  tft.setCursor(110,0);
  tft.setTextColor(BLUE);
  tft.println("PS");
  tft.setTextSize(2);
  tft.setTextColor(GREEN);
  tft.println(" www.spelecshop.com");
}
void carderror(uint16_t color) {
  tft.fillScreen(BLACK);
  tft.setCursor(2,95);
  tft.setTextColor(RED);
  tft.setTextSize(4);
  tft.println("CARD ERROR");
}

The supplier doesn't have more details about the product. SO any body used this kind of LCD before?

Thanks

Hi All,

I make it working, to help all other people using such LCD TFT screen with Arduino UNO R3, I used

UTFT myGLCD(ILI9327_8,A2,A1,A3,A4);

This screen look to be an 8 bits

Hi,

Thank's dias1973 for second test code on post #4, also for me is work too on:

  • 3.5" LCD TFT for UNO R3 and also work on:
  • 2.4" LCD TFT for UNO R3

PS:
-this 2.4" LCD TFT for UNO R3 before this code just garbled pixels shows
reade posts #66 from:
http://forum.arduino.cc/index.php?topic=223769.60

Thanks

You welcome!

It work well on arduino UNO, But I can't make it working on mega 2560, I keep trying since yesterday. I connect the LCD screen to same pins of UNO but noway.

If any got it working please post your code. Thanks!

hola te recomiendo usar el siguiente tutorial y sobre todo un arduino mega es muy versatil ademas la cantidad de puertos que te quedan disponibles permite ampliar el proyecto, y si tienes alguna duda al momento de hacer el programa con la lcd no dudes en consultar buena noche

Hi eguar,

Thank you!, The problem is that I am using the same LCD I posted before (you can see link in my first post).

I connect it to Mega 2560 with pins A2, A1 A3, A4 (I connect it like to arduino UNO). but don't work.

Do you have any idea plz?

I had same problem as you. Display was working fine on uno but not on mega. I found solution on a russian forum here. Posts 302 and 308. So here is edited library that works for me.

H,

Thank you so much :slight_smile:

UTFT is ok now ! thanks :wink:

would it be possible to use utouch ?

I try this code:

#include <UTFT.h>
#include <stdint.h>
#include "TouchScreen.h"

bool Debug = true; //режим отладки

// These are the pins for the shield!
#define YP A2  
#define XM A1 
#define YM  6 
#define XP  7

#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define TS_MAXX 92
#define TS_MINX 936
#define TS_MAXY 135
#define TS_MINY 900

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);


extern uint8_t BigFont[];


UTFT myGLCD(31,A2,A1,A3,A4);

int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";

/*************************
**   Custom functions   **
*************************/

void drawButtons()
{
// Draw the upper row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x*60), 10, 60+(x*60), 60);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x*60), 10, 60+(x*60), 60);
    myGLCD.printNumI(x+1, 27+(x*60), 27);
  }
// Draw the center row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x*60), 70, 60+(x*60), 120);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x*60), 70, 60+(x*60), 120);
    if (x<4)
      myGLCD.printNumI(x+6, 27+(x*60), 87);
  }
  myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (10, 130, 150, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 130, 150, 180);
  myGLCD.print("Clear", 40, 147);
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (160, 130, 300, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (160, 130, 300, 180);
  myGLCD.print("Enter", 190, 147);
  myGLCD.setBackColor (0, 0, 0);
}

void updateStr(int val)
{

  if(Debug)
  {   
    char myChar = val;
    Serial.println(myChar);
  }
  if (stCurrentLen<20)
  {
    stCurrent[stCurrentLen]=val;
    stCurrent[stCurrentLen+1]='\0';
    stCurrentLen++;
    myGLCD.setColor(0, 255, 0);
    myGLCD.print(stCurrent, LEFT, 224);
  }
  else
  {
    myGLCD.setColor(255, 0, 0);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    delay(500);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    myGLCD.setColor(0, 255, 0);
  }
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
if(Debug)
 { Serial.print("\tx1:");  Serial.print(x1);
  Serial.print("\ty1");Serial.print(y1);
  Serial.print("\tx2");Serial.print(x2);
  Serial.print("\ty2");Serial.println(y2);}

myGLCD.setColor(255, 255, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  delay(500);
  TSPoint p = ts.getPoint();
  while      (p.z > MINPRESSURE && p.z < MAXPRESSURE) 
    TSPoint p = ts.getPoint();

  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  }

/*************************
**  Required functions  **
*************************/
void setup()
{
 if (Debug) { Serial.begin(9600);}
// Initial setup
  myGLCD.InitLCD();
  myGLCD.clrScr();

//  myTouch.InitTouch();
//  myTouch.setPrecision(PREC_MEDIUM);

  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  drawButtons();  
}

void loop()
{
  while (true)
  {
  // a point object holds x y and z coordinates
  TSPoint p = ts.getPoint();
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) 
//    if (myTouch.dataAvailable())
    {
/*
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
*/
  x = map(p.x, TS_MINX, TS_MAXX, 399, 0);
  y = map(p.y, TS_MINY, TS_MAXY, 239, 0);
  x = 400-x;
  y = 240-y;
     // x=(927-p.x)>>1;
if (Debug)  {  Serial.print("p,x:");Serial.print(x);}
    //  y=int((p.y-150)/3); // подгоняем
if (Debug)  {  Serial.print("\ty:");Serial.println(y);}

      if ((y>=10) && (y<=60))  // Upper row
      {
        if ((x>=10) && (x<=60))  // Button: 1
        {
          waitForIt(10, 10, 60, 60);
          updateStr('1');
        }
        if ((x>=70) && (x<=120))  // Button: 2
        {
          waitForIt(70, 10, 120, 60);
          updateStr('2');
        }
        if ((x>=130) && (x<=180))  // Button: 3
        {
          waitForIt(130, 10, 180, 60);
          updateStr('3');
        }
        if ((x>=190) && (x<=240))  // Button: 4
        {
          waitForIt(190, 10, 240, 60);
          updateStr('4');
        }
        if ((x>=250) && (x<=300))  // Button: 5
        {
          waitForIt(250, 10, 300, 60);
          updateStr('5');
        }
      }

      if ((y>=70) && (y<=120))  // Center row
      {
        if ((x>=10) && (x<=60))  // Button: 6
        {
          waitForIt(10, 70, 60, 120);
          updateStr('6');
        }
        if ((x>=70) && (x<=120))  // Button: 7
        {
          waitForIt(70, 70, 120, 120);
          updateStr('7');
        }
        if ((x>=130) && (x<=180))  // Button: 8
        {
          waitForIt(130, 70, 180, 120);
          updateStr('8');
        }
        if ((x>=190) && (x<=240))  // Button: 9
        {
          waitForIt(190, 70, 240, 120);
          updateStr('9');
        }
        if ((x>=250) && (x<=300))  // Button: 0
        {
          waitForIt(250, 70, 300, 120);
          updateStr('0');
        }
      }

      if ((y>=130) && (y<=180))  // Upper row
      {
        if ((x>=10) && (x<=150))  // Button: Clear
        {
          waitForIt(10, 130, 150, 180);
          stCurrent[0]='\0';
          stCurrentLen=0;
          myGLCD.setColor(0, 0, 0);
          myGLCD.fillRect(0, 224, 319, 239);
        }
        if ((x>=160) && (x<=300))  // Button: Enter
        {
          waitForIt(160, 130, 300, 180);
          if (stCurrentLen>0)
          {
            for (x=0; x<stCurrentLen+1; x++)
            {
              stLast[x]=stCurrent[x];
            }
            stCurrent[0]='\0';
            stCurrentLen=0;
            myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 208, 319, 239);
            myGLCD.setColor(0, 255, 0);
            myGLCD.print(stLast, LEFT, 208);
          }
          else
          {
            myGLCD.setColor(255, 0, 0);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            delay(500);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            myGLCD.setColor(0, 255, 0);
          }
        }
      }
    }
  }
}

I have the keyboard that appears.
I have a good return X Y touch.
but can not change the display!
the screen remains frozen no message appears as if UTFT no work.

thank you for your help

lolvince:
UTFT is ok now ! thanks :wink:

would it be possible to use utouch ?

I try this code:

#include <UTFT.h>

#include <stdint.h>
#include "TouchScreen.h"

bool Debug = true; //режим отладки

// These are the pins for the shield!
#define YP A2 
#define XM A1
#define YM  6
#define XP  7

#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define TS_MAXX 92
#define TS_MINX 936
#define TS_MAXY 135
#define TS_MINY 900

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

extern uint8_t BigFont[];

UTFT myGLCD(31,A2,A1,A3,A4);

int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";

/*************************
**  Custom functions  **
*************************/

void drawButtons()
{
// Draw the upper row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x60), 10, 60+(x60), 60);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x60), 10, 60+(x60), 60);
    myGLCD.printNumI(x+1, 27+(x60), 27);
  }
// Draw the center row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x
60), 70, 60+(x60), 120);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x
60), 70, 60+(x60), 120);
    if (x<4)
      myGLCD.printNumI(x+6, 27+(x
60), 87);
  }
  myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (10, 130, 150, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 130, 150, 180);
  myGLCD.print("Clear", 40, 147);
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (160, 130, 300, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (160, 130, 300, 180);
  myGLCD.print("Enter", 190, 147);
  myGLCD.setBackColor (0, 0, 0);
}

void updateStr(int val)
{

if(Debug)
  { 
    char myChar = val;
    Serial.println(myChar);
  }
  if (stCurrentLen<20)
  {
    stCurrent[stCurrentLen]=val;
    stCurrent[stCurrentLen+1]='\0';
    stCurrentLen++;
    myGLCD.setColor(0, 255, 0);
    myGLCD.print(stCurrent, LEFT, 224);
  }
  else
  {
    myGLCD.setColor(255, 0, 0);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    delay(500);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    myGLCD.setColor(0, 255, 0);
  }
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
if(Debug)
{ Serial.print("\tx1:");  Serial.print(x1);
  Serial.print("\ty1");Serial.print(y1);
  Serial.print("\tx2");Serial.print(x2);
  Serial.print("\ty2");Serial.println(y2);}

myGLCD.setColor(255, 255, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  delay(500);
  TSPoint p = ts.getPoint();
  while      (p.z > MINPRESSURE && p.z < MAXPRESSURE)
    TSPoint p = ts.getPoint();

myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  }

/*************************
**  Required functions  **
*************************/
void setup()
{
if (Debug) { Serial.begin(9600);}
// Initial setup
  myGLCD.InitLCD();
  myGLCD.clrScr();

//  myTouch.InitTouch();
//  myTouch.setPrecision(PREC_MEDIUM);

myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  drawButtons(); 
}

void loop()
{
  while (true)
  {
  // a point object holds x y and z coordinates
  TSPoint p = ts.getPoint();
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
//    if (myTouch.dataAvailable())
    {
/*
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
*/
  x = map(p.x, TS_MINX, TS_MAXX, 399, 0);
  y = map(p.y, TS_MINY, TS_MAXY, 239, 0);
  x = 400-x;
  y = 240-y;
    // x=(927-p.x)>>1;
if (Debug)  {  Serial.print("p,x:");Serial.print(x);}
    //  y=int((p.y-150)/3); // подгоняем
if (Debug)  {  Serial.print("\ty:");Serial.println(y);}

if ((y>=10) && (y<=60))  // Upper row
      {
        if ((x>=10) && (x<=60))  // Button: 1
        {
          waitForIt(10, 10, 60, 60);
          updateStr('1');
        }
        if ((x>=70) && (x<=120))  // Button: 2
        {
          waitForIt(70, 10, 120, 60);
          updateStr('2');
        }
        if ((x>=130) && (x<=180))  // Button: 3
        {
          waitForIt(130, 10, 180, 60);
          updateStr('3');
        }
        if ((x>=190) && (x<=240))  // Button: 4
        {
          waitForIt(190, 10, 240, 60);
          updateStr('4');
        }
        if ((x>=250) && (x<=300))  // Button: 5
        {
          waitForIt(250, 10, 300, 60);
          updateStr('5');
        }
      }

if ((y>=70) && (y<=120))  // Center row
      {
        if ((x>=10) && (x<=60))  // Button: 6
        {
          waitForIt(10, 70, 60, 120);
          updateStr('6');
        }
        if ((x>=70) && (x<=120))  // Button: 7
        {
          waitForIt(70, 70, 120, 120);
          updateStr('7');
        }
        if ((x>=130) && (x<=180))  // Button: 8
        {
          waitForIt(130, 70, 180, 120);
          updateStr('8');
        }
        if ((x>=190) && (x<=240))  // Button: 9
        {
          waitForIt(190, 70, 240, 120);
          updateStr('9');
        }
        if ((x>=250) && (x<=300))  // Button: 0
        {
          waitForIt(250, 70, 300, 120);
          updateStr('0');
        }
      }

if ((y>=130) && (y<=180))  // Upper row
      {
        if ((x>=10) && (x<=150))  // Button: Clear
        {
          waitForIt(10, 130, 150, 180);
          stCurrent[0]='\0';
          stCurrentLen=0;
          myGLCD.setColor(0, 0, 0);
          myGLCD.fillRect(0, 224, 319, 239);
        }
        if ((x>=160) && (x<=300))  // Button: Enter
        {
          waitForIt(160, 130, 300, 180);
          if (stCurrentLen>0)
          {
            for (x=0; x<stCurrentLen+1; x++)
            {
              stLast[x]=stCurrent[x];
            }
            stCurrent[0]='\0';
            stCurrentLen=0;
            myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 208, 319, 239);
            myGLCD.setColor(0, 255, 0);
            myGLCD.print(stLast, LEFT, 208);
          }
          else
          {
            myGLCD.setColor(255, 0, 0);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            delay(500);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            myGLCD.setColor(0, 255, 0);
          }
        }
      }
    }
  }
}




I have the keyboard that appears.
I have a good return X Y touch.
but can not change the display!
the screen remains frozen no message appears as if UTFT no work.

thank you for your help

Why this?

UTFT myGLCD(31,A2,A1,A3,A4);

Are you using the ILI9327 with arduino UNO? if it is the case you have to use what i posted before, and it work well

I read on the Russian forum that there should be this configuration.
for me it works with TLU library.
I'll try with "ILI9327_8" instead of "31" tonight.
EDIT => replace "31" to "ILI9327_8" is OK for me

but I did not manage to operate the touch screen is the same time.

dias1973:
Hi eguar,

Thank you!, The problem is that I am using the same LCD I posted before (you can see link in my first post).

I connect it to Mega 2560 with pins A2, A1 A3, A4 (I connect it like to arduino UNO). but don't work.

Do you have any idea plz?

I have uno and mega2560 with 3.5utft for uno by mcufriend.

i found here!

http://gnome.eu.org/index.php/Arduino_TFT_3.5inch_module

(31, A2, A1 A3, A4)

works fine. but slow and color is so strange.

Hello,
Could somebody test GitHub - dgolda/UTFT: Modified UTFT library working with ILI9327 8-bit for example 3.5" TFT LCD from mcufriend.com with ILI9327 8bit display for UNO?
I've just added some fixes and code compiles for UNO and works with my display for MEGA.
But I haven't display for UNO, so I cannot test if it works.

My display works with init code:
UTFT myGLCD(NIC35WS,A2,A1,A3,A4); //3.5" TFTLCD for arduino 2560 from mcufriend.com on UNO

Maybe version for UNO needs also A0 for LCD_RD, but I'm not sure...

Consegui este com o vendedor - http://pan.baidu.com/s/1gdy7UFp

Hello, everybody!

I have some problems with my new 3.5" TFT LCD.
It does not have a touchscreen and sd card slot (I have a single sd card module). Also it has different pinout, as a regular SPI. There is MCP23S17 inside. I just want to make it work.

I connected it to my arduino nano via usual spi, and it works well with the example that I found.

LCD -> NANO

3v3 - 3v3
GND - GND
SS - D10
SCK - D13
MOSI - D11
MISO - D12

"MCP23S17_9327_35_spi_8" example that works:

#include <SPI.h>              // We use this library, so it must be called here.
//
// GPA port - these show which wires from the LCD are connected to which pins on the I/O expander
//
#define LCD_RST  0b00001000	// reset                  0x08
#define LCD_RD   0b00010000	// not used               0x10
#define LCD_WR   0b00100000	// 1 = read; 0 = write    0x20
#define LCD_RS   0b01000000	// 1 = data; 0 = command  0x40
#define LCD_CS   0b10000000	// enable by toggling low 0x80

#define MCP23S17  B01000000       // MCP23017 SPI Address 

#define IODIRA    0x00            // MCP23017 address of I/O direction
#define IODIRB    0x01            // MCP23017 1=input
#define GPIOA     0x12            // MCP23017 address of GP Value
#define GPIOB     0x13            // MCP23017 address of GP Value

// SPI
#define SS        10               // Pin mapping to Arduino = SELECT
#define MOSI      11               // Pin mapping to Arduino = Master Out Slave In
#define SCLK      13               // Pin mapping to Arduino = Serial clock
#define MISO      12               // Pin mapping to Arduino = Master IN slave OUT

void setup()
{
  pinMode (SS, OUTPUT);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  SPI_portexpanderinit();
  initft();
  dis_color4(0xf800, 0x07e0, 0x001f, 0x07ff, 0xf81f, 0xffe0, 0x0000, 0xffff); //8色间隔画面
  SPI.end();
}

void loop(){}

void SPI_portexpanderinit()
{
  // --- Set I/O Direction
  SPI_TX(MCP23S17, IODIRB, B00000000);        // MCP23S17 port B = OUTPUT
  SPI_TX(MCP23S17, IODIRA, B00000000);        // MCP23S17 port A = OUTPUT
  //  --- Clear ALL Bits of GPIOA and GPIOB
  SPI_TX(MCP23S17, GPIOB, B00000000);         // MCP23S17 Clear port B
  SPI_TX(MCP23S17, GPIOA, B00000000);         // MCP23S17 Clear port A
}

void SPI_TX(int device, int regadd, int tx_data)
{
  PORTB &= 0b11111011;               // set CS low with direct write to digital pin 10
  SPI.transfer(device);              // device address write bit already 1ow
  SPI.transfer(regadd);
  SPI.transfer(tx_data);	
  PORTB |= 0b00000100;               // set CS high with direct write to digital pin 10
}

void cmd(int dat)
{ SPI_TX(MCP23S17, GPIOB, dat);
  SPI_TX(MCP23S17, GPIOA, B00011000);  //          10 08 toggle cs
  SPI_TX(MCP23S17, GPIOA, B10111000);  // 80    20 10 08
}
void writeData(int dat)
{ SPI_TX(MCP23S17, GPIOB, dat);
  SPI_TX(MCP23S17, GPIOA, B01011000);  //    40    10 08
  SPI_TX(MCP23S17, GPIOA, B11111000);  // 80 40 20 10 08 toggle cs, 
}

void initft()
{
  SPI_TX(MCP23S17, GPIOA, LCD_RST );
  delay(50);
  SPI_TX(MCP23S17, GPIOA, 0 );
  delay(10);
  SPI_TX(MCP23S17, GPIOA, B11111000);    // turn on all LCD control bits
  delay(50);
  cmd(0xE9);
  writeData (0x20);
  cmd(0x11); //Exit Sleep
  //delay(100);
  cmd(0xD1);
  writeData (0x00);
  writeData (0x71);
  writeData (0x19);
  cmd(0xD0);
  writeData (0x07);
  writeData (0x01);
  writeData (0x08);
  cmd(0x36);
  writeData (0x48);
  cmd(0x3A);
  writeData (0x05);
  cmd(0xC1);
  writeData (0x10);
  writeData (0x10);
  writeData (0x02);
  writeData (0x02);
  cmd(0xC0); //Set Default Gamma
  writeData (0x00);
  writeData (0x35);
  writeData (0x00);
  writeData (0x00);
  writeData (0x01);
  writeData (0x02);
  cmd(0xC5); //Set frame rate
  writeData (0x04);
  cmd(0xD2); //power setting
  writeData (0x01);
  writeData (0x44);
  cmd(0xC8); //Set Gamma
  writeData (0x04);
  writeData (0x67);
  writeData (0x35);
  writeData (0x04);
  writeData (0x08);
  writeData (0x06);
  writeData (0x24);
  writeData (0x01);
  writeData (0x37);
  writeData (0x40);
  writeData (0x03);
  writeData (0x10);
  writeData (0x08);
  writeData (0x80);
  writeData (0x00);
  cmd(0x2A);
  writeData (0x00);
  writeData (0x00);
  writeData (0x00);
  writeData (0xeF);
  cmd(0x2B);
  writeData (0x00);
  writeData (0x00);
  writeData (0x01);
  writeData (0x8F);
  cmd(0x29); //display on
  cmd(0x2C); //display on
  //delay(100);
}

//=============================8色彩间隔画面======================================//
void dis_color4(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int e, unsigned int f, unsigned int g, unsigned int h)
{
  unsigned int i, m;
  cmd(0x002c);
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, a >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, a);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, b >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, b);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, c >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, c);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, d >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, d);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, e >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, e);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, f >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, f);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, g >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, g);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }

  SPI_TX(MCP23S17, GPIOA, 0xf8 );
  for (i = 0; i < 50; i++)
    for (m = 0; m < 240; m++)
    {
      SPI_TX(MCP23S17, GPIOA, 0x58); //LCD_RST|LCD_RD|LCD_RS
      SPI_TX(MCP23S17, GPIOB, h >> 8);
      SPI_TX(MCP23S17, GPIOA, 0x78 ); //LCD_RST|LCD_WR|LCD_RS|LCD_RD
      SPI_TX(MCP23S17, GPIOA, 0x58);
      SPI_TX(MCP23S17, GPIOB, h);
      SPI_TX(MCP23S17, GPIOA, 0x78 );
    }
  SPI_TX(MCP23S17, GPIOA, 0xf8 );
}

Then I tried different versions of UTFT library, but have no result yet. Also there is no description how to connect my LCD to the arduino nano using UTFT library.

In "UTFT_Demo_400x200" example I wrote:
UTFT myGLCD(ILI9327_8,A2,A1,A3,A4);

I have no idea how to connect my LCD to arduino correctly using UTFT library, because there is no description or designation of A2,A1,A3,A4 pins in this example.

Help me please.