Advertisement
microrobotics

IPS 1.54 Inch Display SPI ST7789 Chipset

May 11th, 2023
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Below is a simple example of using an IPS 1.54 Inch Display with an SPI ST7789 Chipset. This will use the Adafruit_ST7789 library to control the display. In this example, it assumes the following connections:
  3.  
  4. SCLK => GPIO18
  5. MOSI => GPIO23
  6. CS => GPIO5
  7. DC => GPIO16
  8. RST => GPIO17
  9. BLK => GPIO19
  10. Please replace the pin definitions with your actual hardware connections. The example code will display the text "Hello, world!" in white and "from ESP32!" in red on the display.
  11. */
  12.  
  13. #include <Adafruit_GFX.h>
  14. #include <Adafruit_ST7789.h>
  15. #include <SPI.h>
  16.  
  17. #define TFT_CLK 18  // SCLK
  18. #define TFT_MOSI 23 // MOSI
  19. #define TFT_CS   5  // CS
  20. #define TFT_DC   16 // DC
  21. #define TFT_RST  17 // RST
  22. #define TFT_BLK  19 // BLK
  23.  
  24. Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST, TFT_CLK, TFT_MOSI, -1);
  25.  
  26. void setup() {
  27.   pinMode(TFT_BLK, OUTPUT);
  28.   digitalWrite(TFT_BLK, HIGH); // turn backlight on
  29.   tft.init(240, 240, SPI_MODE2); // Init ST7789 240x240
  30.   tft.setRotation(2);
  31.  
  32.   tft.fillScreen(ST77XX_BLACK);
  33.   delay(500);
  34.  
  35.   // text display tests
  36.   tft.setCursor(0, 0);
  37.   tft.setTextColor(ST77XX_WHITE);
  38.   tft.setTextSize(1);
  39.   tft.println("Hello, world!");
  40.   delay(500);
  41.  
  42.   tft.setTextColor(ST77XX_RED);
  43.   tft.setTextSize(2);
  44.   tft.println("from ESP32!");
  45. }
  46.  
  47. void loop() {
  48.   // put your main code here, to run repeatedly:
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement