Teensy 4.0 and LCD SPI TFT 240x320 ILI9341 glitches

Hello,

I bought a "TFT Display 2.4" inch LCD 240x320 SPI 3.3V 5V ILI9341 SD Slot for Arduino Pi ESP" (which I can convert into a touch controller if I know which XPT2046 chip I should buy). I don't know if they came in different sizes or if they are all the same. Sorry, but I'm a newbie).

I followed the wiring connections here PJRC Store

I tried the ILI9341_t3 library example called graphicstest.ino, but when I uploaded the code, this is what I see:

What causes this issue? Should I provide a better pic of all the wiring and write down all the connections I made to the Teensy 4.0?

I also got a TFT 3.5" XPT2046 display for raspberry pi, but I don't know if there is any available library for the teensy

My first thought would be that it's not actually an ILI9341 in there. Given the incomplete use of the display, I suspect it might be an ST7789.

So the seller gave to the product the wrong description :sweat_smile:

https://www.ebay.co.uk/itm/173204192216

I used the graphicstest.ino example for the ST7789 and the screen is white.

If I use the ST7735 graphicstest, the test works. But the other examples aren't working properly, some of them won't run or would just glitching.

Alright, I tried to use the ST7789_t3 library, but for the colours I have to use the ST7735_* commands from the ST7735 library. It's a bit confusing, but at least I know that the screen works with the ST7789 library.

What I don't understand is why the colours I declared in the code are appearing inverted.

#include <ST7789_t3.h>

#include <SPI.h>




#define TFT_MISO  12

#define TFT_MOSI  11  //a12

#define TFT_SCK   13  //a13

#define TFT_DC   9 

#define TFT_CS   10  

#define TFT_RST  8




ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_RST);




void setup() {

 




  Serial.begin(9600);




  tft.init(240, 320); 




  tft.setRotation(1); 




  tft.fillScreen(ST7735_BLACK);




  tft.drawRect(0, 0, tft.width(), tft.height(), ST7735_RED);





  tft.setCursor(50, 20);

  tft.setTextColor(ST7735_WHITE);

  tft.setTextSize(2);

  tft.print("TEST 2.8 \" SCREEN");





  tft.fillCircle(tft.width()/2, tft.height()/2, 30, ST7735_YELLOW);





  tft.setCursor(60, 180);

  tft.setTextColor(ST7735_GREEN);

  tft.setTextSize(3);

  tft.print("IT WORKS!");

}




void loop() {

}

I tried to use the tft.invertDisplay(true); command in void setup, but if I use it, the Teensy keeps connecting and disconnecting, and the sketch doesn't start.

Also, I can't see the true colours:

LED and VCC are connected to the 3.3V

So apparently my problem with the examples of the libraries was that I couldn't find a way to set them up correctly with my ST7789V.

I managed to launch the graphicstest.ino from the Adafruit ST7735 and ST7789 library without any issue.

The only thing left to fix was the inverted colours issue.

The tft.invertDisplay(true); command didn't work, so I had to edit the Adafruit_ST7789.cpp file in the C:\Users\XXX\Documents\Arduino\libraries\Adafruit_ST7735_and_ST7789_Library\.

I changed the text ST77XX_INVON to ST77XX_INVOFF.

The screen now it works fine.

Thank you @van_der_decken for pointing me out to the correct model of the screen.

Is this line to be changed from the file? Adafruit-ST7735-Library/Adafruit_ST7789.cpp at master · adafruit/Adafruit-ST7735-Library · GitHub

    ST77XX_INVON  ,   ST_CMD_DELAY,  //  7: hack

Hi, that's what worked for me

Another solution, in case the INVOFF/INVON change doesn't make it work (or it changes back to the default settings in case the library gets an update) is to add this tft.invertDisplay(0); after tft.in(); in the sketch code you are using for your screen.

For example:

void setup() {

  Serial.begin(9600);
  
  tft.init(240, 320);

  tft.invertDisplay(0);

Using tft.invertDisplay(0); you bypass any library interpretation issues and turn off the hardware inversion directly on the ST7789 chip