ST7789 1.3" 240x240 TFT

All that relates to the H/W
Post Reply
bugs
Posts: 46
Joined: Mon Feb 08, 2021 10:10 pm
Has thanked: 7 times
Been thanked: 20 times

ST7789 1.3" 240x240 TFT

Post by bugs »

This TFT module was mentioned in the feature request forum section.
[Local Link Removed for Guests]
I bought one to play with and found it did not play nicely with Annex.
Even with an Arduino UNO it was a headache but eventually it worked and was then tried with a Nodemcu running Arduino. This proved the hardware - so back with Annex I found a VERY useful post by Liu Palm in the old forum with a program to drive an ST7735 TFT.
[External Link Removed for Guests]
I was able to modify this slightly so that it worked with the ST7789. The module I bought required a reset line and SPI mode 3 in order to work.
I then tried some Annex TFT code samples and found that everything worked ok.

So after all that waffle - the code looks like this.
The TFT.INIT is required only to prevent error messages. The working init is done by a routine at the bottom of the program.

Hope this is useful to someone.
Again many thanks to Liu Palm for the original hard work.
image.png
image.png

Code: [Local Link Removed for Guests]

'  ST7789 1.3" 240x240 TFT (with no CS)
' does not work using TFT.INIT alone

  spimode = 3  'ST7789 only works with this mode
  spispeed= 40000000

'nodemcu pins
  D0=16 : D1=5 : D2=4 : D3=0 : D4=2 : D5=14 : D6=12 : D7=13 : D8=15 : D9=3 : D10=1
 
  DC = D1 'gpio5
  CS = D8 'gpio15 - not connected to anything
  rstpin = D0  'gpio16
  
  pin.mode(rstpin), output
  pin(rstpin)=1
  
  spi.setup spispeed,spimode   ' slow to 40MHz for ST7789 or 4MHz for logic analyser
  
  pin(rstpin)=0    'initial reset
  pause 250
  pin(rstpin)=1
  
  TFT.INIT -1, DC, 1  ,240,240,0 
 'have to include the above line else get erro message "TFT not initialised line xx"
 
  ST7789_init  'this routine replaces TFT.INIT   
  
'just some tft tests  
  tft.fill TFT.RGB(5, 5, 5)
  LCD_cmd &h29          ' DISPON
  pause 100
  
  tft.fill TFT.RGB(5, 5, 5)
  TFT.BMP "/peng.bmp", 0, 0
  pause 2000
  
  tft.fill TFT.RGB(5, 5, 5)
  TFT.TEXT.COL TFT.RGB(255, 255, 255), TFT.RGB(0, 100, 0)
  TFT.TEXT.SIZE 3
  TFT.TEXT.POS 0, 130
  TFT.PRINT "Hello World";
  pause 1000
  
  TFT.LINE 239, 0, 0, 239, TFT.RGB(0, 255,255) 
  TFT.RECT 150, 20, 50, 50, TFT.RGB(255, 128, 0),1 
  TFT.CIRCLE 100, 200, 10,TFT.RGB(128, 128,255), 1
  for r = 0 to 300000 step 0.02
    d=r/6
    s=sin(r)*sin(5*r+d)*50+64
    c=cos(r)*sin(5*r+d)*50+64
    tft.circle s,c,10,rnd(65535),1
  next r  
end

'___________________________________________
  Routines for initialising ST7789
'---------------------------------------
sub LCD_cmd(x)
  pin(DC) = 0:  pin(CS) = 0
  r=spi.byte(x)
  pin(CS) = 1
end sub

'---------------------------------------
sub LCD_dat(x)
  pin(DC) = 1:  pin(CS) = 0
  r=spi.byte(x)
  pin(CS) = 1
end sub

'---------------------------------------
sub ST7789_init
  spi.setup spispeed,spimode   ' slow to 40MHz for ST7789 or 4MHz for logic analyser
  pin.mode DC,output
  pin.mode CS,output
  pin(CS) = 1
  
  pin(rstpin)=0        'Chip reset
  pause 250
  pin(rstpin)=1
  
  LCD_cmd &h01          ' SWRESET
  pause 150 
  LCD_cmd &h11          ' SLPOUT
  pause 500  
  LCD_cmd &h21          ' ST77XX_INVON
  LCD_cmd &h36          ' ST77XX_MADCTL
  LCD_dat &h00      ' was 68
  LCD_cmd &h3a          ' ST77XX_COLMOD
  LCD_dat &h55    ' 16-bit color
  LCD_cmd &h13          ' NORON
  pause 10
   ' moved to main program so don't enable display until screen has been cleared
'  LCD_cmd &h29          ' DISPON
'  pause 100
  
  'set the window 240x240
  LCD_cmd &h2a          ' ST77XX_CASET
  LCD_dat &h00
  LCD_dat &h00
  LCD_dat &h00
  LCD_dat 239
  LCD_cmd &h2b          ' ST77XX_RASET
  LCD_dat &h00
  LCD_dat &h00
  LCD_dat &h00
  LCD_dat 239
end sub  



image.png
You do not have the required permissions to view the files attached to this post.
User avatar
PANNO
Posts: 57
Joined: Thu Feb 25, 2021 4:03 am
Has thanked: 51 times
Been thanked: 9 times

Re: ST7789 1.3" 240x240 TFT

Post by PANNO »

Hi,
I have problems with the line :

TFT.INIT -1, DC, 1 ,240,240,0

Am i wrong?
cicciocb
Site Admin
Posts: 309
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 85 times
Been thanked: 197 times
Contact:

Re: ST7789 1.3" 240x240 TFT

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Thu Jul 01, 2021 1:49 pm Hi,
I have problems with the line :

TFT.INIT -1, DC, 1 ,240,240,0

Am i wrong?
1 - Are you using the ESP8266 as the code submitted by bugs is for the ESP8266?
2 - Is the variable DC defined in your code ?
PANNO2
Posts: 16
Joined: Tue Jun 08, 2021 6:26 pm
Has thanked: 7 times

Re: ST7789 1.3" 240x240 TFT

Post by PANNO2 »

Hi,
after changing the TFT with a new one it works.

thanks a lot
Post Reply