Is it ok, to show my sketch here?
TFT_eSPI library knows this display-controller, so it is easy to write a small sketch. For my test I use a STM32F411CEUS "BlackPill"-board.
Inside variant_BLACKPILL_F411CE.h:
Code: Select all
PA4 CS
PA7 MOSI (on display SDA)
PA6 MISO
PA5 CLK (on display SCL)
If you use TFT_eSPI library, settings are not made inside your sketch. You have to look for a file User_setup.h inside library folder. At first view content of this file looks confusing and like a bunch of comments, because library can work with SPI and 8bit parallel and different microcontrollers. So you have to comment out, what you don't need and remove comment characters for what you need.
For my Blackpill-board this is a reduced User_Setup.h:
Code: Select all
// User defined information reported by "Read_User_Setup" test & diagnostics example
#define USER_SETUP_INFO "User_Setup"
// Define STM32 to invoke optimised processor support (only for STM32)
#define STM32
#define TFT_DC PA12 // Data Command control pin
#define TFT_RST PA8
// Only define one driver, the other ones must be commented out
#define GC9A01_DRIVER
// For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width
// and height in portrait orientation
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
// ###### EDIT THE PINs BELOW TO SUIT YOUR STM32 SPI TFT SETUP ######
// The TFT can be connected to SPI port 1 or 2
//#define TFT_SPI_PORT 1 // SPI port 1 maximum clock rate is 55MHz
//#define TFT_MOSI PA7
//#define TFT_MISO PA6
//#define TFT_SCLK PA5
//#define TFT_SPI_PORT 2 // SPI port 2 maximum clock rate is 27MHz
//#define TFT_MOSI PB15
//#define TFT_MISO PB14
//#define TFT_SCLK PB13
// Can use Ardiuno pin references, arbitrary allocation, TFT_eSPI controls chip select
//#define TFT_CS D5 // Chip select control pin to TFT CS
//#define TFT_DC D6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)
//#define TFT_RST D7 // Reset pin to TFT RST (or RESET)
// OR alternatively, we can use STM32 port reference names PXnn
//#define TFT_CS PE11 // Nucleo-F767ZI equivalent of D5
//#define TFT_DC PE9 // Nucleo-F767ZI equivalent of D6
//#define TFT_RST PF13 // Nucleo-F767ZI equivalent of D7
// Comment out the #defines below with // to stop that font being loaded
// The ESP8366 and ESP32 have plenty of memory so commenting out fonts is not
// normally necessary. If all fonts are loaded the extra FLASH space required is
// about 17Kbytes. To save FLASH space only enable the fonts you need!
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT
// For the STM32 processor define the SPI port channel used (default 1 if undefined)
//#define TFT_SPI_PORT 2 // Set to 1 for SPI port 1, or 2 for SPI port 2
// Define the SPI clock frequency, this affects the graphics rendering speed. Too
// fast and the TFT driver will not keep up and display corruption appears.
#define SPI_FREQUENCY 27000000
// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY 20000000
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY 2500000
And information about font sizes may be wrong. I use FONT4 and FONT6. Inside TFT_eSPI.h I found:
Code: Select all
#ifdef LOAD_FONT4
#include <Fonts/Font32rle.h>
#define LOAD_RLE
#endif
#ifdef LOAD_FONT6
#include <Fonts/Font64rle.h>
#ifndef LOAD_RLE
#define LOAD_RLE
#endif
#endif
Sketch is really small but uses 41708 bytes of program storage space and global variables 1696 bytes.
Code: Select all
#include <SPI.h>
#include <TFT_eSPI.h> // TFT_eSPI@2.5.43
TFT_eSPI tft = TFT_eSPI();
void setup() {
tft.init();
tft.fillScreen(TFT_WHITE);
tft.setCursor(48, 40, 6);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
tft.print("3.25");
tft.setTextFont(4);
tft.print(" km");
tft.setCursor(20, 95, 6);
tft.print("0:12:30");
tft.setTextFont(4);
tft.print(" h");
tft.setCursor(45, 150, 6);
tft.print("10.5");
tft.setTextFont(4);
tft.print(" km/h");
}
void loop() {
// put your main code here, to run repeatedly:
}
Result in the attached file.
I replaced first version with moire pattern with a better one.