Bodmer / TFT_eSPI

Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips
Other
3.69k stars 1.07k forks source link

STM32F405RC OR STM32F103C8 BLACK SCREEN #3381

Closed bihailantian655 closed 2 months ago

bihailantian655 commented 2 months ago
  1. PlatformIO
  2. TFT_eSPI library version
  3. Board package version (e.g. 2.0.3)
  4. Procesor, STM32F405RC
  5. TFT driver ST7735
  6. SPI

[env:coreboard_f401rc] platform = ststm32 board = coreboard_f401rc framework = arduino lib_deps = bodmer/TFT_eSPI@^2.5.43

define USER_SETUP_INFO "User_Setup"

// #define STM32 //#define STM_PORTA_DATA_BUS //#define STM_PORTB_DATA_BUS

define ST7735_DRIVER // Define additional parameters below for this display

// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue

define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red

// For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation

define TFT_WIDTH 80

define TFT_HEIGHT 160

// #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset) // #define ST7735_ROBOTLCD // For some RobotLCD Arduino shields (128x160, BGR, https://docs.arduino.cc/retired/getting-started-guides/TFT)

define ST7735_REDTAB

// #define ST7735_BLACKTAB // #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset

// #define TFT_INVERSION_ON // #define TFT_INVERSION_OFF

define TFT_MOSI PB5

define TFT_MISO PB4

define TFT_SCLK PB3

define TFT_CS PA15 // Chip select control pin to TFT CS

define TFT_DC PB6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)

define TFT_RST PD2// Reset pin to TFT RST (or RESET)

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

define SMOOTH_FONT

// #define SPI_FREQUENCY 1000000 // #define SPI_FREQUENCY 5000000

define SPI_FREQUENCY 10000000

// #define SPI_FREQUENCY 20000000

// Optional reduced SPI frequency for reading TFT

define SPI_READ_FREQUENCY 10000000

bihailantian655 commented 2 months ago

``/* Ellipse drawing example

This sketch does not use any fonts. */

include // Hardware-specific library

include

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

void setup(void) { tft.init();

tft.init();

digitalWrite(TFT_RST, LOW); digitalWrite(TFT_RST, HIGH);

tft.setRotation(1);

}

void loop() {

tft.fillScreen(TFT_BLACK);

// Draw some random filled ellipses for (int i = 0; i < 20; i++) { int rx = random(40); int ry = random(40); int x = rx + random(160 - rx - rx); int y = ry + random(128 - ry - ry); tft.fillEllipse(x, y, rx, ry, random(0xFFFF)); }

delay(2000); tft.fillScreen(TFT_BLACK);

// Draw some random outline ellipses for (int i = 0; i < 20; i++) { int rx = random(40); int ry = random(40); int x = rx + random(160 - rx - rx); int y = ry + random(128 - ry - ry); tft.drawEllipse(x, y, rx, ry, random(0xFFFF)); }

delay(2000); }

bihailantian655 commented 2 months ago

Resolving coreboard_f401rc dependencies... Platform ststm32 @ 17.4.0 (required: ststm32) ├── framework-arduinoststm32 @ 4.20701.0 (required: platformio/framework-arduinoststm32 @ ~4.20701.0) ├── framework-cmsis @ 2.50900.0 (required: platformio/framework-cmsis @ ~2.50900.0) ├── framework-cmsis-stm32f1 @ 4.3.1 (required: platformio/framework-cmsis-stm32f1 @ ~4.3.1) ├── tool-dfuutil @ 1.11.0 (required: platformio/tool-dfuutil @ ~1.11.0) ├── tool-dfuutil-arduino @ 1.11.0 (required: platformio/tool-dfuutil-arduino @ ~1.11.0) ├── tool-ldscripts-ststm32 @ 0.2.0 (required: platformio/tool-ldscripts-ststm32 @ ~0.2.0) ├── tool-openocd @ 3.1200.0 (required: platformio/tool-openocd @ ~3.1200.0) ├── tool-stm32duino @ 1.0.2 (required: platformio/tool-stm32duino @ ~1.0.1) └── toolchain-gccarmnoneeabi @ 1.120301.0 (required: platformio/toolchain-gccarmnoneeabi @ ~1.120301.0)

Libraries └── TFT_eSPI @ 2.5.43 (required: bodmer/TFT_eSPI @ ^2.5.43)

bihailantian655 commented 2 months ago

TESTED ONLY DS CS have signal 。mosi rst sck have no siginal

Adafruit_GFX AND CUBEMX IDE CAN DISPLAY .

include // Core graphics library

include // Hardware-specific library for ST7735

include // Hardware-specific library for ST7789

include

if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32

define TFT_CS 14

define TFT_RST 15

define TFT_DC 32

elif defined(ESP8266)

define TFT_CS 4

define TFT_RST 16

define TFT_DC 5

else

define TFT_MOSI PB5

define TFT_MISO PB4

define TFT_SCLK PB3

define TFT_CS PA15 // Chip select control pin to TFT CS

define TFT_DC PB6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)

define TFT_RST PD2// Reset pin to TFT RST (or RESET)

endif

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

float p = 3.1415926;

bihailantian655 commented 2 months ago

define USER_SETUP_INFO "User_Setup"

define STM32

//#define ILI9341_2_DRIVER // Alternative ILI9341 driver, see https://github.com/Bodmer/TFT_eSPI/issues/1172

define ST7735_DRIVER // Define additional parameters below for this display

//#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display

// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display // Try ONE option at a time to find the correct colour order for your display

// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue // #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red

// For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation

define TFT_WIDTH 80

// #define TFT_WIDTH 128 // #define TFT_WIDTH 172 // ST7789 172 x 320 // #define TFT_WIDTH 170 // ST7789 170 x 320 // #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320

define TFT_HEIGHT 160

// #define TFT_HEIGHT 128 // #define TFT_HEIGHT 240 // ST7789 240 x 240 // #define TFT_HEIGHT 320 // ST7789 240 x 320 // #define TFT_HEIGHT 240 // GC9A01 240 x 240

// For ST7735 ONLY, define the type of display, originally this was based on the // colour of the tab on the screen protector film but this is not always true, so try // out the different options below if the screen does not display graphics correctly, // e.g. colours wrong, mirror images, or stray pixels at the edges. // Comment out ALL BUT ONE of these options for a ST7735 display driver, save this // this User_Setup file, then rebuild and upload the sketch to the board again:

// #define ST7735_INITB // #define ST7735_GREENTAB // #define ST7735_GREENTAB2 // #define ST7735_GREENTAB3 // #define ST7735_GREENTAB128 // For 128 x 128 display

define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)

// #define ST7735_ROBOTLCD // For some RobotLCD Arduino shields (128x160, BGR, https://docs.arduino.cc/retired/getting-started-guides/TFT) // #define ST7735_REDTAB // #define ST7735_BLACKTAB // #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset

// If colours are inverted (white shows as black) then uncomment one of the next // 2 lines try both options, one of the options should correct the inversion.

// #define TFT_INVERSION_ON // #define TFT_INVERSION_OFF

define TFT_MOSI PB5

define TFT_MISO PB4

define TFT_SCLK PB3

define TFT_CS PA15 // Chip select control pin to TFT CS

define TFT_DC PB6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)

define TFT_RST PD2// Reset pin to TFT RST (or RESET)

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. // With an ILI9341 display 40MHz works OK, 80MHz sometimes fails // With a ST7735 display more than 27MHz may not work (spurious pixels and lines) // With an ILI9163 display 27 MHz works OK.

// #define SPI_FREQUENCY 1000000 // #define SPI_FREQUENCY 5000000

define SPI_FREQUENCY 20000000

// #define SPI_FREQUENCY 20000000 // #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

include // Core graphics library

include // Hardware-specific library for ST7735

include // Hardware-specific library for ST7789

include

if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32

define TFT_CS 14

define TFT_RST 15

define TFT_DC 32

elif defined(ESP8266)

define TFT_CS 4

define TFT_RST 16

define TFT_DC 5

else

define TFT_MOSI PB5

define TFT_MISO PB4

define TFT_SCLK PB3

define TFT_CS PA15 // Chip select control pin to TFT CS

define TFT_DC PB6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)

define TFT_RST PD2// Reset pin to TFT RST (or RESET)

endif

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

float p = 3.1415926;

void testlines(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, 0, tft.width()-1, y, color); delay(0); }

tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, 0, 0, y, color); delay(0); }

tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, tft.height()-1, tft.width()-1, y, color); delay(0); }

tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color); delay(0); } }

void testdrawtext(char *text, uint16_t color) { tft.setCursor(0, 0); tft.setTextColor(color); tft.setTextWrap(true); tft.print(text); }

void testfastlines(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t y=0; y < tft.height(); y+=5) { tft.drawFastHLine(0, y, tft.width(), color1); } for (int16_t x=0; x < tft.width(); x+=5) { tft.drawFastVLine(x, 0, tft.height(), color2); } }

void testdrawrects(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color); } }

void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=tft.width()-1; x > 6; x-=6) { tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1); tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2); } }

void testfillcircles(uint8_t radius, uint16_t color) { for (int16_t x=radius; x < tft.width(); x+=radius2) { for (int16_t y=radius; y < tft.height(); y+=radius2) { tft.fillCircle(x, y, radius, color); } } }

void testdrawcircles(uint8_t radius, uint16_t color) { for (int16_t x=0; x < tft.width()+radius; x+=radius2) { for (int16_t y=0; y < tft.height()+radius; y+=radius2) { tft.drawCircle(x, y, radius, color); } } }

void testtriangles() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 0xF800; int t; int w = tft.width()/2; int x = tft.height()-1; int y = 0; int z = tft.width(); for(t = 0 ; t <= 15; t++) { tft.drawTriangle(w, y, y, x, z, x, color); x-=4; y+=4; z-=4; color+=100; } }

void testroundrects() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 100; int i; int t; for(t = 0 ; t <= 4; t+=1) { int x = 0; int y = 0; int w = tft.width()-2; int h = tft.height()-2; for(i = 0 ; i <= 16; i+=1) { tft.drawRoundRect(x, y, w, h, 5, color); x+=2; y+=3; w-=4; h-=6; color+=1100; } color+=100; } }

void tftPrintTest() { tft.setTextWrap(false); tft.fillScreen(ST77XX_BLACK); tft.setCursor(0, 30); tft.setTextColor(ST77XX_RED); tft.setTextSize(1); tft.println("Hello World!"); tft.setTextColor(ST77XX_YELLOW); tft.setTextSize(2); tft.println("Hello World!"); tft.setTextColor(ST77XX_GREEN); tft.setTextSize(3); tft.println("Hello World!"); tft.setTextColor(ST77XX_BLUE); tft.setTextSize(4); tft.print(1234.567); delay(1500); tft.setCursor(0, 0); tft.fillScreen(ST77XX_BLACK); tft.setTextColor(ST77XX_WHITE); tft.setTextSize(0); tft.println("Hello World!"); tft.setTextSize(1); tft.setTextColor(ST77XX_GREEN); tft.print(p, 6); tft.println(" Want pi?"); tft.println(" "); tft.print(8675309, HEX); // print 8,675,309 out in HEX! tft.println(" Print HEX!"); tft.println(" "); tft.setTextColor(ST77XX_WHITE); tft.println("Sketch has been"); tft.println("running for: "); tft.setTextColor(ST77XX_MAGENTA); tft.print(millis() / 1000); tft.setTextColor(ST77XX_WHITE); tft.print(" seconds."); }

void mediabuttons() { // play tft.fillScreen(ST77XX_BLACK); tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); delay(500); // pause tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); delay(500); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); delay(50); // pause color tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); }

void setup(void) { Serial.begin(115200); printf("AT+BT_TRANS=1\r\n"); Serial.print(F("Hello! ST77xx TFT Test"));

// Use this initializer if using a 1.8" TFT screen: tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab

// OR use this initializer if using a 1.8" TFT screen with offset such as WaveShare: // tft.initR(INITR_GREENTAB); // Init ST7735S chip, green tab

// OR use this initializer (uncomment) if using a 1.44" TFT: //tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab

tft.initR(INITR_MINI160x80); // Init ST7735S mini display

tft.setSPISpeed(10000000);

Serial.println(F("Initialized"));

uint16_t time = millis(); tft.fillScreen(ST77XX_BLACK); time = millis() - time;

Serial.println(time, DEC); delay(500);

// large block of text tft.fillScreen(ST77XX_BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE); delay(1000);

// tft print function! tftPrintTest(); delay(4000);

// a single pixel tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN); delay(500);

// line draw test testlines(ST77XX_YELLOW); delay(500);

// optimized lines testfastlines(ST77XX_RED, ST77XX_BLUE); delay(500);

testdrawrects(ST77XX_GREEN); delay(500);

testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA); delay(500);

tft.fillScreen(ST77XX_BLACK); testfillcircles(10, ST77XX_BLUE); testdrawcircles(10, ST77XX_WHITE); delay(500);

testroundrects(); delay(500);

testtriangles(); delay(500);

mediabuttons(); delay(500);

Serial.println("done"); delay(1000); }

void loop() { tft.invertDisplay(true); Serial.println("loop"); delay(500); tft.invertDisplay(false); delay(500); }