B4R Library rESP3228CYD

B4R Library rESP3228CYD

Purpose
rESP3228CYD
is an open source SPI LCD graphics library with basic functionality for the Sunton ESP32 2.8" TFT Cheap Yellow Display (CYD).

Information
  • This library is partial wrapped (functions to set text, draw basic shapes and colors) from the LovyanGFX library.
  • Additional functions defined to set text, draw special shapes, set the RGB LED and more.
  • 24-bit color codes.
  • Touch enabled.
  • Library developed in CPP and compiled using the Arduino IDE 2.3.4 (or Arduino IDE 1.8.9) and the B4Rh2xml tool.
  • Software: B4R 4.00 (64 bit), ESP32 library 3.1.1, LovyanGFX 1.2.0.
  • Hardware: Sunton ESP32 2.8" TFT model SUTESP3228 (ESP32S - 2432S028) and the TFT LCD Graphics driver ILI9341.
  • ESP32 communicates with the TFT Display and Touchscreen using SPI communication protocol.
  • Not wrapped are the classes Sprites (LGFX_Sprite), Buttons (LGFX_Button) (see To-Do).
  • This library has been developed for personal use only.
Notes
The background to develop this library, is to use a small TFT display as a Solar Info Panel (multi pages touch panel) for the production@home, but of course there are many other use cases.

Screenshots of the examples
1742040489751.png


Files
rESP3228CYD.zip archive contains the library and sample project.

Install
In the Arduino IDE install the library LovyanGFX - TFT LCD Graphics driver.
From the zip archive, copy the content of the library folder, to the B4R additional libraries folder keeping the folder structure.

Display Driver
The library includes the display driver ILI9341, which is defined in the file ESP32_2432S028.h.
Make changes as required (see source comments).

Functions
See the examples.

Examples
  • Basic - Show some of the function (see below).
  • Gauge - Simple gauge with min, max, actual value.
  • Touch - Show touch position on the screen.
  • Solar - Solar Info Panel with key measurements (WiFi, MQTT).
  • GPIO - RGB LED.
B4R Basic Example
B4X:
Sub Process_Globals
    Private VERSION As String = "rESP3228CYD Example Basic v20250314"
    Public Serial1 As Serial
    Private lcd As ESP3228CYD
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log(CRLF, CRLF, "[AppStart]", VERSION)
    'Init display without touch
    lcd.Initialize(Null)
    'Call the demo sub
    CallSubPlus("Demo", 500, 5)
End Sub

Private Sub Demo(tag As Byte)
    lcd.DisplayRotation = 1
  
    ' Set screen background color green
    lcd.BackgroundColor = lcd.COLOR_GREEN

    ' Draw version text at top middle center
    lcd.DrawText(lcd.Width / 2, 10, VERSION, lcd.TEXT_ALIGN_MIDDLE_CENTER, 1.5, lcd.COLOR_BLUE, lcd.COLOR_GREEN)

    ' Draw text bottom left using drawtext
    lcd.DrawText(10, lcd.Height - lcd.FontHeight(1) - 2, "B4X is great... enjoy", lcd.TEXT_ALIGN_MIDDLE_LEFT, 1, lcd.COLOR_BLACK, lcd.COLOR_DEFAULT)
  
    ' Draw some filled shapes  
    lcd.FillCircle(30, 30, 15, lcd.COLOR_RED)
    lcd.FillRoundRect(10, 70, 50, 20, 5, lcd.COLOR_RED)
  
    ' Set cursor at x,y position
    Dim x,y As ULong
    x = 100
    y = 100
    lcd.SetCursor(x,y)

    ' Print text in red at cursor position  
    lcd.SetTextSize(3)
    lcd.SetTextColor(lcd.ColorRGB(255,0,0))
    lcd.Print("HELLO")

    ' Print text in white at new cursor position
    lcd.SetCursor(100,200)
    lcd.SetTextSize(3)
    lcd.SetTextColor(lcd.ColorRGB(255,255,255))
    lcd.Print("World")

    ' Draw blue pixel
    lcd.DrawPixel(50, lcd.Height / 2 , lcd.COLOR_BLUE)

    ' Draw lines
    lcd.DrawLine(60, 60, 100, 100, lcd.ColorRGB(255,0,0))
    'lcd.DrawLine(10, lcd.Height - 20, lcd.Width - 20, lcd.Height - 20, lcd.COLOR_BLUE)
    lcd.DrawGradientLine(10, lcd.Height - 20, lcd.Width - 20, lcd.Height - 20, lcd.COLOR_RED, lcd.color_BLACK)
    lcd.DrawWideLine(10, lcd.Height / 2, lcd.Width / 2, lcd.Height / 2, 5, lcd.COLOR_CYAN)

    '3-point black Bezier curve
    lcd.drawBezier3(10, 200, 100, 150, 150, 200, lcd.COLOR_BLACK)
  
    'Draw circles
    lcd.DrawCircle(60, 60, 20, lcd.COLOR_BLUE)
    'lcd.FillCircle(60, 60, 20, lcd.ColorRGB(255,0,0))
    'Dim c As ULong = Bit.ParseInt("000000FF", 32)
    'lcd.FillCircle(60, 60, 20, c)
    'lcd.FillCircle(150, 150, 20, lcd.COLOR_RED)

    ' Little triangle
    lcd.fillTriangle(80, 80, 60, 80, 80, 60, lcd.COLOR_YELLOW)
  
    'Draw TextBox
    lcd.DrawTextBox((lcd.Width / 2) - (100 / 2), 30, 100, 40, "INFO", lcd.COLOR_BLACK, 2, lcd.COLOR_WHITE, lcd.COLOR_RED, 4)
    lcd.DrawTextBoxMultiLIne(200, 80, 100, 130, "Line1", "Line2", "Line3", lcd.COLOR_BLACK, 0, lcd.COLOR_LIGHTGRAY, lcd.COLOR_RED, 4)
End Sub

To-Do
  • Wrap button class (LGFX_Button) with touch enabled.
  • Wrap sprite class (LGFX_Sprite).
  • GPIO use connector to connect BMP280.
  • Special characters.
  • Example Solar Info Panel using Bluetooth library rBLEServer.
  • Test other CYD's.
Credits
  • Developer(s) of the LovyanGFX library.
License
GNU General Public License v3.0.
 

Attachments

  • rESP3228CYD-051.zip
    38.5 KB · Views: 6
Top