ST7735 SPI 1.8" TFT + mbed (work in progress)

The Library and demo

Background

I bought a cheap 1.8" TFT breakout for 15USD from ebay. The breakout has a 128x160 TFT, a ST7735 graphics controller, SD card cage and 10-pin interface with SPI. This notebook entry is about finding the pinout & writing a library for mbed.

The library is working, but still has some bugs I want to get rid off before publishing. The library was written by combining info from ST7735 datasheet, Ladyada's Adafruit ST7735 lib for Arduino and Peter Drescher's SPI for QVGA TFT library for mbed http://mbed.org/users/dreschpe/notebook/qvga-tft-with-hx8347d-controller/?c=2222

Many thanks to Peter for his work on the QVGA TFT.

The breakout

/media/uploads/smultron1977/18tft.jpg /media/uploads/smultron1977/viewpicture.aspx.jpeg

http://www.ebay.com/itm/ws/eBayISAPI.dll?ViewItem&item=280751182006&ssPageName=ADME:L:OC:US:1123

Pinout

TFT -> MBED

  • P1 GND -> GND
  • P2 SD-CS -> NC
  • P3 LCD-CS -> P8
  • P4 SCLK -> P7
  • P5 MOSI -> P5
  • P6 MISO -> P6
  • P7 RS -> P11 (ST7735 needs this to toggle between data & commands)
  • P8 RESET -> P15
  • P9 BKL -> GND
  • P10 VCC -> VU

Progress 30.11. Starfield running

The library has still some bugs that need to be fixed before publishing.

Progress 29.11. Success: pixel on screen

I found the bug. The matter was a simple one: I forgot to write the high 8 bits of the pixel. This was due to me thinking that spi.format was in (16,3) mode, when it was in fact in (8,3) = only 8 bits were written = write operation in the ST7735 was never completed.

You can see my mistake below: only 8 bits after RAMWRITE (0x2C) in the end (compare with the arduino above)

/media/uploads/smultron1977/success.jpg

Progress 29.11. ... SPyIng a Pixel in the Nude

After failing to get a pixel on screen by brute force, I decided to do something more elegant. I hooked up my lovely USBeeAX logic analyzer to Arduino nano and the TFT screen and looked at exactly what the Adafruit library on the nano is doing with the SPI bus to send a pixel on screen.

So, below you can see what putting one pixel on screen (black pixel at 1,1) looks like in the nude ! Beautiful isn't it !

0x2A is a command to set column start and end adress, which for some reason is not 1 and 2 but 0x03 and 0x04 ! Useful bit of information !

0x2B is a command to set row start and end, again its 2 and 3 instead of 1 and 2... this will help me alot.

0x2C is the RAM WRITE command that sends the pixel (00 00) to the memory

In this picture you can really see for your self how SPI works:

  • SS (sometimes called CS) is pulled low to activate the SPI slave
  • SCK (the clock signal) is wriggling up and down to carry data, in this case data is read on the low-to-high edge of the pulse
  • MOSI is blinking the bits, that are the actual data

(Ignore the MISO FF's, theyre just hanging around not doing anything)

/media/uploads/smultron1977/white_pixel_at_1_1.jpg

Progress 26.11. Init functions working

I now have garbage on the screen + screen is responding to power control / display commands. But graphics functions are not working, need to crosscheck the ST7735 and HX8347, they seem to be different in this respect.


9 comments on ST7735 SPI 1.8" TFT + mbed (work in progress):

22 Nov 2011
27 Nov 2011

Hello Jonne, the maximum clock speed of the ST7735 is 15MHz for writing and 6.6Mhz for reading. You have to lower the clockspeed if you use my functions. At start of the tft_reset()function.

Start with the pixel(int x, int y, int colour) function. If you get can set a pixel with a colour you have half the way.

Peter

27 Nov 2011

Thanks for the advice. I started writing this library by looking at Adafruit's library for Arduino. I guess I'll have to look at the datasheet a bit closer as well.

29 Nov 2011

A pixel is now blinking. Now for some code cleaning and optimizing. Code coming up soon.

11 Dec 2011

The library is now published. I don't have time to figure out the problems with the read functions. So instead I'm publishing this in a not completely ready state, in case someone is interested in looking at it.

04 Dec 2012

Jonne, I'm trying to get your library up and going, and it's not working for me. The demo works perfectly, but if I import the library into a new program it fails to compile. I get the error: no instance of contructor "mbed::Stream::Stream" matches the argument list. Any ideas?

04 Dec 2012

Hi Tanner. I haven't used my mbed for a while now, so I might get this wrong. I'll dig mine out if you can't get your problem solved. But in any case: off the top of my head, Stream is a class defined in the core mbed libraries - not in my library. Try to #include the other libraries (that are included in the main.cpp of the demo) in your programs' main.cpp and see if that solves your problem.

25 Nov 2016

How do yo implement your demo animation? Well, It's great, your library really working!!, thanks!.But I have the first two lines and the first column of the screen uninitialized after running myTFT.fillrect(0,0,127,159,Black). I don't find the mistake.

Thanks,

19 Apr 2022 This post is awaiting moderation

Hello Jonne, is there a chance to switch Red and Blue Values? I used your library, but it seems that my 1,77 TFT has a problem with drawing the correct color it seems that Blue and Red are switched.

Thanks, Ben

Please log in to post comments.