Lidas
March 10, 2023, 11:42am
1
Good morning everyone, I ask for your help, I have a seeeduino xiao samd21 and I wanted to connect a ST7789 display and make it go with the eSPI tft library, do you think it is possible and if so how do you recommend me to do it, because I have not found any indication around
help me please, thanks
i made this sketch to try but i just get black screen
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
//#define TFT_CS 0
#define TFT_DC 4
#define TFT_RST 5
#define TFT_MOSI 10
#define TFT_SCLK 8
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void setup(void) {
Serial.begin(115200);
tft.init(240, 240, SPI_MODE3); // or tft.init(320, 240, SPI_MODE3);
tft.setRotation(2);
tft.fillScreen(ST77XX_BLACK);
delay(4000);
}
void loop() {
// put your main code here, to run repeatedly:
tft.setTextWrap(false);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(1);
tft.print("HELLO WORLD");
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.print("HELLO WORLD");
}
Try putting a delay at end of your loop() function - it is continuously looping around and you may be seeing the black fill preferentially,
Try the code below. I checked it on “ST7735”, so maybe it will not work correctly on “ST7789”.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#define TFT_CS A0
#define TFT_DC A4
#define TFT_RST A5
//#define TFT_MOSI A10
//#define TFT_SCLK A8
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup(void) {
// Serial.begin(115200);
// tft.init(240, 240, SPI_MODE3); // or tft.init(320, 240, SPI_MODE3);
tft.init(240, 240);
// tft.setRotation(2);
tft.setRotation(3);
tft.fillScreen(ST77XX_BLACK);
// delay(4000);
}
void loop() {
// tft.setTextWrap(false);
tft.setTextWrap(true);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(1);
// tft.print("HELLO WORLD");
tft.println("HELLO WORLD");
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
// tft.print("HELLO WORLD");
tft.println("HELLO WORLD");
}
Lidas
March 13, 2023, 11:03am
4
tried it doesn’t work always black screen
Here is a snippet from the Adafruit_ST7789.h
file with public functions:
/// Subclass of ST77XX type display for ST7789 TFT Driver
class Adafruit_ST7789 : public Adafruit_ST77xx {
public:
Adafruit_ST7789(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk,
int8_t rst = -1);
Adafruit_ST7789(int8_t cs, int8_t dc, int8_t rst);
#if !defined(ESP8266)
Adafruit_ST7789(SPIClass *spiClass, int8_t cs, int8_t dc, int8_t rst);
#endif // end !ESP8266
void setRotation(uint8_t m);
void init(uint16_t width, uint16_t height, uint8_t spiMode = SPI_MODE0);
Note that the first parameter is CS, not DC as in the first code segment.
So that means the original;
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
would set in the arduino module:
cs = TFT_DC ; //okay, arbitrary pin
dc = TFT_MOSI ; //not so good SPI MOSI/data (10) on XIAO not control pin
mosi = TFT_SCLK ; //again not so good. XIAO SPI SCLK (8) not data source
sclk = TFT_RST ; //again not so good, set to discrete pin no clock
rst = -1; //not passed, default okay
Hi Lidas,
Is the connection correct?
A0 ---- CS
A4 ---- DC
A5 ---- RES
A10 — SDA
A8 ---- SCL
Please try copy-paste the code below.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#define TFT_CS A0 // A0 ---- CS
#define TFT_DC A4 // A4 ---- DC
#define TFT_RST A5 // A5 ---- RES
//#define TFT_MOSI A10 // A10 --- SDA
//#define TFT_SCLK A8 // A8 ---- SCL
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup(void) {
tft.init(240, 240);
tft.setRotation(3);
tft.fillScreen(ST77XX_BLACK);
}
void loop() {
tft.setTextWrap(true);
tft.fillScreen(ST77XX_WHITE);
// 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");
delay(1000);
}