1.8'' TFT Display

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

1.8'' TFT Display

Post by Overclocked » Fri Mar 06, 2015 2:17 am

Hi Everyone, Its been a while since Ive played around and I was excited to see that the TFT library has been ported over :D, so I bought one of those cheap TFT displays off of ebay.

http://www.ebay.com/itm/1-8-128-160-SPI ... 20ecc8ee25

Ported Code
http://sfcompiler.co.uk/phpBB3/viewtopi ... &hilit=TFT

Thats the same one I got (driver is ST7735). The nomenclature is a bit confusing, since I am used to using SCLK and SDA for I2C and Not SPI. I am more used to seeing SCLK, MOSI and MISO for SPI. Any way. I'm giving the code I found a shot. According to the source, RS (Im guessing is reset) goes to pin 1, RW goes to D/C, CS to CS and SCK and SDA to their perspective pins. It seems however that according to my scope, the clock is wayyy to fast for the data. It also seems that the original author is using software I2C (SPI?). I am almost tempted to rewrite the Driver (ST7735) to use hardware SPI.

Anyway. I cant get the display to do much of nothing, other than be a bright flashlight. Here is my code. Maybe I'm missing something. Any help will be greatly appreciated :).

Code: Select all

Device = 18F2410
Clock = 8
Include "IntOSC.bas"
Include "TFT.bas"
Include "TftGraphic.bas"
Include "Arial.bas"



#option TFT_MODEL = ST7735


While true  
    Tft.SetPenColor (255,255,255)
    Tft.Cls()
    Tft.FillRect(0,0,128,160)
//  Tft.SetFont(Arial)
//Tft.SetBrushColor = BrushColor.Clear
 //  Tft.WriteAt(10,10,"Verdana")



Wend

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: 1.8'' TFT Display

Post by Coccoliso » Fri Mar 06, 2015 6:58 am

Hello,
this is what was said by the seller ..

Code: Select all

Features:
100% Brand New
 1.8" Serial Port SPI TFT LCD Display Module
 Size: 1.8 inch
 Dot Matrix: 128*160
 Size: 54mm(length)*34mm(width)
 Input Voltage: 5V/3.3V
Driver IC: HX8353 / S6D02A1 / ST7735
Pin Definition: 1-RST 2-CE 3-D/C 4-DIN 5-CLK 6-UCC 7-BL 8-GND
 It has PCB backplane with power IC, SD card socket
 It need 4 IO port at least to drive.
 The module port is compatible with 1602 LCD and Nokia 5110/3310 LCD Display port.
It has two connectors, one 8-pin and one 16-pin and is declared as SPI but there are inconsistencies on the pinout.
The chip is a S6D02A1A01, the 8-pin connector is a I2C only and is reported at this point also on the 16-pin.
16-pin connector has connections for SPI but it seems that it is only for the SD card (separate lines between TFT and SD Card):

1 - GND
2 - VCC
3 - n.c.
4 - TFT Back light
5 - n.c.
6 - RESET
7 - RS
8 - TFT_SDA
9 - TFT_SCK
10 - TFT_CS
11 - SD_CLK
12 - SD_MISO
13 - SD_MOSI
14 - SD_CS
15 - n.c.
16 - n.c.

I downloaded the datasheet for the seller and as I thought the display is an I2C
The SF library for the ST7735 is I2C with other 3 signal lines but at this point we need to see if the display is truly "compatible" with the ST7735 seen that the mounted chip is a S6D02A1A01.
Must then set fire to the fuses and connect it to try..

As you could see in the source ST7735.BAS (FW source by Simeon Kartalov :wink: http://www.firewing.info/pmwiki.php?n=F ... ser.ST7735 ) is connected with this options:

Code: Select all

 TFT_RS
 TFT_RW
 TFT_CS
 TFT_SCK
 TFT_SDA
The source is ported from a Firewing source and a comment for the TFT_RS option is incorrect since it is not the data/command selector but the reset signal.
The signal that selects data / command is in reality the TFT_RW.
So..

If 16-Pin connector is used:

Code: Select all

 TFT_RS  connected to RESET (pin 6)
 TFT_RW connected to pin RS (pin 7)
 TFT_CS connected to pin TFT_CS (pin 10)
 TFT_SCK connected to pin TFT_SCK (pin 9)
 TFT_SDA connected to pin TFT_SDA (pin 8)
If 8-Pin connector is used:

Code: Select all

 TFT_RS  connected to RESET (pin 1)
 TFT_RW connected to pin D/C (pin 3)
 TFT_CS connected to pin CE (pin 2)  
 TFT_SCK connected to pin CLK (pin 5)
 TFT_SDA connected to pin DIN (pin 4)

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Fri Mar 06, 2015 9:16 pm

Coccoliso wrote:Hello,

Code: Select all

 TFT_RS  connected to RESET (pin 1)
 TFT_RW connected to pin D/C (pin 3)
 TFT_CS connected to pin CE (pin 2)  
 TFT_SCK connected to pin CLK (pin 5)
 TFT_SDA connected to pin DIN (pin 4)
This is how I connected it :) Basically how it was shown in Source. I also verified that the 8 and 16 pin connections are connected together, atleast the ones for the screen. I have no use for the SD card.

I never noticed that archive tbh, and digging a little deeper into the files shows they've included some source for a chipkit..Interesting..except I dont know how I would go about writing my own drivers :/.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: 1.8'' TFT Display

Post by Coccoliso » Sat Mar 07, 2015 4:57 pm

In fact the chip ST7735 can be driven in parallel, with I2C or SPI. The hw module that you submitted wire the display to be used only with the I2C. The I2C interface is a bottleneck to drive a TFT.

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Sun Mar 08, 2015 1:56 pm

That is true, but I only need to display a few things. TFT seemed the way to go. I also saw that the libraries were ported over, and no ones tested them (except again, I dont know where to go from here). Wonder if I should buy a chipkit to see if the display can be driven using the source code that was included.

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: 1.8'' TFT Display

Post by bitfogav » Sun Mar 15, 2015 10:35 am

Sorry I just saw this topic, I can confirm that this SF port driver ST7735 do work with the 1.8 TFT display that you posted above..


I used the following code:

Code: Select all

#option TFT_MODEL = ST7735
Include "TFT.bas"
Include "TftGraphic.bas"
Include "Arial.bas"

   Tft.Cls  
   tft.SetOrientation(orlandscape)
   Tft.Brush.Style = 1 'BrushStyle.IsClear
   Tft.SetFont(Arial)  
   Tft.WriteAt(10,10,"Arial")  
   Tft.SetFont(ArialBold)
   Tft.WriteAt(10,35,"Arial Bold") 
   Tft.SetFont(ArialItalic)
   Tft.WriteAt(10,60,"Arial Italic") 
   Tft.SetFont(ArialBoldItalic)
   Tft.WriteAt(10,85,"Arial Bold Italic")

While True
Wend 
The following connections to the display:
Pin1. TFT_RS = RST
Pin2. TFT_CS = CS
Pin3. TFT_RW = D/C
Pin4. TFT_SDA = DIN
Pin5. TFT_SCK = CLK

Here is the code running on the display:
SFtft18.jpg
SFtft18.jpg (60.9 KiB) Viewed 14624 times

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Sun Mar 15, 2015 9:00 pm

Odd, I did exactly that this time

RST to PortA.5
CS to PortA.4
RS to PortA.3
SCLK to PortA.1
SDA to PortA.2

Back light to a resistor that goes to VCC (+5V).

But I noticed something. You have a blue background, mine is White. If im understanding the code correctly, we are setting the brush color to be clear, and thus it wont show up, right?

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: 1.8'' TFT Display

Post by bitfogav » Sun Mar 15, 2015 11:06 pm

Overclocked wrote: Back light to a resistor that goes to VCC (+5V).

But I noticed something. You have a blue background, mine is White.
Yes the back light is connected to +5v via a resistor.. My background on the display is actually black, I think my camera has caught the display out of align (which as lead to the white shade on one side).

If you just got a white screen then I guess no data is getting to the display? If I just power up my display then all I get is a white screen.

You said you are using 18F2410 and PORTA? Have you tried setting PORTA (ADC) to digital? you may want to include the following in your code

Code: Select all

    ADCON1 = $0F
    CMCON = $07
Overclocked wrote:If im understanding the code correctly, we are setting the brush color to be clear, and thus it wont show up, right?
Actually we don't need to set the brush in the code I posted, so you can just remove that line of code, we can set the brush to clear or solid, so for example

Code: Select all

Brush.Style = BrushStyle.bsClear
Rectangle(5,4, 20,20)    '*** Draws only the frame

Brush.Style = BrushStyle.bsSolid
Rectangle(5,4, 20,20)    '*** Draws filled rectangle

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Mon Mar 16, 2015 12:16 am

bitfogav wrote:
You said you are using 18F2410 and PORTA? Have you tried setting PORTA (ADC) to digital? you may want to include the following in your code

Code: Select all

    ADCON1 = $0F
    CMCON = $07
Added that code in, still nothing. But Im noticing that the clock is A lot faster than the data and needs to be slowed down quite a bit. I have verified that data is getting out and to the LCD from my scope but the clock seems out of sync with the data.

What processor did you try it on?

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: 1.8'' TFT Display

Post by bitfogav » Mon Mar 16, 2015 7:02 pm

Overclocked wrote:What processor did you try it on?
I'm using a 18F47J53, the only difference is that it is a 3.3v device, I can't see that being the issue though?. :roll:

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Mon Mar 16, 2015 11:06 pm

bitfogav wrote:
I'm using a 18F47J53, the only difference is that it is a 3.3v device, I can't see that being the issue though?. :roll:
Would you mind posting your code? Also what speed did your bus run at? Mine seems to clock in at a measly 50Khz :/ Something tells me it may be because Im using the internal oscillator (IntOsc8).

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: 1.8'' TFT Display

Post by Jerry Messina » Tue Mar 17, 2015 10:00 am

Even at 8MHz, that code should give you a 200KHz clock on the sck pin. What Config and OSCCON settings are you using?

The 2410 has a 4x PLL that you can use with the internal osc to run at 32MHz. Enable it using OSCTUNE.bits(6) = 1

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Tue Mar 17, 2015 11:26 am

Jerry Messina wrote:Even at 8MHz, that code should give you a 200KHz clock on the sck pin. What Config and OSCCON settings are you using?

The 2410 has a 4x PLL that you can use with the internal osc to run at 32MHz. Enable it using OSCTUNE.bits(6) = 1

Code: Select all

OSCCON = %11110110
Placed After my includes. Now Ive used those Osccon settings before with no trouble.

These are my includes

Code: Select all

Device = 18F2410  

Clock = 8 
#option TFT_MODEL = ST7735
Include "IntOSC.bas"

Include "TFT.bas"
Include "TftGraphic.bas"
Include "Arial.bas"
IntOsc.bas contains the following:

Code: Select all

Module IntOSC
Config osc = INTIO67

OSCCON = %11110110
//OSCTUNE.6 = 1 //PLL EN

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: 1.8'' TFT Display

Post by Jerry Messina » Tue Mar 17, 2015 1:27 pm

The PLL is available only when it's configured to use the internal oscillator block as its "primary" clock source (FOSC3:FOSC0 = 1001 or 1000).

You set the "primary" oscillator with FOSC3:FOSC0 configuration bits, so with the int osc block set in CONFIG1H, and 8MHz or 4MHz selected in OSCCON,
you need System Clock Select bits SCS1:SCS0 set to "primary" for the PLL to work.

This isn't real obvious from the datasheet.

Code: Select all

// let the compiler know we're going to be running at 32MHz
clock = 32

// select primary osc (can also use INTIO7 and you'll get CLKO function on RA6)
config OSC = INTIO67


// OSCCON setup for int osc w/pll (OSCCON = $70)
// select primary osc (needed for pll)
OSCCON.bits(0) = 0		// SCS0
OSCCON.bits(1) = 0		// SCS1
// 8MHz internal
OSCCON.bits(4) = 1		// IRCF0
OSCCON.bits(5) = 1		// IRCF1
OSCCON.bits(6) = 1		// IRCF2

// enable pll
OSCTUNE.bits(6) = 1

Overclocked
Posts: 21
Joined: Mon Oct 13, 2008 9:53 pm
Location: CT

Re: 1.8'' TFT Display

Post by Overclocked » Tue Mar 17, 2015 10:17 pm

Jerry Messina wrote:The PLL is available only when it's configured to use the internal oscillator block as its "primary"
Thanks for this code, the bus is now running at a speedy 800Khz, wooo, but still no dice. Im beginning to wonder if the display is bad. Only way to find out is to buy the Adafruit display.

EDIT: Its also possible that mine doesnt Have ST7735 Controller.

Im referencing this:
https://www.youtube.com/watch?v=iM__J9mA_Cc

The Red Display comes up if you explicitly search for "ST7735".

Is there a way to use Hardware SPI with this (without modifying code too much)?

Post Reply