Cannot get the touchpanel working on MEGA2560 with ILI9341

Hi guys!

I am making a project for a friend with a 3.2" TFT display on an Arduino Mega 2560 with a V2.2 shield version.

The display is working the ILI9341_16 driver.

I downloaded the librairies UTFT and URTouch from Rinky-Dink (thanks to them!) to make the project work.
The UTFT demos worked perfectly but I cannot make it with the URTouch exemples.
It is like the touch panel isn't working (even with the calibration exemple)... Hopefully, I have a second TFT display (the same one) so I tried with this one and the result was the same... No response… :confused:

Do you already have the same kind of problem? Do you have any Ideas?

I just changed the definition of the pins, in order to match with the screen's driver and the Mega 2560:

UTFT myGLCD(ILI9341_16,38,39,40,41);
URTouch myTouch( 6, 5, 4, 3, 2);

Thank you very much in advance,

Alex

Sorry if I didn't give you enough informations…

The material is:

Below, you'll find the code used (which is from the URTouch exemples: Button Test):

// URTouch_ButtonTest 
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a quick demo of how create and use buttons.
//
// This program requires the UTFT library.
//
// It is assumed that the display module is connected to an
// appropriate shield or that you know how to change the pin 
// numbers in the setup.
//

#include <UTFT.h>
#include <URTouch.h>

// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due       : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board                   : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!
UTFT    myGLCD(ILI9341_16,38,39,40,41); 

// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due       :  6, 5, 4, 3, 2
// Teensy 3.x TFT Test Board                   : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
URTouch  myTouch( 6, 5, 4, 3, 2);

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

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 (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)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable())
    myTouch.read();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}

/*************************
**  Required functions  **
*************************/

void setup()
{
// 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)
  {
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      
      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);
          }
        }
      }
    }
  }
}

Please feel free if you need further informations…
Thanks,

Alex

I tryied to find some other Libraries, but Adafruit's is working only on Arduino UNO, not on MEGA and even after looking on the datasheet of the screen and the Library, I didn't know how to make it work on MEGA.
I tryied also with the XPT2046 library, witch is the touchpanel chip I have on my 320QVT_9341 TFT display. But same, only for UNO not for MEGA.

It seems like everybody is making it work with the URTouch library so I must have done something wrong, but I cannot find what...

Do I need to add something on the code than only change the parameters of myTouch() ?

Thanks for your help because I am really lost at this moment...

Alex

TFT_320QVT - Overview.pdf (327 KB)

I do not have a QVT screen. But many people do. AFIK, the QVT_9341 screen works fine with the ILI9341_16 "model" with UTFT.

Likewise, the QVT_9341 has a regular XPT2046 Touch controller.

There are several 40-pin adapters on the market. They normally map the TFT pin and Touch pins in the same way. i.e. the UTFT and URTouch examples should work straight out of the box. (model = ILI9341_16)

The 40-pin Adapter Shield is the mystery. You can never find the schematic for the v2.2 on the Internet. But it should be pretty easy to check it for yourself with a DMM. And compare it with a published schematic e.g. ElecFreaks v2.0.

If the TFT is working ok, you only have to worry about the XPT2046. I suspect that there is a reason why you can't find a V2.2 schematic.

David.

Thank you for your answer David!

Yes, the display part is OK, only the touch part isn't working...

Yes, it is with the XPT2046 tat it should be a problem, but I don't know how to fix it.
For you, it is a problem about the Shield?

How can I test it? You said with a DMM and compares with the schematic, but how can I tests the 40-pins?
I know how to test for +3.3V, 5V pins, but the others?

What Reason do you suspect that there is no schematic for V2.2?

Alex

You print the schematic for the v2.0 on paper.

Then with your DMM locate each pin on XPT2046 and the associated header pin. The DMM will read as 0R when you have copper trace. And register 10000R when you measure a 103 resistor.

As you pursue your detective work, tick each end of the connection on the schematic with a pencil.

You need to follow this meticulously. It costs you one or two sheets of paper and a pencil. Do not try to "do it in your head"

I suspect that v2.2 matches v2.0 pretty closely. The differences are probably copper trace shape and layout rather than the electrical connections.

I also suspect that the original design was from ElecFreaks. You just have a clone. But hey-ho, we all make mistakes. Chinese companies can make pcb mistakes too !!

David.

Thank you David for your quick answer,

So I have to check for all of the 40pins the output and the 20 on the XPT2046
But I can check that pin19 is 5V, pin6 is 3.3V, that pin2 is 5V and that pin1 is GND.
But all the other should be at 10kOhm resistor ?

Sorry if I seem stupid with my questions, it is the first time I'm doing this.

Alex

If you are unsure how to use a DMM, I suggest that you just wait for a few days. There are plenty of QVT_9341 owners on this Forum. And many of them will be using ElecFreaks Adapter Shields. Someone might even have your particular Chinese brand.

  1. I would assume your XPT2046 is ok. Many people have QVT_9341 board.

  2. Unplug the Adapter Shield.

  3. Follow all the relevant traces from the V2.0 schematic in the link I gave you.

  4. put probe#1 on CONN254 2x20 pin#29 (D_CLK on the 40-pin socket)
    put probe#2 on U5 pin#17 (D_CLK on 74HC541PW)

  5. repeat for D_CS, D_DIN, D_BUSY, D_OUT, D_IRQ

  6. repeat for all the other pins on the HC541 to connector J1

  7. it looks as if R1 is the only resistor on the Shield. And it has nothing to do with Touch.

You have to learn how integrated circuits are numbered. And how connectors are numbered. God invented Wikipedia to explain these schemes.

As I said earlier. Print the schematic on paper. Do not try to "remember in your head"

David.

Thanks for your answer David,

I tried to do what you explained to me, but I'm not sure if I'm doing it right.
I followed the schematic about the V2 and the PCB traces.

This is what I have (please tell me if I'm doing right or if I have to do Something else)
I follow the Schematics V2

And in the linked file "capture" it is the illustration of the shield with number for each chip or pin.
In the linked file "1" this is a capture of the excel document I've made with the linked between pins (when resistive was =0 Ohm) The couple are with the same color with the name of the pin shown on the schematic.

It seems to me that none of them are a right couple, so I think that I've made some mistake but I check several times..

Seriously, what do you expect me to do with your coloured boxes?

I gave you some practical advice. i.e. print schematic. tick each connection point with a pencil.

I doubt if V2.2 differs much from v2.0. You can either post a photo of your pencil ticked schematic or just describe any "different connection" in English.

David.

Sorry, it is just the way I've made it.
Because I wasn't sure of the sens of the 75HC541 chips but in any way, it doesn't work. But the links are:

2x20 PIN #29 (D_CLK) goes with 75HC541(4) #13
2x20 PIN #30 (D_CS) goes with 75HC541(4) #14
2x20 PIN #31 (D_DIN) goes with 75HC541(4) #15
2x20 PIN #32 (D_BUSY) goes with 75HC541(3) #19
2x20 PIN #33 (D_OUT) goes with 75HC541(3) #18
2x20 PIN #34 (D_IRQ) goes with 75HC541(3) #17

Not sure if that can better help you, let me know,
Thanks,

Alex

You appear to have different chip numbering and pin routeing. (ElecFreaks V2.0 schematic)

2x20 PIN #29 (D_CLK) goes with 75HC541(4) #13 (U5 #18)
2x20 PIN #30 (D_CS) goes with 75HC541(4) #14 (U5 #17)
2x20 PIN #31 (D_DIN) goes with 75HC541(4) #15 (U5 #16)
2x20 PIN #32 (D_BUSY) goes with 75HC541(3) #19 (U4 #18)
2x20 PIN #33 (D_OUT) goes with 75HC541(3) #18 (U4 #17)
2x20 PIN #34 (D_IRQ) goes with 75HC541(3) #17 (U4 #16)

Which looks consistent. But you really need to compare with how the signals go to J19.

You can make a similar table. However, all these things are fine in theory. Real life is more important. I would feel happier with seeing a pencil annotated schematic.

It is possible that the XPT2046 is badly soldered on the display pcb.
I would be more suspicious of a "clone" Adapter. Especially when they have not copied the ElecFreaks exactly.

David.

Yes, it seems to be a different numeroting…
Enclose you'll find a schematic, hop that it is what you expected.

The links for J19 are the Following:

J19 (#1) -> 75HC541(3) (#3)
J19 (#2) -> 75HC541(4) (#9)
J19 (#3) -> 75HC541(4) (#8)
J19 (#4) -> 75HC541(4) (#7)
J19 (#5) -> 75HC541(3) (#4)
J19 (#6) -> 75HC541(3) (#5)
J19 (#7 - TX0) -> ?
J19 (#8 - RX0) -> 75HC541(4) (#3)

I don't think that there is a problem with XPT2046 because I've got 2 320QVT9341 from 2 différents manufacturer. So it would be very Strange if both have the same soldering problem on the XPT2046.

Seriously, there are world conventions for drawing schematics. The Elecfreaks PDF is one of the worst drawn schematics that I have ever seen. But surely you could print it on regular paper.

What country do you come from ?

Convention numbers integrated circuits from pin#1 anti-clockwise. pin#1 is always at top-left of the package looking from the top. Let's face it. SMD package pins can NOT even be seen from the underneath of the pcb.

You bought the "unknown make" Adapter. You have to do your own detective work.

From "your" drawing:

#33 (D_OUT) goes to pin#18 (Y0) of the HC541
pin#4 (A2) of the HC541 goes to D3 (OUT) on J19

The HC541 should have channel#0 (Y0) linked to (A0)

It looks as if you are an English speaker. Redraw your i.c.s bigger. And annotate the package pin numbers e.g. #2=A0, #3=A1, #4=A2, #5=A3 ... #18=Y0, #17=Y1, #16=Y2, #15=Y3, ...

I would be very surprised if a Chinaman would ever make such a catastrophic mistake with pcb layout.
I suggest that you should make sure that you have traced your pins correctly.

David.

If the OP has the white Elecfreaks shield, it should work with the pin numbers shown in the original post. While I agree with David that the Elecfreaks schematic is difficult to read, as far as I investigated, it is correct for the white version 2.2 board. Been there, done that, have the same boards and they do work with the libraries as-is.

If you do not have the while Elecfreaks shield, please post a photo of what you purchased.

It is a knock-off of the Elecfreaks shield that the OP has bought.

Since you own an Elecfreaks v2.2 pcb, can you confirm that the components and connections match the v2.0 schematic ?

Can I conclude that v2.2 is just a copper layout upgrade? i.e. no electrical changes.

I have always assumed that ElecFreaks Adapters work 100%. After all, we would have heard if the Touch or SD did not work.

Mind you, Mcufriend TFT shields have sold 10000s. But we hear little about the design flaws features.

David.

Sorry about the schematics, it's look like easier for me in this way than in the ElecFreaks way. That is why I've done like this.
I'll check again tomorrow and make the #2=A0, #3=A1, #4=A2, #5=A3 ... #18=Y0, #17=Y1, #16=Y2, #15=Y3, ... thing, because its look like I've made a mistake about the anticlock pin numbers.

About the board I have, it looks like exactly the same as the ElecFreaks V2.2 but just without the printing logo. Thats all.

Hi,

Indeed, with the good pin numerotation, is better! Thanks David
So you'll find the schematics enclosed for U4, U5 and J19.

In highlight it is verified connection wich is OK due to the ElecFreaks V2 schematic.

In a red circle, it is pins without the connection needed.

So connections that doesn't work are:

On U5 : PIN#7 = A5 ; PIN#20 = VCC
On J19: PIN#7 = D1 TX0
On U4 : PIN#1 = OE0

How can I proceed?

Thanks,

So it seems your v2.2 clone matched the ElecFreaks V2.0 schematic pretty well.

You can hand-wire 3.3V to pin#20 (VCC) of U5.
And hand-wire GND to pin#1 (/OE0) of U4.

Don't worry about F_WP (unless you intend to solder a Flash chip)
Even if you do use Flash chip, you can override /WP in software. So it does not matter how it is wired.

Anyway, it looks as if you have learned about chip numbering and schematic reading.
The PDF improves with magnification !!
Do you understand the reason for pencil ticks for each wiring route? Nowadays CAD programs check a design. In the old days layout was done with coloured tape by humans and checked by humans.

Don't ask why anyone would draw a schematic with the SMT chip pins around the wrong way.
In the days of through-hole chips, it was worth looking at the underside of a pcb.

I would triple check the connections before you get out the soldering iron. One mistake is possible. Two mistakes are unlikely. I am assuming the F_WP omission to be intentional.

David.

Thank you for your quick answer and all your advides David.

Indeed, it helps me a lot!

OK, I'll handsold theses two pins.
But I don't understand, how is it possible that the display part was working without 3V3(VCC) on U5 and without GND(OE0) on U4?

It's right that it isn't always easy to understand the electronic schematic for newbies like me, so yes I see why it's important to pencil ticks. :slight_smile:

Yes I will double check again, but anyway, even if there is already connection for the 3V3 or the GND, do I risk somethink to handsold again a 3V3 or GND?

Thanks,