display_test.ino 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // OneBitDisplay ST7305 TFT Demo Sketch for ESP32-S3
  2. // Displays "Hello world!" sequentially with auto-wrap
  3. #include <SPI.h>
  4. #include <OneBitDisplay.h>
  5. ONE_BIT_DISPLAY lcd;
  6. // Define GPIO pins for ESP32-S3 and TFT connection.
  7. // IMPORTANT: Adjust these pin numbers according to your specific ESP32-S3 development board's pinout.
  8. // Example values (please verify with your board's pinout diagram):
  9. #define TFT_CS 15 // Chip Select (CS) pin
  10. #define TFT_MOSI 13 // Master Out Slave In (MOSI) pin
  11. #define TFT_SCK 14 // Serial Clock (SCK) pin
  12. #define TFT_DC 4 // Data/Command (DC) pin
  13. #define TFT_RES 5 // Reset (RES) pin
  14. #define TFT_LED -1 // Backlight LED pin, -1 if not used or controlled externally
  15. // Screen resolution
  16. #define SCREEN_WIDTH 122
  17. #define SCREEN_HEIGHT 250
  18. // SPI communication frequency (40MHz is a common starting point for TFTs on ESP32-S3)
  19. #define SPI_FREQUENCY 40000000
  20. void setup() {
  21. Serial.begin(115200);
  22. Serial.println("Initializing ST7305 TFT with OneBitDisplay on ESP32-S3...");
  23. // Set SPI pins for the display
  24. lcd.setSPIPins(TFT_CS, TFT_MOSI, TFT_SCK, TFT_DC, TFT_RES, TFT_LED);
  25. // Initialize the display (LCD_ST7305 type, SPI frequency)
  26. lcd.SPIbegin(LCD_ST7305, SPI_FREQUENCY);
  27. Serial.println("Display initialized successfully!");
  28. // Allocate a back buffer for drawing operations (recommended for larger screens/complex drawing)
  29. lcd.allocBuffer();
  30. // Set display rotation (0, 90, 180, 270 degrees)
  31. lcd.setRotation(0);
  32. // Fill screen with black background
  33. lcd.fillScreen(OBD_WHITE);
  34. // Set text color to white
  35. lcd.setTextColor(OBD_BLACK);
  36. // Set font size
  37. lcd.setFont(FONT_16x16); // Using 8x8 font for better fit on screen
  38. // Enable text wrapping
  39. lcd.setTextWrap(true);
  40. // Set initial cursor position
  41. lcd.setCursor(0, 0);
  42. // Initial display update
  43. lcd.display();
  44. }
  45. void loop() {
  46. // Display "Hello world! "
  47. lcd.print("EarlySpring! ");
  48. int succ = lcd.display(); // Update display to show the new text
  49. //Serial.println(succ);
  50. delay(1000); // Wait for 1 second
  51. }