Hello. For several days now I have had a problem connecting the “GC9A01” display with the “xiaio esp32c3” board.
This problem does not occur when connecting the screen to Wemos d1 mini (with TFT libraries set)
I’ve searched the entire internet and there are only a few threads about connecting and setting the TFT library for Xiaomi i
Currently I found the pin setting:
GND ---------- GND
VCC ---------- 3.3V
SCL ---------- D8
SDA ---------- D10
RES ---------- D2
DC ---------- D1
CS ---------- D0
this is how I set them in the User Setups file for the GC9A01 display. Of course, the drivers are also set to this display.
I found the pin connection on the seeeduino forum along with a demo file, which after setting the library and uploading should work, but it doesn’t work Sad
I have my own project, but I can’t move forward because nothing is displayed on the screen…
In my opinion, the fault lies with either the library or the controller itself, because the code is only loaded on a blank screen.
Is there anyone who had a similar problem and solved it?
Below I am posting the code I found along with the library settings. If anyone had this display and board and could check it and tell me what I could have done wrong, I would be very grateful.
Regards.
//XIAO_ESP32C3_GC9A01_circular_TFT_ring_meter
//
// creates a rainbow temperature scale using Bodmer’s example at TFT_eSPI
// with an index marker
// and numerical temperature display
// on a cirdular 240*240 TFT GC9A01A driver
// microcontroller Seeed studio Xiao_ESP32C3
//
// Floris Wouterlood
// April 2, 2024
//
// public domain
// pin layout:
// both displays Xiao_ESP32C3
// GND ---------- GND
// VCC ---------- 3.3V
// SCL ---------- D8
// SDA ---------- D10
// RES ---------- D2
// DC ---------- D1
// CS ---------- D0
//
#include <SPI.h>
#include <TFT_eSPI.h>
// do not forget to use User_Setup_xxxx.h that matches microcontroller-display combination
// here: Setup_FW_Xiao_ESP32C3_GC9A01_TFT_026.h - see
TFT_eSPI tft = TFT_eSPI();
// RGB 565 color picker at 16 bit color generator (RGB565 color picker) | Electrical engineering and programming notepad
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define GREY 0x2108
#define SCALE0 0xC655 // accent color for unused scale segments
#define SCALE1 0x5DEE // accent color for unused scale segments
#define TEXT_COLOR 0xFFFF
// Meter colour schemes
#define RED2RED 0
#define GREEN2GREEN 1
#define BLUE2BLUE 2
#define BLUE2RED 3
#define GREEN2RED 4
#define RED2GREEN 5
#define DEG2RAD 0.0174532925 // conversion factor degrees to radials
int xpos = 0;
int ypos = 0;
int gap = 55;
int radius = 120;
int angle;
uint32_t runTime = -99999; // time for next update
int reading; // value to be displayed
int d = 0; // variable used for the sinewave test waveform
bool range_error = 0;
float rt_x, rt_y, rl_x, rl_y, rr_x, rr_y;
float rt_x_old, rt_y_old, rl_x_old, rl_y_old, rr_x_old, rr_y_old;
float angle_top, angle_rechts, angle_links;
float center_x = 120; // center coordinates of the radius serving the index tag
float center_y = 125;
float temp_00;
void setup(void) {
tft.begin ();
Serial.begin (9600);
tft.setRotation (0);
tft.fillScreen (BLACK);
}
void loop() {
if (millis() - runTime >= 0L) { // execute every TBD ms
runTime = millis();
temp_00 = random (00,100); // for testing purposes
reading = temp_00;
indexTag ();
ringMeter (reading, 0, 100, xpos, ypos, radius,GREEN2RED); // draw analogue meter
delay (1000);
}
}
// #########################################################################
// Draw the meter on the screen, returns x coord of righthand side #
// #########################################################################
int ringMeter(int value, int vmin, int vmax, int x, int y, int r, byte scheme) {
x += r; y += r; // calculate coords of centre of ring
int w = r / 3; // width of outer ring is 1/4 of radius
angle = 150; // half the sweep angle of meter (300 degrees)
int v = map(value, vmin, vmax, -angle, angle); // map the value to an angle v
byte seg = 3; // segments are 3 degrees wide = 100 segments for 300 degrees
byte inc = 6; // draw segments every 3 degrees, increase to 6 for segmented ring
int colour = BLUE;
for (int i = -angle+inc/2; i < angle-inc/2; i += inc)
{
float sx = cos((i - 90) * DEG2RAD);
float sy = sin((i - 90) * DEG2RAD);
uint16_t x0 = sx * (r - w) + x;
uint16_t y0 = sy * (r - w) + y;
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
float sx2 = cos((i + seg - 90) * DEG2RAD); // calculate pair of coordinates for segment end
float sy2 = sin((i + seg - 90) * DEG2RAD);
int x2 = sx2 * (r - w) + x;
int y2 = sy2 * (r - w) + y;
int x3 = sx2 * r + x;
int y3 = sy2 * r + y;
if (i < v) { // fill in colored segments with 2 triangles
switch (scheme) {
case 0: colour = RED; break; // fixed color
case 1: colour = GREEN; break; // fixed color
case 2: colour = BLUE; break; // fixed color
case 3: colour = rainbow(map(i, -angle, angle, 0, 127)); break; // full spectrum blue to red
case 4: colour = rainbow(map(i, -angle, angle, 70, 127)); break; // green to red (high temperature etc)
case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break; // red to green (low battery etc)
default: colour = BLUE; break; // fixed colour
}
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
}
else // fill in blank segments
{
tft.fillTriangle(x0, y0, x1, y1, x2, y2, GREY);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, GREY);
}
}
return x + r; // calculate and return right hand side x coordinate
}
// #########################################################################
// Return a 16 bit rainbow colour
// #########################################################################
unsigned int rainbow(byte value){
byte red = 0; // value is expected to be in range 0-127 (0 = blue to 127 = red)
byte green = 0; // green is the middle 6 bits
byte blue = 0; // blue is the bottom 5 bits
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
// #########################################################################
// Return a value in range -1 to +1 for a given phase angle in degrees
// #########################################################################
float sineWave(int phase) {
return sin(phase * 0.0174532925);
}
// #########################################################################################
// # create a moving index tag indicating temperature inner to the rainbbow scale #
// #########################################################################################
void indexTag (){
tft.fillTriangle (rt_x_old, rt_y_old, rl_x_old, rl_y_old, rr_x_old, rr_y_old, BLACK);
angle_top = -(240DEG2RAD)+((3temp_00)DEG2RAD); // offset plus scale dynamics = 100 degrees temp over 300 arc degrees
angle_links = (angle_top - (6DEG2RAD));
angle_rechts = (angle_top + (6*DEG2RAD));
rt_x = (center_x + ((radius-45) * cos (angle_top)));
rt_y = (center_y + ((radius-45) * sin (angle_top)));
rl_x = (center_x + ((radius-60) * cos (angle_links)));
rl_y = (center_y + ((radius-60) * sin (angle_links)));
rr_x = (center_x + ((radius-60) * cos (angle_rechts)));
rr_y = (center_y + ((radius-60) * sin (angle_rechts)));
rt_x_old = rt_x;
rt_y_old = rt_y;
rl_x_old = rl_x;
rl_y_old = rl_y;
rr_x_old = rr_x;
rr_y_old = rr_y;
tft.fillTriangle (rt_x, rt_y, rl_x, rl_y, rr_x, rr_y, YELLOW);
}