Go Down

Topic: Problem interfacing with TFT ILI9225 Driver with Arduino Uno (Read 434 times) previous topic - next topic

iev60047

Hi all,

I want to preface that I have virtually no ability or previous experience with Arduino, but if I don't jump in now, I never will.

That being said, I recently purchased a HiLetGo TFT ILI9225 display and I have been attempting to upload any basic sketch to no avail. The past half-dozen hours I have perused countless guides/instructables that sometimes come close to solving my problem, but do not quite 'hit the head on the nail' for beginners in my opinion.

I am using the TFT_22_ILI9225 library and a Arduino UNO. I have wired up the display following the wiki I previously linked, ie (ILI9225 to UNO) CS to 10, RST to 8, RS to 9, etc. I trimmed down some code from another post that helped just providing an outline of a functioning sketch.

My code is:

Code: [Select]
#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST 8 //A4
#define TFT_RS 9 //A3
#define TFT_CS 10 //A5  // SS
#define TFT_SDI 11  //A2// MOSI
#define TFT_CLK 13 //A1  // SCK
#define TFT_LED 0 //3  A0 // 0 if wired to +5V directly

// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);
// Use software SPI (slower)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED);


// Setup
void setup()
{
    Serial.begin(9600);
    Serial.println("Hello jaflue");
    tft.begin();
    tft.setFont(Terminal6x8);
    tft.drawText(10, 10, "Hello jaflue !");
    delay(1000);
}


On the bright side, the display powers up (it's getting juice) and when I upload the sketch the display flickers rapidly several times as if it's attempting to write, but then again remains all-white.

Any advice, or requests on my end are much appreciated. In fact, any tips, guidance, wisdom or simply pointers in the right direction are welcome.

Sincerely,
Ian

david_prentice

#1
Jun 04, 2018, 04:29 pm Last Edit: Jun 04, 2018, 04:32 pm by david_prentice
The display pcb is designed to plug directly into the Analog and Power headers of your Uno.
Just line up the TFT_CS pin with Analog#5 on your Uno / Mega.

The library example should work out of the box.
Code: [Select]

#define TFT_RST A4
#define TFT_RS A3
#define TFT_CS A5  // SS
#define TFT_SDI A2 // MOSI
#define TFT_CLK A1  // SCK
#define TFT_LED A0 // 0 if wired to +5V directly


After you have tried this convenient way to plug in the board,  you can experiment with hardware SPI.
This involves individual jumper wires and selecting the HW constructor
Code: [Select]

// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);


David.

iev60047

Thank you David for your help. I got the TFT screen working with using the software SPI setup with the TFT screen pinned up directly ('the convenient way') into the Arduino UNO.

I have a question.

I tried hooking up using the HW (hardware) constructor using the analog pins. Can I use the analog pins here for the HW constructor? Because right now I am getting just a blinking screen, ie the screen is refreshing (led backlight is blinking) but nothing is showing up. I also tried hooking this up with the digital pinout with my code as follows:

Code: [Select]
#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST 4
#define TFT_RS 3
#define TFT_CS 2  // SS
#define TFT_SDI A2 // MOSI
#define TFT_CLK A1  /// SCK
#define TFT_LED 5 /// 0 if wired to +5V directly
// size of screen is 176x 220
/// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);
/// Use software SPI (slower)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED);// USE THIS IF DISPLAY IS HOOKED DIRECTLY INTO ARDUINO

int CircleRadius = 16;
const int n =1;
float x = 0;
float x1=0;
float y1 = 0;
int b = 0;
int x5;
int x4;
int x3;
int x2;
int y5;
int y4;
int y3;
int y2;

int a1 = 106; int a2 = 70; int a3; int a4; int a5; int b1 = 120; int b2 = 100; int bc3; int bd4; int be5;

// Setup
void setup()
{
    int CircleRadius = 16;
    Serial.begin(9600);
    Serial.println("Hello jaflue");
    tft.begin();
    tft.setFont(Terminal6x8);
    tft.drawText(10, 10, "Hello jaflue !", COLOR_BLUE);
    delay(1000);
    tft.clear();
}
void loop()
{
    if(b <5) {
       tft.drawRectangle(a1, b1, a2, b2, COLOR_BLUE);
   
      x1 = x1 + n;
      y1 = 2*(x1) + 1;
      Serial.begin(9600);
      Serial.println("Hello jaflue");
      //tft.clear();
      //tft.setFont(Terminal2x1);
      //tft.drawText(10, 10, "Hello jaflue !")
      //tft.setBackgroundColor(COLOR_GREEN);
      //delay(1000);
      //Serial.println("What radius do you want for the circle?"); //Prompt User for Input
      //while(Serial.available()==0) { }// Wait for User to Input Data 
      //CircleRadius=Serial.parseInt();  //Read the data the user has input
      tft.drawPixel(x1, y1, COLOR_BLUE); 
      tft.drawCircle(110, 88, CircleRadius, COLOR_GREEN);  //uint16_t 110, uint16_t 88, uint16_t 16, uint16_t blue
      x5 = x1;
      b = b +1;
      delay(1000);
    }
     else if(b>=5){
        tft.drawRectangle(a1, b1, a2, b2, COLOR_BLACK);
        a1 = a1 +1;
        b1 = b1+1;
        a2 = a2-1;
        b2 = b2-1;
        tft.drawRectangle(a1, b1, a2, b2, COLOR_BLUE);
       
        tft.drawPixel(x1, y1, COLOR_BLACK);
        x5 = x5 +1;
        y5 = 2*(x5)+1;
        x4 = x5;
        x3 = x4-1;
        x2 = x3-1;
        x1 = x2-1;
       
        y4 = 2*(x4) +1;
        y3 = 2*(x3) +1;
        y2 = 2*(x2) +1;
        y1 = 2*(x1) +1;
       
        tft.drawPixel(x5, y5, COLOR_BLUE);
        tft.drawPixel(x4, y4, COLOR_BLUE);
        tft.drawPixel(x3, y3, COLOR_BLUE);
        tft.drawPixel(x2, y2, COLOR_BLUE);
        tft.drawPixel(x1, y1, COLOR_BLUE);
       
        delay(50);
      }

    }




Is there something obvious I am missing? Do I need to use resistors at all? Right now I am simply directly connecting the ports here.

Best,
Ian



david_prentice

The hardware construct means that you must use the SCK, MOSI pins for TFT_CLK, TFT_SDI.
All the other pins can be on random GPIO.    Do not use MISO.

Yes,  it goes faster on the hardware constructor.

David.

iev60047

#4
Jun 10, 2018, 12:14 am Last Edit: Jun 10, 2018, 12:28 am by iev60047 Reason: Found more pertinent information.
I don't understand.

I first want to get comfortable with just basic functions of the TFT screen. I am not interested yet in using the SD_ CS, SD_MOSI, SD_MISO, SD_SCK, F_CS pins from the TFT screen. Correct me if I am wrong: I thought that the SD_CS through SD_SCK pinouts from the TFT screen are only necessary if one wants to use the SD card reader.


When you say that I must use the SCK and MOSI pins for the TFT_CLK, TFT_SDI what are the SCK and MOSI pins? Are these IO pins on the Arduino UNO itself?


I attached a picture of the screen I am using. I am currently only hooking up the IO pins (VCC, GND, GND, NC, NC, LED, CLK, SDI, RS, RST, CS) from the left side of the TFT screen.

And do I need to use resistors?
___________________________________________________________________________________

Edit: I just found a great pinout schematic of the Arduino UNO from Pighixxx and discovered that the digital pins 11 and 12 are the MOSI and MISO (respectively) pins of the UNO.

I will try and hook up anew.

david_prentice

No resistors.  From #2.  if you connect like this:
Code: [Select]

#define TFT_RST 4
#define TFT_RS 3
#define TFT_CS 2  // SS
#define TFT_SDI 11 // MOSI
#define TFT_CLK 13  /// SCK
#define TFT_LED 5 /// 0 if wired to +5V directly
// size of screen is 176x 220
/// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);


I believe that you have NC where I have LED.   Just ignore LED.

David.

iev60047

 :)  It kind of worked! This really made me happy. (Just to be clear, I plug this into the 3.3v power source from the arduino?)

The screen now flickers with the animation I have set up. However, the screen only shows when it refreshes. For example in the void setup() portion of my code, the screen will flicker on with the correct text, ie "Hello jaflue !" however it will immediately go dark afterwards even if I set the delay to delay(100000). I even then commented out the tft.clear() command just in case that function was causing the screen to go dim.
Code: [Select]

#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST 4
#define TFT_RS 3
#define TFT_CS 2  // SS
#define TFT_SDI 11 // MOSI
#define TFT_CLK 13  /// SCK
#define TFT_LED 5   /// 0 if wired to +3V directly
// size of screen is 176x 220
/// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);
/// Use software SPI (slower)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED);// USE THIS IF DISPLAY IS HOOKED DIRECTLY INTO ARDUINO

int CircleRadius = 16;
const int n =1;
float x = 0;
float x1=0;
float y1 = 0;
int b = 0;
int x5;
int x4;
int x3;
int x2;
int y5;
int y4;
int y3;
int y2;

int a1 = 106; int a2 = 70; int a3; int a4; int a5; int b1 = 120; int b2 = 100; int bc3; int bd4; int be5;

// Setup
void setup()
{
    int CircleRadius = 16;
    Serial.begin(9600);
    Serial.println("Hello jaflue");
    tft.begin();
    tft.setFont(Terminal6x8);
    tft.drawText(10, 10, "Hello jaflue !", COLOR_BLUE);
    delay(100000);
    //tft.clear();
}
void loop()
{
    if(b <5) {
       tft.drawRectangle(a1, b1, a2, b2, COLOR_BLUE);
   
      x1 = x1 + n;
      y1 = 2*(x1) + 1;
      Serial.begin(9600);
      Serial.println("Hello jaflue");
      //tft.clear();
      //tft.setFont(Terminal2x1);
      //tft.drawText(10, 10, "Hello jaflue !")
      //tft.setBackgroundColor(COLOR_GREEN);
      //delay(1000);
      //Serial.println("What radius do you want for the circle?"); //Prompt User for Input
      //while(Serial.available()==0) { }// Wait for User to Input Data 
      //CircleRadius=Serial.parseInt();  //Read the data the user has input
      tft.drawPixel(x1, y1, COLOR_BLUE); 
      tft.drawCircle(110, 88, CircleRadius, COLOR_GREEN);  //uint16_t 110, uint16_t 88, uint16_t 16, uint16_t blue
      x5 = x1;
      b = b +1;
      delay(1000);
    }
     else if(b>=5){
        tft.drawRectangle(a1, b1, a2, b2, COLOR_BLACK);
        a1 = a1 +1;
        b1 = b1+1;
        a2 = a2-1;
        b2 = b2-1;
        tft.drawRectangle(a1, b1, a2, b2, COLOR_BLUE);
       
        tft.drawPixel(x1, y1, COLOR_BLACK);
        x5 = x5 +1;
        y5 = 2*(x5)+1;
        x4 = x5;
        x3 = x4-1;
        x2 = x3-1;
        x1 = x2-1;
       
        y4 = 2*(x4) +1;
        y3 = 2*(x3) +1;
        y2 = 2*(x2) +1;
        y1 = 2*(x1) +1;
       
        tft.drawPixel(x5, y5, COLOR_BLUE);
        tft.drawPixel(x4, y4, COLOR_BLUE);
        tft.drawPixel(x3, y3, COLOR_BLUE);
        tft.drawPixel(x2, y2, COLOR_BLUE);
        tft.drawPixel(x1, y1, COLOR_BLUE);
       
        delay(50);
      }

    }



With everything hooked up correctly. I am not sure what the problem is.

Thank you so much David, you have been a great teacher so far.

Best,
Ian

___________________________________________________________________________________

Edit: I just got it working completely! I though you meant in your previous reply when you said
Quote
I believe that you have NC where I have LED.   Just ignore LED.
that you meant I didn't/shouldn't have to hook the LED pin from the tft screen. I eventually did connect the LED pin from the screen to digital pin 0 on the UNO, as my screen is plugged directly into the +3V power source from the UNO. Now the display is working as my code specifies! (which actually isn't that functional but I just wanted to test it out).

So for reasons of posterity and in case other people are struggling with the same thing I am struggling with I am attaching pictures of the correctly wired Arduino UNO to the tft ili9225 non-touch screen along with my code that should display "hello jaflue !" and a circle, a growing rectangle and line that moves diagonally across the screen.

Code: [Select]

#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST 4
#define TFT_RS 3
#define TFT_CS 2  // SS
#define TFT_SDI 11 // MOSI
#define TFT_CLK 13  /// SCK
#define TFT_LED 0   /// 0 if wired to +3V directly
// size of screen is 176x 220
/// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);
/// Use software SPI (slower)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED);// USE THIS IF DISPLAY IS HOOKED DIRECTLY INTO ARDUINO

int CircleRadius = 16;
const int n =1;
float x = 0;
float x1=0;
float y1 = 0;
int b = 0;
int x5;
int x4;
int x3;
int x2;
int y5;
int y4;
int y3;
int y2;

int a1 = 106; int a2 = 70; int a3; int a4; int a5; int b1 = 120; int b2 = 100; int bc3; int bd4; int be5;

// Setup
void setup()
{
    int CircleRadius = 16;
    Serial.begin(9600);
    Serial.println("Hello jaflue");
    tft.begin();
    tft.setFont(Terminal6x8);
    tft.drawText(10, 10, "Hello jaflue !", COLOR_BLUE);
    delay(1000);
    //tft.clear();
}
void loop()
{
    if(b <5) {
       tft.drawRectangle(a1, b1, a2, b2, COLOR_BLUE);
   
      x1 = x1 + n;
      y1 = 2*(x1) + 1;
      Serial.begin(9600);
      Serial.println("Hello jaflue");
      //tft.clear();
      //tft.setFont(Terminal2x1);
      //tft.drawText(10, 10, "Hello jaflue !")
      //tft.setBackgroundColor(COLOR_GREEN);
      //delay(1000);
      //Serial.println("What radius do you want for the circle?"); //Prompt User for Input
      //while(Serial.available()==0) { }// Wait for User to Input Data 
      //CircleRadius=Serial.parseInt();  //Read the data the user has input
      tft.drawPixel(x1, y1, COLOR_BLUE); 
      tft.drawCircle(110, 88, CircleRadius, COLOR_GREEN);  //uint16_t 110, uint16_t 88, uint16_t 16, uint16_t blue
      x5 = x1;
      b = b +1;
      delay(1000);
    }
     else if(b>=5){
        tft.drawRectangle(a1, b1, a2, b2, COLOR_BLACK);
        a1 = a1 +1;
        b1 = b1+1;
        a2 = a2-1;
        b2 = b2-1;
        tft.drawRectangle(a1, b1, a2, b2, COLOR_BLUE);
       
        tft.drawPixel(x1, y1, COLOR_BLACK);
        x5 = x5 +1;
        y5 = 2*(x5)+1;
        x4 = x5;
        x3 = x4-1;
        x2 = x3-1;
        x1 = x2-1;
       
        y4 = 2*(x4) +1;
        y3 = 2*(x3) +1;
        y2 = 2*(x2) +1;
        y1 = 2*(x1) +1;
       
        tft.drawPixel(x5, y5, COLOR_BLUE);
        tft.drawPixel(x4, y4, COLOR_BLUE);
        tft.drawPixel(x3, y3, COLOR_BLUE);
        tft.drawPixel(x2, y2, COLOR_BLUE);
        tft.drawPixel(x1, y1, COLOR_BLUE);
       
        delay(50);
      }

    }







iev60047

#7
Jun 10, 2018, 01:01 am Last Edit: Jun 10, 2018, 01:02 am by iev60047 Reason: Wrong picture attached.
I am attaching one more picture of my setup.

david_prentice

Your wiring looks ok to me.   Note that Chinese male-male jumpers often break.   Dupont jumpers sometimes break.

When showing a wiring photo,  rotating the Uno 90 degrees clockwise would pull the wires straight.   Easier to check wire colour and pins.    

Short jumper wires are easier to see.

Choose black for GND.   Red for 5V.   The power wires are unlikely to be wrong.

No,  do not use 3.3V.  The board is designed for 5V Uno/Mega.   It does not work with 3.3V GPIO.

David.

iev60047

#9
Jun 10, 2018, 01:17 am Last Edit: Jun 10, 2018, 01:19 am by iev60047 Reason: More pictures.
Thank David for the tips on wiring and taking pictures. I now have better pictures of this wiring.

I also switched the power from 3v to 5v.

Hope this can help other people.

Best,
Ian

Go Up