480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

Display on 3.5 inch 480x320 TFT with SPI ILI9488 (SKU:MSP3520) with XIAO EP32C3 (arduino-esp32) using Arduino_GFX Library.


Install GFX Library for Arduino (Arduino_GFX) in Library Manager. Arduino_GFX is a Arduino graphics library supporting various displays with various data bus interfaces. This library start rewrite from Adafruit_GFX, LovyanGFX, TFT_eSPI, Ucglib, and more...

Connection:

    Connection between XIAO ESP32C3 and
    3.5" 480x320 TFT with SPI ILI9488 (SKU:MSP3520)

    XIAO ESP32C3
                  +-------------+
        +---------|GPIO2  5V    |
        |   +-----|GPIO3  GND   |-----------+
	| +-|-----|GPIO4  3V3   |---------+ |
	| | | +---|GPIO5  GPIO10|-------+ | |
	| | | |   |GPIO6  GPIO9 |       | | |
	| | | |	  |GPIO7  GPIO8 |-----+ | | |
        | | | |	  |GPIO21 GPIO20|     | | | |
	| | | |	  +-------------+     | | | |	  ILI9488 SPI TFT
 	| | | |			      | | | |	  +------------
	| | | |			      | | +-|-----|1 	VCC
	| | | |			      | |   +-----|2 	GND
	| | | +-----------------------|-|---------|3 	CS
	| | +-------------------------|-|---------|4 	RESET
	| +---------------------------|-|---------|5 	DC/RS
	|			      | +---------|6 	SDI(MOSI)
	|			      +-----------|7 	SCK
	+-----------------------------------------|8 	LED
                                                  |9 	SDO(MISO)-(NC)
						  |
													

 Code:

c3_ili9488_HelloWorld.ino, modified from HelloWorld example of GFX Library for Arduino
/*******************************************************************************
 * Modified from HelloWorld example of Arduino_GFX
 * run on Xiao ESP32C3 + 480x320 ILI9488 SPI TFT
 ******************************************************************************/
#include <Arduino_GFX_Library.h>

#define TFT_CS    5   //GPIO5
#define TFT_RESET 3   //GPIO3
#define TFT_DC    4   //GPIO4
#define TFT_MOSI  10  //GPIO10/MOSI
#define TFT_SCK   8   //GPIO8/SCK
#define TFT_LED   2   //GPIO2
#define TFT_MISO  -1  // not used for TFT

#define GFX_BL TFT_LED // backlight pin

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, TFT_CS);

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ILI9488_18bit(bus, TFT_RESET, 0 /* rotation */, false /* IPS */);


/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

void setup(void)
{
    gfx->begin();
    gfx->fillScreen(BLACK);

#ifdef GFX_BL
    pinMode(GFX_BL, OUTPUT);
    digitalWrite(GFX_BL, HIGH);
#endif

    gfx->setCursor(10, 10);
    gfx->setTextColor(RED);
    gfx->println("Hello World!");

    delay(5000); // 5 seconds
}

void loop()
{
    gfx->setCursor(random(gfx->width()), random(gfx->height()));
    gfx->setTextColor(random(0xffff), random(0xffff));
    gfx->setTextSize(random(6) /* x scale */, random(6) /* y scale */, random(2) /* pixel_margin */);
    gfx->println("Hello World!");

    delay(1000); // 1 second
}


c3_ili9488_test.ino, color testing.
/*******************************************************************************
 * Exercise of Arduino_GFX, color testing.
 * Run on Xiao ESP32C3 + 480x320 ILI9488 SPI TFT
 ******************************************************************************/
#include <Arduino_GFX_Library.h>

#define TFT_CS    5   //GPIO5
#define TFT_RESET 3   //GPIO3
#define TFT_DC    4   //GPIO4
#define TFT_MOSI  10  //GPIO10/MOSI
#define TFT_SCK   8   //GPIO8/SCK
#define TFT_LED   2   //GPIO2
#define TFT_MISO  -1  // not used for TFT

#define GFX_BL TFT_LED // backlight pin

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, TFT_CS);

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ILI9488_18bit(bus, TFT_RESET, 3 /* rotation */, false /* IPS */);

/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

void setup(void)
{
    gfx->begin();
    gfx->fillScreen(BLACK);

#ifdef GFX_BL
    pinMode(GFX_BL, OUTPUT);
    digitalWrite(GFX_BL, HIGH);
#endif
    gfx->setTextColor(WHITE);
    gfx->setTextSize(2, 2, 2);

    gfx->setCursor(10, 10);
    gfx->println("XIAO ESP32C3 (in Arduino framework)");

    gfx->setCursor(10, 30);
    gfx->println("+ ILI9488 SPI TFT");

    gfx->setCursor(10, 50);
    gfx->println("using Arduino_GFX Library");

    int w = gfx->width();
    int h = gfx->height();

    gfx->setCursor(10, 70);
    gfx->printf("%i x %d", w, h);
    gfx->drawRect(0, 0, w, h, WHITE);

    delay(3000);

    for(int i=0; i<w; i++){
      int d = (int)(255 * i/w);
      gfx->drawLine(i, 0, i, w, RGB565(d, 0, 0));
      delay(10);
    }
    for(int i=0; i<w; i++){
      int d = (int)(255 * i/w);
      gfx->drawLine(w-i, 0, w-i, w, RGB565(0, d, 0));
      delay(10);
    }
    for(int i=0; i<w; i++){
      int d = (int)(255 * i/w);
      gfx->drawLine(i, 0, i, w, RGB565(0, 0, d));
      delay(10);
    }
}

void loop()
{
    gfx->setTextColor(WHITE);
    gfx->setTextSize(6, 6, 2);

    gfx->fillScreen(RED);
    gfx->setCursor(100, 100);
    gfx->printf("RED");
    delay(2000);

    gfx->fillScreen(GREEN);
    gfx->setCursor(100, 100);
    gfx->printf("GREEN");
    delay(2000);

    gfx->fillScreen(BLUE);
    gfx->setCursor(100, 100);
    gfx->printf("BLUE");
    delay(2000);
}

Related:

Comments

Popular posts from this blog

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator