- Name: ST7735_TFT_PICO
- Description:
- Library for a TFT SPI LCD, ST7735 Driver
- Raspberry pi PICO RP2040 library.
- Inverse colour, rotate, sleep, idle & vertical scroll modes supported.
- 12 fonts included
- Graphics + print class included.
- bi-color, 16 bit and 24 colour Bitmaps supported.
- Hardware and software SPI
- Author: Gavin Lyons
- Port of my Raspberry PI library version 1.5 at github link.
- Developed on Toolchain:
- Raspberry pi PICO RP2040
- SDK(1.4.0) C++
- compiler G++ for arm-none-eabi((15:10.3-2021.07-4)
- CMAKE(VERSION 3.12) , VScode(1.84.2)
- Linux Mint 21.2
There are example files included. User picks the one they want by editing the CMakeLists.txt :: add_executable(${PROJECT_NAME} section. Comment in one path and one path only.
Filename | Function | Note |
---|---|---|
ST7735_TFT_HELLO | Hello world | --- |
ST7735_TFT_TESTS | Text + fonts | --- |
ST7735_TFT_GRAPHICS | Graphics | --- |
ST7735_TFT_FUNCTIONS_FPS | Functions(like rotate scroll) + FPS test 702 | --- |
ST7735_TFT_BMP_DATA | bi colour, 24 & 16 bitmaps tests + FPS test 701 | Bitmap data is stored in arrays on PICO |
The API (application programming interface) documentation is at link hosted on github pages and generated by Doxygen.
In the main.cpp example files. There are four sections in "Setup()" function where user can make adjustments to select for SPI type used, PCB type used and screen size.
- USER OPTION 0 SPI_SPEED + TYPE
- USER OPTION 1 GPIO
- USER OPTION 2 SCREEN SECTION
- USER OPTION 3 PCB_TYPE
USER OPTION 0 SPI SPEED
Here the user can pass the SPI Bus freq in kiloHertz, Currently set to 8 Mhz. Max SPI speed on the PICO is 62.5Mhz. There is a file with SPI test results for the FPS tests in extra/doc folder. "nd parameter is the SPI interface(spi0 spi1 etc).
If users wants software SPI just call this method with just one argument for the optional GPIO software uS delay, which by default is zero. Setting this higher can be used to slow down Software SPI which may be beneficial in some setups.
USER OPTION 1 GPIO
The 5 GPIO pins used, the clock and data lines must be the clock and data lines of spi interface chosen in option 0 if using hardware SPI.
USER OPTION 2 Screen size + Offsets
In the main.cpp file, in USER OPTION 2 . 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
Select your PCB controller type by passing an enum type to function TFTInitPCBType. Default is "TFT_ST7735R_Red". If you select the wrong one if may still work but with inverted colors.
Number | Description | Enum label | Tested on |
---|---|---|---|
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 , 128 x 128 pixels |
4 | ST7735S "Black Tab" | TFT_ST7735S_Black | RED PCB v1.2, 1.8 , 128 x 160 pixels |
Font data table:
num | enum name | Char size XbyY | ASCII range | Size bytes | Size Scale-able |
---|---|---|---|---|---|
1 | $_Default | 5x8 | 0-0xFF, Full Extended | 1275 | Y |
2 | $_Thick | 7x8 | 0x20-0x5A, no lowercase letters | 406 | Y |
3 | $_SevenSeg | 4x8 | 0x20-0x7A | 360 | Y |
4 | $_Wide | 8x8 | 0x20-0x5A, no lowercase letters | 464 | Y |
5 | $_Tiny | 3x8 | 0x20-0x7E | 285 | Y |
6 | $_Homespun | 7x8 | 0x20-0x7E | 658 | Y |
7 | $_Bignum | 16x32 | 0x2D-0x3A ,0-10 - . / : | 896 | N |
8 | $_Mednum | 16x16 | 0x2D-0x3A ,0-10 - . / : | 448 | N |
9 | $_ArialRound | 16x24 | 0x20-0x7E | 4608 | N |
10 | $_ArialBold | 16x16 | 0x20-0x7E | 3072 | N |
11 | $_Mia | 8x16 | 0x20-0x7E | 1520 | N |
12 | $_Dedica | 6x12 | 0x20-0x7E | 1152 | N |
- $ = TFTFont
- A print class is available to print out many data types.
- Fonts 1-6 are byte high(at text size 1) scale-able fonts, columns of padding added by SW.
- Font 7-8 are large numerical fonts and cannot be scaled(just one size).
- Fonts 9-12 Alphanumeric fonts and cannot be scaled(just one size) These fonts are optional and can be removed from program by commenting out the relevant TFT_OPTIONAL_FONT_X define in the ST7735_TFT_Font.hpp file
Font Methods:
Font num | Method | Size parameter | Notes |
---|---|---|---|
1-6 | drawChar | Y | draws single character |
1-6 | drawText | Y | draws character array |
7-12 | drawChar | N | draws single character |
7-12 | drawText | N | draws character array |
1-12 | ~ | Polymorphic print class which will print out many data types |
These functions return a number in event of an error, such as wrong font chosen , ASCII character outside chosen fonts range, character out of screen bounds and invalid character array pointer object. See API docs for details
There are 4 functions to support drawing bitmaps,
Num | Function Name | Colour support | bitmap size Max | Note |
---|---|---|---|---|
1 | TFTdrawIcon | bi-colour | (8 x (0-Max_y)) 128 bytes max | Data vertically addressed |
2 | TFTdrawBitmap | bi-colour | 2048 bytes | Data horizontally addressed |
3 | TFTdrawBitmap16Data | 16 bit color 565 | 32768 | Data from array on PICO |
4 | TFTdrawBitmap24Data | 24 bit color | 49152 | Data from array on PICO, Converted by software to 16-bit color |
- Bitmap size in kiloBytes = (screenWidth * screenHeight * bitsPerPixel)/(1024 * 8)
- Math in bitmap size column 2-5 assumes 128x128 pixel screen.
- The data array for 1 and 2 is created from image files using file data conversion tool link
- The data array for 3 and 4 is created from BMP files using file data conversion tool link
These functions will return error codes in event of an error, see API docs for details.
Connections as setup in main.cpp test file.
TFT PinNum | Pindesc | HW SPI |
---|---|---|
1 | LED | VCC |
2 | SCLK | GPIO18 |
3 | SDA | GPIO19 |
4 | A0/DC | GPIO3 |
5 | RESET | GPIO17 |
6 | SS/CS | GPIO2 |
7 | GND | GND |
8 | VCC | VCC |
- NOTE connect LED backlight pin 1 thru a 150R/220R ohm resistor to 3.3/5V VCC.
- This is a 3.3V logic device do NOT connect the I/O logic lines to 5V logic device.
- You can connect VCC to 5V if there is a 3.3 volt regulator on back of TFT module.
- SW SPI pick any GPIO you like , HW SPI SCLK and SDA will be tied to spio interface.
- Backlight on/off control is left to user.
Output of some of the test routine's. Left to right
- Bitmap (bi-color) A background and a foreground, 128 X 128 pixels.
- Different sizes of default font. Size 2 3 4 & 5 shown.
- Different Fonts at font size 2, fonts 1-6 All these fonts are scale-able
- Graphics.
- Clock Demo Test 11, showing icons, and font 7 "BigNums"
- 24 bit RGB test image displayed from a data array , 128 X 128 pixels.
- 16 bit 565 test image displayed from a data array , 128 X 128 pixels.
- Fonts 7-12