Go Down

Topic: 2.4 inch TFT touch LCD Screen Module For Arduino UNO R3 SD low price jocks (Read 214522 times) previous topic - next topic

david_prentice

The first step is to learn how to format code neatly.   Then place it within CODE tags.   e.g.
Code: [Select]

int old;
void loop()
{
    i = i + 1;
    tft.setCursor(0, 30);
    tft.setTextSize(3);
    tft.setTextColor(WHITE);
    tft.print("IN: ");
    tft.setCursor(50, 30);
    tft.setTextColor(BLACK);
    tft.print(old);
    tft.setCursor(50, 30);
    tft.setTextColor(WHITE);
    tft.print(i);
    tft.println();
    old = i;
    delay(1000);
}


Yes,  I tried your solution.   It works fine.   But there is a neater way:
Code: [Select]

void loop()
{
    i = i + 1;
    //    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);  //foreground, background
    tft.setCursor(0, 0);
    tft.setTextSize(3);
    tft.print("IN: ");
    tft.print(i);
    tft.print("    ");   //trailing spaces
    tft.println();
    delay(1000);
}


As an exercise for the reader,   what statements could you remove from the loop() and put in the setup() ?
What happens when i goes from 32767 to -32768 ?
Why did I add the trailing spaces?
Is there a different way to overwrite old numbers?

David.

studentas

{...} As an exercise for the reader,   what statements could you remove from the loop() and put in the setup() ?
What happens when i goes from 32767 to -32768 ?
Why did I add the trailing spaces?
Is there a different way to overwrite old numbers?
David.
It is only example for dynamic info visualing problem. In real project will be loop for displaying heater temperature, calculating his power and coefficient of efficiency.

ha2709

Just for the sake of trying to help and knowing what headache i had trying to figure this out, here's some icecream for you:

Download the latest ADAfruit libraries and add them to where your userlibrary is located (mine is at: C:\Users\QUAD ONE\Documents\Arduino\libraries).

Load up the GraphicsTest.ino that comes with this library

In the GraphicsTest.ino, change the line:
Code: [Select]

uint16_t identifier = tft.readID();

to
Code: [Select]

uint16_t identifier = 0x9341;

This way you "hardcode" what driver should be used as it can't resolve this on it's own

If this doesn't work you can try to substitute with the other possibie types:

0x9325;
0x9328;
0x9341;
0x8357;
0x7575;

Good luck (again)

 

I succesful at uint16_t identifier = 0x9341;
Many thanks

Muurman

Why is that reset nedeed ? Can I not Just leave it disconnected and configure it on A6?

And is the read nessesary? 

david_prentice

Post a link to the actual display that you have.

Yes,  all the MCUFRIEND shields need the Reset pin.
If you know which controller you have,  it might be possible to make a hardware modification.

If you know which controller you have,  you do not need to read the ID.

Note that Ebay vendors often lie about controllers.

David.

Muurman

i have a couple :
http://www.ebay.de/itm/111768965859

http://www.ebay.de/itm/172239752361

http://www.ebay.de/itm/111875574700 ( 3.5 inch )

1 of the 2.4 is working with the id : 37697 the other with id : 37672

I already tried and read can i set to for example A6

So i can free the read pin.

But why is the reset used?

david_prentice

I struggled with a calculator to discover that you were talking about 0x9341 and 0x9328.
i.e. ILI9341 and ILI9328.

Both controllers are supported by MCUFRIEND_kbv library.

You can make a hardware mod for the ILI9341 to work without a Hardware Reset pin.
This will not work with a ILI9328.

David.

RajoAlfa

Hi, my LCD 2.4' from eBay (mcufriend, dont know what chip it uses) does not work with MCUFRIEND_kbv library, but works with spfd5408 library from adafruit. reversed axis fixed by changing code to this:
 
Code: [Select]

// Calibrate values
#define TS_MAXX 125
#define TS_MINY 85
#define TS_MINX 965
#define TS_MAXY 905

(switching MAXY with MINY).

But i have hard time understanding the touchscreen reading method (spfd5408 library).
Can someone explain?

Code: [Select]

void loop()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    /*
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\tPressure = "); Serial.println(p.z);
    */
   
    if (p.y < (TS_MINY-5)) {
      Serial.println("erase");
      // press the bottom of the screen to erase
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
    }
    // scale from 0->1023 to tft.width

    // *** SPFD5408 change -- Begin
    // Bug in in original code
    //p.x = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    // *** SPFD5408 change -- End
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());;

    /*
    Serial.print("("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
    */
    if (p.y < BOXSIZE) {
       oldcolor = currentcolor;

       if (p.x < BOXSIZE) {
         currentcolor = RED;
         tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*2) {
         currentcolor = YELLOW;
         tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*3) {
         currentcolor = GREEN;
         tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*4) {
         currentcolor = CYAN;
         tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*5) {
         currentcolor = BLUE;
         tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*6) {
         currentcolor = MAGENTA;
         tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
       }

       if (oldcolor != currentcolor) {
          if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
          if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
          if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
          if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
          if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
          if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
       }
    }
    if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
      tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
    }
  }
}
TSPoint waitOneTouch() {

  // wait 1 touch to exit function
 
  TSPoint p;
 
  do {
    p= ts.getPoint();
 
    pinMode(XM, OUTPUT); //Pins configures again for TFT control
    pinMode(YP, OUTPUT);
 
  } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE));
 
  return p;
}




david_prentice

Quote
Hi, my LCD 2.4' from eBay (mcufriend, dont know what chip it uses) does not work with MCUFRIEND_kbv library, but works with spfd5408 library from adafruit. reversed axis fixed by changing code to this:
Go on.   What does LCD_ID_readreg sketch say?
As far as I know,   Adafruit has never produced an spfd5408 library.
Google finds a library from Joao Lopes.   But it never even looks for an ID of 0x5408 (SPFD5408)

I have never seen a SPFD5408.   Until very recently,   I had never found a a user with a genuine SPFD5408.

I suggest that you identify the actual controller that you have got.

Then I will explain how the TouchScreen library works with Mcufriend Shields.

David.

RajoAlfa

Yes thats the one.
Title says : "Adafruit Libraries changed to works in TFT 2.4 shields with the SPFD5408 ....."
Link ->  https://github.com/JoaoLopesF/SPFD5408
I'm really sorry if i didn't gave credit to the right guy/team, wouldn't like that if it happened to me.
Controller ->you mean arduino or lcd?
Arduino Uno and TFT LCD 2.4' , in front it says : HR4 8346S01 G4/1, at the back : 2.4'' TFT LCD Shield (35702)
http://www.mcufriend.com
cant upload pictures, i will if you tell me how.

RajoAlfa

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 00 00   ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 38 80 00   Manufacturer ID
reg(0x0009) 00 00 61 00 00   Status Register
reg(0x000A) 08 08   Get Powsr Mode
reg(0x000C) 06 06   Get Pixel Format
reg(0x0061) 00 00   RDID1 HX8347-G
reg(0x0062) 00 00   RDID2 HX8347-G
reg(0x0063) 00 00   RDID3 HX8347-G
reg(0x0064) 00 00   RDID1 HX8347-A
reg(0x0065) 00 00   RDID2 HX8347-A
reg(0x0066) 00 00   RDID3 HX8347-A
reg(0x0067) 00 00   RDID Himax HX8347-A
reg(0x0070) 00 A6   Panel Himax HX8347-A
reg(0x00A1) 00 00 00 00 00   RD_DDB SSD1963
reg(0x00B0) 00 00   RGB Interface Signal Control
reg(0x00B4) 00 02   Inversion Control
reg(0x00B6) 00 24 02 00 00   Display Control
reg(0x00B7) 00 00   Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00   ILI9481, HX8357-B
reg(0x00C0) 0A 0A 0A 0A 0A 0A 0A 0A 0A   Panel Control
reg(0x00C8) 40 40 40 40 40 40 40 40 40 40 40 40 40   GAMMA
reg(0x00CC) 00 00   Panel Control
reg(0x00D0) 00 00 00   Power Control
reg(0x00D2) 00 00 00 00 00   NVM Read
reg(0x00D3) 00 01 16 02   ILI9341, ILI9488
reg(0x00DA) 38 38   RDID1
reg(0x00DB) 80 80   RDID2
reg(0x00DC) 00 00   RDID3
reg(0x00E0) 00 22 23 25 08 10 14 40 7B 50 0B 1B 22 20 2F 37   GAMMA-P
reg(0x00E1) 00 0C 14 23 0E 14 15 36 59 46 0B 1F 27 1F 20 22   GAMMA-N
reg(0x00EF) 00 00 00 00 00 00   ILI9327
reg(0x00F2) 00 24 04 04 1E 00 00 00 00 00 00 00   Adjust Control 2
reg(0x00F6) 00 00 00 00   Interface Control


From LCD_ID_readreg sketch

david_prentice

This is a new (unknown) controller that has appeared on the market.
Code: [Select]

reg(0x0004) 00 38 80 00   Manufacturer ID
reg(0x00D3) 00 01 16 02   ILI9341, ILI9488

It seems to have an ID = 0x1602 or possibly 0x3880
You can try the test_3880 branch on GitHub.  (it will report an ID = 0x3880)

Apparently the display is jittery.  I have promised to post a test sketch but it is difficult when I do not have a datasheet.    Please ask the Ebay Vendor for the make or model,  and let me know.

David.

RajoAlfa

This purchase of mine was 1 year back.
I have messeged him before because of the wrong label -> in ad was written " 3.5' display with some other picture ". No response.
( http://www.ebay.co.uk/usr/moncss?_trksid=p2057872.m2749.l2754 )
(256 negative responses. )
He also apparently disappeared from market. xD 
So i work with what i have.
I have it working nice, i can put anything to display, etc.
But i don't quite understand the touchscreen code. It looks to me like an incomplete library since many #define in the simple "paint" and no simple read_touch, give x and y value, use them. It need to open close digital pins, map the readings, and i can't use normal example: ... if(x<100 && x>200){... function?

david_prentice

Have you tried the library examples?

Note that you always have to call pinMode() for YP, XM after every TouchScreen method because these pins are shared by the TFT.

David.

RajoAlfa

Yes, it's white screen on every example.
I kinda understand the code, here is all you need for touch input to work:
Code: [Select]

 while(true){
      digitalWrite(13, HIGH);
      TSPoint p = ts.getPoint();
      digitalWrite(13, LOW);
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {   //here you can adjust the sensitivity of the touch!
         p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
         p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
         if(p.x< 239){                       //it covers from 0 to 239 pixel in x axis (screen is 240x320)
           if(p.y<107 && p.y>1){         //if you touch first 1/3 of the screen...
             //do stuff..
           }
           if(p.y<214 && p.y>107){      //if you touch second 1/3 of the screen...
             //do stuff..
           }
           if(p.y<319 && p.y>215){        //if you touch third 1/3 of the screen...
             //do stuff..
           }
          }
        }
      }

 only i would put this
Code: [Select]

pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
into void setup(){...} maybe

Go Up