# ST7735 TFT Readme [![ Image TFT ](https://github.com/gavinlyonsrepo/pic_16F18346_projects/blob/master/images/st7735/pcb.jpg)](https://github.com/gavinlyonsrepo/pic_16F18346_projects/blob/master/images/st7735/pcb.jpg) ## Table of contents * [Overview](#overview) * [Software](#software) * [User Options](#user-options) * [File system](#file-system) * [Bitmap](#bitmap) * [Color codes](#color-codes) * [Advanced screen buffer mode](#advanced-screen-buffer-mode) * [Hardware](#hardware) * [Output](#output) * [Notes](#notes) * [Error 99](#error-99) ## Overview * Name: ST7735_TFT * Description: 0. C++ Library for a TFT SPI LCD, ST7735 Driver 1. Dynamic install-able Linux based Single Board ComputersC++ library. 2. Inverse colour, rotate, sleep, idle & vertical scroll modes supported. 3. Graphics + print class included. 4. 24 bit colour , 16 bit color, bi-color Bitmaps & sprites supported. 5. Hardware and Software SPI 6. Dependency: lgpio Library 7. NB The Spidev buffer size setting must be larger than biggest buffer the code will attempt to write If not you will get 'Error 99'. See Notes section for more details. 8. Make sure SPI is enabled in your computers configuration. * Author: Gavin Lyons * Port of my PIC library at [github link.](https://github.com/gavinlyonsrepo/pic_16F18346_projects) ## Software ### User options In the example files. There are 3 sections in "Setup()" function where user can make adjustments to select for SPI type used, PCB type used and screen size. 1. USER OPTION 1 GPIO/SPI TYPE 2. USER OPTION 2 SCREEN SECTION 3. USER OPTION 3 PCB_TYPE, + SPI SETTINGS #### USER OPTION 1 SPI TYPE / GPIO This library supports both Hardware SPI and software SPI. The TFTSetupGPIO function is overloaded(2 off one for HW SPI the other for SW SPI). The parameters set for TFTSetupGPIO define which is used. HW SPI is far faster and more reliable than SW SPI #### USER OPTION 2 Screen size + Offsets User can adjust screen pixel height, screen pixel width and x & y screen offsets. These offsets can be used in the event of screen damage or manufacturing errors around edge such as cropped data or defective pixels. The function TFTInitScreenSize sets them. #### USER OPTION 3 PCB Version, SPI Settings TFTInitPCBType function is overloaded(2 off, one for HW SPI the other for SW SPI). | parameter | default value | note | SPi type | | --- | --- | --- | --- | | SWSPI_CommDelay | 0 | uS delay for GPIO to change speed | software | | HWSPI_DEVICE | 0 | A SPI device, >= 0. which SPI interface to use , ls /dev/spi* | Hardware | | HWSPI_CHANNEL | 0 | A SPI channel, >= 0. Which Chip enable pin to use usually 0 or 1 | Hardware | | HWSPI_SPEED | 1000000 | The speed of serial communication in bits per second. | Hardware | | HWSPI_FLAGS | 0 | mode 0 for this device | Hardware | | GPIO_CHIP_DEVICE | 0 | gpio chip device >= 0, check ls/dev/gpiochip* | both | | PCB_TYPE | TFT_ST7735R_Red | see table and text below | Both | PCB_TYPE: In the main.cpp in USER OPTION 3 PCB_TYPE select your display type, by passing an enum type to function TFTInitPCBType. Default is "TFT_ST7735R_Red". There are 5 types of the ST7735 TFT display supported. If your display works but RGB colors are wrong you may have chosen wrong display type. | Number | Description | Enum label | Tested | | ---- | ---- | --- | --- | | 1 | ST7735B controller | TFT_ST7735B | n/a | | 2 | ST7735R Green Tab | TFT_ST7735R_Green | n/a | | 3 | ST7735R Red Tab | TFT_ST7735R_Red | RED PCB v1.1, 1.44, 128x128 pixels | | 4 | ST7735S Black Tab | TFT_ST7735S_Black | RED PCB v1.2, 1.8, 128 x 160 pixels | | 5 | ST7735S 80x160 | TFT_ST7735S_80160 | Blue PCB .96 inch, 80x160 pixels | The ST7735S 80x160 requires an offset of (26,1) or (24,0) ### File system In example folder sub-folders: The main.cpp file contains tests showing library functions. A bitmap data file contains data for bi-color bitmaps and icons tests. The color bitmaps used in testing are in bitmap folder, 3 16-bit and 5 24-bit images. Hello world can be setup for software or hardware SPI by changing "HardwareSPI" at top of file. It also has a 'USER SCREEN TYPE SECTION' where user can switch PCB type: For types tested with library, There are other options see User options. ```c #define REDTAB_SETUP // Setup for 128x128 ST7735R Red Tab display. //#define BLACKTAB_SETUP // Setup for 120x160 ST7735S Black Tab display. //#define S5P80160_SETUP // Setup for 80x160 ST7735S BOE/HSD (buydisplay) display. ``` | # | example folder name | Description | | ------ | ------ | ------ | | 1 | hello_world | Basic use case | | 2 | test | Tests bitmap, text,graphics, function and Frame rate per second (FPS) | | 3 | advanced_screen_buffer_mode | advanced screen buffer mode test | | 4 | demos | various demos | ### Bitmap [Bitmap Documentation](../bitmap_16/README.md) ### Color codes For functions that accept a 16 bit color value. There is list of pre-defined colors in the 'colors' folder in doc. ### Advanced screen buffer mode Advanced screen buffer mode. There is advanced buffer mode where the code writes to a global screen buffer instead of the VRAM of display. It is off by default more details at readme, which is in the 'doc' folder [at link.](../buffer_mode/README.md) ## Hardware Connections as setup in main.cpp test file. | TFT PinNum | Pindesc | RPI HW SPI | RPI SW SPI | | --- | --- | --- | --- | | 1 | LED | VCC | VCC | | 2 | SCLK | SPI_CLK | GPIO6 | | 3 | SDA | SPI_MOSI | GPIO5 | | 4 | A0/DC | GPIO24 | GPIO24 | | 5 | RESET | GPI025 | GPIO25 | | 6 | SS/CS | SPI_CE0 | GPI21 | | 7 | GND | GND | GND | | 8 | VCC | VCC | VCC | 1. Connect LED backlight pin 1 thru a 150R/220R ohm resistor to 3.3/5V VCC. 2. This is a 3.3V logic device do NOT connect the I/O logic lines to 5V logic device. 3. You can connect VCC to 5V if there is a 3.3 volt regulator on back of TFT module. 4. Pick any GPIO you want for SW SPI for HW SPI: reset and DC lines are flexible. 5. User can select SPI_CE0 or SPI_CE1 for HW SPI 6. Backlight control is left to user. [![ Wiring pic ](https://github.com/gavinlyonsrepo/ST7735_TFT_RPI/blob/main/extra/images/wiring.jpg)](https://github.com/gavinlyonsrepo/ST7735_TFT_RPI/blob/main/extra/images/wiring.jpg) ## Output 1. Clock Demo showing icons, small bitmaps 2. 24-bit color bitmap test image 3. 16-bit color bitmap test image [![ Demo pic ](https://github.com/gavinlyonsrepo/ST7735_TFT_RPI/blob/main/extra/images/4.jpg)](https://github.com/gavinlyonsrepo/ST7735_TFT_RPI/blob/main/extra/images/4.jpg) [![ demo pic 2](https://github.com/gavinlyonsrepo/Display_Lib_RPI/blob/main/extra/images/st7735output.jpg)](https://github.com/gavinlyonsrepo/Display_Lib_RPI/blob/main/extra/images/st7735output.jpg) ## Notes ### Error 99 [Error 99 Documentation](../error_99/README.md)