Graphics library for NodeMCU (ESP8266), ESP32 and serial+parallel TFT displays

Hi Bodmer,

It's the same that I have. I bought 2 from 2 different shops:

https://www.aliexpress.com/item/New-26-pin-3-5-inch-Raspberry-Pi-LCD-TFT-Touchscreen-Display-kit-RPI-Touch-Shield/32526486667.html

https://www.aliexpress.com/item/3-5-TFT-LCD-Touch-Screen-Module-320-x-480-SPI-RGB-Display-For-Raspberry-Pi/32661117216.html

and there are more sellers for these on AliExpress.

Avoid the 3.5" tfts marked KeDei, it uses 3 wire SPI, and no schematics can be found.

My attempts to use it with Arduino failed; I have some idea from observing on Raspi with logic analyzer, and may give it another try with my new IO class. Controller is unknown, polarity is reversed, etc.

Jean-Marc

The library has been updated to support Raspberry Pi 480 x 320 displays based on the ILI9486 TFT driver and with a 16 bit interface.

This is an example of the compatible display.

The display must be of the same interface design comprising 74HC04, 74HC4040 and 2 off 74HC4094 devices. These are commonly 3.5" TFTs compatible with the Waveshare design.

See also Jean-Marc's web links and post #93.

Since 16 bits has to be sent for every transaction there is a small overhead and thus the display draw performance is constrained.

The performance is reasonable, the TFT interface built onto the back of the TFT will only support a 20MHz rate unless modifications are made. This is a limit of the display interface design.

The UTFT Demo runs in 3s

Typical 480 x 320 results at 20MHz SPI for the GFX graphicstest sketch are:

TFT_eSPI library test!
Benchmark                Time (microseconds)
Screen fill              625771
Text                     37269
Lines                    502658
Horiz/Vert Lines         58450
Rectangles (outline)     32978
Rectangles (filled)      1511987
Circles (filled)         359877
Circles (outline)        290419
Triangles (outline)      104101
Triangles (filled)       599591
Rounded rects (outline)  132635
Rounded rects (filled)   1726473
Done!

For a 320 x 240 display the equivalent results would be:

TFT_eSPI library test!
Benchmark                Time (microseconds)
Screen fill              312986
Text                     24360
Lines                    150932
Horiz/Vert Lines         28403
Rectangles (outline)     18591
Rectangles (filled)      641954
Circles (filled)         137072
Circles (outline)        88468
Triangles (outline)      36436
Triangles (filled)       251335
Rounded rects (outline)  47381
Rounded rects (filled)   734838
Done!

The library has been updated to add support for a Raspberry Pi ILI9486 480x320 display with a modification made to the circuit that adds a directly controlled write strobe:

This allows fast writing of blocks of repeated colour pixels. The complete 480x320 screen can then be cleared in 23ms and the Run Length Encoded fonts render very fast too (1.2ms for a 72 pixel high digit). Other graphics functions that write sequences of the same colour to the screen are also speeded up significantly.

The 480x320 adapted "UTFT" graphics test sketch now runs in 1.6s and the Adafruit GFX style graphicstest runs 3x faster at 1.95s:

Benchmark                Time (microseconds)
Screen fill              115291
Text                     28714
Lines                    393270
Horiz/Vert Lines         11581
Rectangles (outline)     8164
Rectangles (filled)      279258
Circles (filled)         186516
Circles (outline)        240076
Triangles (outline)      78149
Triangles (filled)       167982
Rounded rects (outline)  94215
Rounded rects (filled)   348198
Done!
Total = 1.9496

Update: The diode must be a low capacitance type, so power diodes are not suitable for the mod circuit. A 1N4148 diode works fine and has been tested at 27MHz SPI clock rate without problems. However I have replaced it with a lower Voltage drop BAT85 schottky diode, this achieves a lower logic "0" voltage when the TFT_WR line is pulled low by the NodeMCU.

Hi Bodmer,
looks like you have another great library, I just ordered a 3.5" display to try out. The plane spotter sketch as well as the META weather one.
Thanks for all your efforts.
Regards,
Stan

Hi Stan,

The larger 480 x 320 screen is great, but it is the most expensive TFT I have in a project at $15. I have not tried to use the touch screen yet and may not bother as I find these resistance based touch screens scratch very easily.

I have combined the weather and clock sketches into one so each occupies half the screen and that works well. When you have your screen up and running then I can make a copy available if you are interested. The only issue is that the clock seconds hand freezes every 10 minutes for about 10s when the weather update information is fetched from the web, so I may remove that or blank out the second hand it during updates.

I hope to get the Plane Spotter sketch running full screen on 480x320 too but I am going to be very busy with paid work for a few weeks so that will have to wait.

A new RPi 4" "WaveShare" 480x320 screen arrived today. This is destined for a RPi project but I have connected it the the ESP8266 NodeMCU board and the TFT_eSPI library runs fine with it.

In case anyone is interested in using this larger screen then here is a link to the eBay page. Note the postal charge! There are other advertisers that sell these displays at a slightly lower cost.

As is often the case with displays from China the images in the advert do not correspond exactly with the delivered screen but it works fine, it does have the WaveShare logo and is marked "4 inch RPi LCD (A)".

Due to the very restrictive PCB track and PCB pad access it would be much trickier to add the speed enhancing mod detailed in post #99 , but the drawing performance is still very good even with no modifications.

In response to a PM, here are the connections for the RPi display with the TFT_eSPI library:

Hi Bodmer,
I just got my display today, thanks for posting the pin out as it is not marked.
Regards,
Stan

Hello Bodmer!

Thank you SO MUCH for all your work on this stuff. My project is going to ROCK because of you.

Can you or anyone tell me why I'm getting these artifacts when I try to display JPG images with your libraries?

Here's my code (based on your NodeMCU_Jpeg example sketch):

#define FS_NO_GLOBALS
#define TFT_BLACK 0
#include <FS.h>
#include <JPEGDecoder.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();

void setup()
{
  Serial.begin(9600); // Used for messages and the C array generator
  delay(10);
  Serial.println("NodeMCU decoder test!");
  tft.begin();
  tft.setRotation(0);  // 0 & 2 Portrait. 1 & 3 landscape
  tft.fillScreen(TFT_BLACK);
  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS initialisation failed!");
    while (1) yield(); // Stay here twiddling thumbs waiting
  }
  Serial.println("\r\nInitialization done.");
  listFiles(); // Lists the files so you can see what is in the SPIFFS
}

void loop()
{
  tft.setRotation(0);  // portrait
  
  // Display Gear Image
  tft.fillScreen(TFT_BLACK);
  drawJpeg("/t5_gear.jpg", 0, 0);
  delay(2000);

  //Display Water Day image
  tft.fillScreen(TFT_BLACK);
  drawJpeg("/waterday.jpg", 0, 0);
  delay(2000);
}

I have attached both of the original 240x320 JPG image files to this message...maybe there's something wrong with how they are encoded? I cannot figure this out.

Thank you so much for your help!

waterday.jpg

t5_gear.jpg

Hi tsjim,

Assuming the library example images display OK, then I suspect the encoding format is the problem.

It looks like the MCU size is 8x8 whereas the examples I have tested are 16x16.

It looks like you have used Photoshop to encode the jpeg, perhaps try a different image edit program and try that.

I do not have access to my Arduino stuff at the moment so cannot test. If there is a bug in the 8x8 decoding then I will see if I can track it down. The other possibility is that the SPI clock frequency is too high for the display. Try 27MHz if you think that may be the case.

Hi tsjim,

I checked the JPEGDecoder library with you files and get the same results on a NodeMCU and a Mega with a different graphics library so the problem must be in the JPEGDecoder library somewhere. The images are encoded as 8x8 MCU blocks and it looks like the decoder does not like this. I used IrfanView to re-saved one of the files and this turned it into a 16x16 MCU size and this renders fine. It also renders faster. See attached.

I have not managed to track down this bug so the only work-around is to use jpeg files encoded in 16x16 MCU blocks. I will post this as an issue on Github.

waterday16.jpg

Hi tsjim,

I have tracked down the bug and corrected it in the picojpeg.c code.

Download the latest JPEGDecoder library via the IDE Library manager (now at 1.7.7). It may take a day for the IDE to see the latest version. Or download a copy direct from Github.

The 8x8 MCU sized jpegs should render OK now.

Tip: The original Jpeg was 80kbytes, if you reduce the quality to make it 20kbytes then it will render faster when loading from SPIFFS.

Hi Bodmer...

That was it! It works perfectly now. Awesome.

Thank you very much!

I have added Espressif ESP32 processor support to the TFT_eSPI library.

So far this has been tested with an ILI9341 based display.

Hello Bodmer,
I got one of the raspberry pi displays working with the demo code but am having a problem getting the Plane spotter to work, have you gotten it to work on one of these displays? I is using the ILI9486 #5 driver.
Regards,
Stan

I happen to have one of those Kedei screens (two actually) so if I can be to any help that would be awesome. One works on my Pi, I want to use the other for Planespotter and Weatherstation.

I read that it uses 3 pin SPI ( Someone mentioned that here) and afaik they all have the same markings but only the signals and display controllers change with almost every iteration. I know that there are a few guys that already connected some version (V5,4,3,2,1 if I am not mistaken) of these tft's to an Arduino and found out by scope what the timings are. That's a start I guess.

Anyway, what do we not know to make it work?

3 pins SPI

Markings

On the back there are 2 connectors. One has 4 pins, 2 for 5 Vdc and 2 NC.

The other one has 8 pins:
L_CS T_CS IRQ GND
GND CLK MISO MOSI

This guy already interfaced (v5) with the ESp8266 and worked out the init for that version.

Mine is V6.3 so I think we need the Init for it (Maybe use working version on Raspberry for testing?) or I have to find out what controller is on the display and hope someone wrote the init part already. Right?

Check the link above Mac

Thanx for the link!

I decided to keep the Kedei screen for the Pi and next time stay away when I see Kedei.
It is not worth the time or the money for me to make it compatible.
I ordered one as described in this topic .

Bodmer,

I want to merge Planespotter and the Weather Station so I can switch between them.

I guess for a start is that I merge settings and libraries.
Then write some code so that both "programs" are simultaneous running (in the background I would say).
Then write some code to switch the display to show PS or WS.
Could be by using on-screen button, could be swiping.

Do you think that the esp8266 is capable of executing that or would it be too slow?

Full pinout of the Waveshare/knockof. If someone wants to make a Waveshare<>ESP pinout that would be awesome. I had to make a lot of guesses today and it's not working (Sometimes with some ocassional flickering and gibberish on the serial). So if you want a free beer (or two) please tell me how to wire this puppy up.

waveshare-pinout.png