Black Pill (stm32druino) with adafruit ST7789 library

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

I am attempting to use black pill (weact v3.1, newest stm32core installed through arduino IDE, https://github.com/WeActTC/MiniSTM32F4x1) with 2 inch ST7789 IPS display (https://www.waveshare.com/2inch-lcd-module.htm) using the Adafruit_ST7789 library (https://github.com/adafruit/Adafruit-ST ... ST7789.cpp) under Adafruit_GFX. I have attached my code here. My code works fine with the arduino nano. However it does not work on black pill. Arduino IDE successfully uploaded the program to the black pill. But the display is always black (black light is on, but nothing shows). I tried to solve it on my own, like change the pin number and make sure the pin is correctly connected, look into the library but does not know what is wrong. May I know anyone know what wrong with this? Thanks a lot!

Code: Select all

#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789

#define TFT_CS    PA4//8
#define TFT_DC    PB0//9
#define TFT_RST   PB1//10
#define TFT_MOSI    PA7//11
#define TFT_SCLK    PA5//13

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

void setup(void) {
  tft.init(240, 320);           // Init ST7789 320x240
  tft.fillScreen(ST77XX_BLACK);
  tft.setRotation(1);
  tft.setTextWrap(false);
  tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
  tft.setTextSize(5);
  tft.setCursor(0, 75);
  tft.println("CODE TEST");
  tft.setCursor(0, 125);
  tft.println("HELLO");

  pinMode(PC13, OUTPUT); // LED connect to pin PC13
}

void loop() {
  digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for 100mS
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for 100mS
}
My computer development environment is: Windows 10 19042.1052, arduino IDE 1.8.13, core 2.0.0, upload method DFU, adafruit st7735 and st7789 library 1.7.3, adafruit gfx library 1.10.10
arduinoMethod.png
arduinoMethod.png (10.52 KiB) Viewed 1374 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

Thank you for the clear description of your setup.

Can you post a photo of your wiring? 800x600 works best.

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:Thank you for the clear description of your setup.

Can you post a photo of your wiring? 800x600 works best.
IMG_4941.jpg
IMG_4941.jpg (206.26 KiB) Viewed 1349 times
Here is the pin connection. I only connect display and blackpill here, please use color between them for matching, and the BL pin is floating.

I have tried all three different function calls for Adafruit_ST7789 and two different SPI (changed pin connection accordingly). All got compiled and uploaded, but still no display

Code: Select all

#define TFT_CS    PA4
#define TFT_DC    PB0
#define TFT_RST   PB1
#define TFT_MOSI    PA7//PB15
#define TFT_SCLK    PA5//PB13

//SPIClass SPI_1(PA7, PA6, PA5);
//SPIClass SPI_2(PB15, PB14, PB13);

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
//Adafruit_ST7789 tft = Adafruit_ST7789(&SPI_1, TFT_CS, TFT_DC, TFT_RST);
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

Thanks for the photo.

The purple line connecting the black pill 5v to the display Vcc is a concern. This is a 3v controller so you would need to keep all your communications as 3v. Don't power the display with a 5v line.

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:Thanks for the photo.

The purple line connecting the black pill 5v to the display Vcc is a concern. This is a 3v controller so you would need to keep all your communications as 3v. Don't power the display with a 5v line.
Thanks for reply. The purple pin is connected to 3.3v as shown in this pinout figure. The 3.3v is at outer position at the other side.
Image

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

Gotcha. Not a voltage issue then.

Can you post a photo of the soldering on the headers topside?

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:Gotcha. Not a voltage issue then.

Can you post a photo of the soldering on the headers topside?
Sure.
IMG_4966.jpg
IMG_4966.jpg (187.37 KiB) Viewed 1305 times
IMG_4965.jpg
IMG_4965.jpg (156.16 KiB) Viewed 1305 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

Looking at another BlackPill example using SP1 (default) it appears they are using PA6 for MISO and PA5 for TFT_CLOCK. Based on the pinout chart you provided this configuration makes more sense would require some rewiring on your part. Same for swapping TFT_RST and TFT_DC pins to match.

https://github.com/ag88/Adafruit_ILI9341_SPI_stm32duino

Code: Select all

 #define TFT_CS			PA4
 #define TFT_CLK		PA5
 #define TFT_MISO		PA6
 #define TFT_MOSI		PA7
 #define TFT_RST		PB0
 #define TFT_DC			PB1

 #define BACKLIGHT		PB10

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:Looking at another BlackPill example using SP1 (default) it appears they are using PA6 for MISO and PA5 for TFT_CLOCK. Based on the pinout chart you provided this configuration makes more sense would require some rewiring on your part. Same for swapping TFT_RST and TFT_DC pins to match.
The st7789 only need MOSI which is PA7 that I am using. The repo also use PA7 as MOSI. I tested swapping TFT_RST and TFT_DC (shown in the code below) and display still not work.

Code: Select all

#define TFT_CS    PA4
#define TFT_DC    PB1
#define TFT_RST   PB0
#define TFT_MOSI    PA7//PB15
#define TFT_SCLK    PA5//PB13

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

I suspect we have an issue that is just due to the speed of the Black Pill product.

Let's introduce some delays in the setup code so the display has enough time to get going before the board starts SPI communication.

Maybe a delay(500) added to setup() as a starting point.

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:Maybe a delay(500) added to setup() as a starting point.
I tried adding delay of 500, 1000, 5000 as shown in the code here. The display is still not working.

Code: Select all

void setup(void) {
//  delay(500);
//  delay(1000);
  delay(5000);
  tft.init(240, 320);           // Init ST7789 320x240
  tft.fillScreen(ST77XX_BLACK);
I also try to make sure that all the pins that I used are working by switching them to output pin, toggle them between high and low, then measure them with multimeter. I got all the pin successfully toggle between 0 and 3.3v.

Code: Select all

#define TFT_CS    PA4
#define TFT_DC    PB1
#define TFT_RST   PB0
#define TFT_MOSI    PA7//PB15
#define TFT_SCLK    PA5//PB13

void setup(void) {

  pinMode(PC13, OUTPUT); // LED connect to pin PC13
  pinMode(TFT_CS, OUTPUT);
  pinMode(TFT_DC, OUTPUT);
  pinMode(TFT_RST, OUTPUT);
  pinMode(TFT_MOSI, OUTPUT);
  pinMode(TFT_SCLK, OUTPUT);
}

void loop() {
  digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(TFT_CS, HIGH);
  digitalWrite(TFT_DC, HIGH);
  digitalWrite(TFT_RST, HIGH);
  digitalWrite(TFT_MOSI, HIGH);
  digitalWrite(TFT_SCLK, HIGH);
  delay(1000);               // wait for 100mS
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(TFT_CS, LOW);
  digitalWrite(TFT_DC, LOW);
  digitalWrite(TFT_RST, LOW);
  digitalWrite(TFT_MOSI, LOW);
  digitalWrite(TFT_SCLK, LOW);
  delay(1000);               // wait for 100mS

}

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

Thanks for confirming the IOs are good.

I think it is safe to assume after the various combinations tested thus far that the Black Pill board is working and the display is working.

I think this might be a STM32 specific issue that could be resolved by adding pull up resistors on SCK and MOSI (2.2k - 3.3k). You might also need them on the CS pins.

https://github.com/Floyd-Fish/ST7789-STM32/issues/6

Also mentioned on the above thread is slowing the SPI. I think this change would have to be made by recompiling the library with a different SPI_DEFAULT_FREQ, but hopefully this can be avoided.

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:Thanks for confirming the IOs are good.
I think it is safe to assume after the various combinations tested thus far that the Black Pill board is working and the display is working.
Display is working with my Arduino nano.
mikeysklar wrote:I think this might be a STM32 specific issue that could be resolved by adding pull up resistors on SCK and MOSI (2.2k - 3.3k). You might also need them on the CS pins.
I have add 3.3k resistor like the picture showed. The display is still not working (backlight has light up, nothing on the front display tho). Can I confirm my setup is correct?
IMG_4974.jpg
IMG_4974.jpg (263.37 KiB) Viewed 1260 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by mikeysklar »

I appreciate you trying the resistors.

Let's backup to your opening sentence about your setup. You have been using a current release of the WeAct STM32 core. Can you install the Arduino_Core_STM32 that we recommend on the product page?

https://github.com/stm32duino/Arduino_Core_STM32
https://www.adafruit.com/product/4877

User avatar
heretop
 
Posts: 11
Joined: Sun Jun 20, 2021 10:44 am

Re: Black Pill (stm32druino) with adafruit ST7789 library

Post by heretop »

mikeysklar wrote:I appreciate you trying the resistors.

Let's backup to your opening sentence about your setup. You have been using a current release of the WeAct STM32 core. Can you install the Arduino_Core_STM32 that we recommend on the product page?

https://github.com/stm32duino/Arduino_Core_STM32
https://www.adafruit.com/product/4877
I finally made it works! Thank you very much for all the help! The core that I used is indeed "https://github.com/stm32duino/Arduino_Core_STM32". I made the display working by revert the stm32duino core from 2.0.0 to 1.9.0 suggested here https://www.stm32duino.com/viewtopic.ph ... art=17#top.
Image
Thanks again for all your help!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”