Help NANO How to Drive GC9A01 LCD Display - Page 1
Forum section: electronics / projects

author: daisizhou
author_rank: Super Contributor
timestamp: December 12, 2023, 11:54:43 am
content: I watched this video--->https://dronebotworkshop.com/gc9a01/According to the instructions on the website, I successfully connected Arduino nano and GC9A01, and successfully lit up the test circuit.When I successfully installed in the ARDUINO IDEhttps://github.com/adafruit/adafruit_gc9a01aThis driver library.Try to reproduce the adafruit as shown in the video_ When driving the example circuit of gc9a01a, but the screen cannot be lit up.I don't know why,Can anyone tell me why? thanks

author: coromonadalix
author_rank: Super Contributor
timestamp: December 12, 2023, 12:55:05 pm
content: some example here :https://reference.arduino.cc/reference/en/libraries/adafruit-gc9a01a/lots of comments in the ino code, and put the included librairies where they need to be ....unless you select the wrong arduino pcb, clock settings etc ... it should work if no errors in the pinoutsAND pls don't forget we are inenglish forumsyour language in arduino is not understood ?

author: daisizhou
author_rank: Super Contributor
timestamp: December 12, 2023, 01:10:20 pm
content: Thank you for your reply.My library installation location is correct,In the IDE software, the sample program has completed compilation and I see a prompt indicating successful upload.But I don't know why GC9A01 just doesn't display the test program,I am referring to the testing example program for gc9a01

author: darkspr1te
author_rank: Frequent Contributor
timestamp: December 12, 2023, 02:32:40 pm
content: I would check a couple of things , In your code it does not config the backlight pin but in the example online it does,Code:tft.begin();#if defined(TFT_BL)pinMode(TFT_BL, OUTPUT);digitalWrite(TFT_BL, HIGH); // Backlight on#endif // end TFT_BLAlso you "may" have to specify the SPI port , in the lib code it shows a few ways to specify the pins and SPI portCode:Adafruit_GC9A01A(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,int8_t _RST = -1, int8_t _MISO = -1);Adafruit_GC9A01A(int8_t _CS, int8_t _DC, int8_t _RST = -1);#if !defined(ESP8266)Adafruit_GC9A01A(SPIClass *spiClass, int8_t dc, int8_t cs = -1,int8_t rst = -1);#endif // end !ESP8266Adafruit_GC9A01A(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc,int8_t cs = -1, int8_t rst = -1, int8_t rd = -1);in the above code snippet the first Adatafruit_GC9A01A declare you include all the pins needed, in the second you only provide chip select, Data/Command and reset pins, third example you provide the spi port, chip select and data/command and reset pins. The last one is for models with 8/16 bit data bus so is different from SPI versions in that is has 8/16 additional wires for data and you provide the first pin of the GPIO port , eg GPIOB Pin0 and it will use pin0 up to pin 7 ,hope that helps.Also do check you are providing the correct value in the correct place as you will notice in the sample above sometimes is has (DC,CS) and other times it's (CS,DC) so try swapping those about too.darkspr1te

author: daisizhou
author_rank: Super Contributor
timestamp: December 13, 2023, 12:07:13 am
content: Thanks.I directly connected the backlight pin to VCC-3.3V.Please note that in the first test program, I successfully lit up the test circuit.So none of my pins have changed.In the video, it was mentioned that during the testing of the "graphicstest" sample program, it was necessary to change pin DC9 to pin 7. I also made the same modifications, but the result still did not light up the screen

author: coromonadalix
author_rank: Super Contributor
timestamp: December 13, 2023, 03:11:10 am
content: i would avoid the pin d13, its notorious to create some problemsbecause it as normaly a led on ittake time to check the demo files and check your pinout vs your coding, changing this and that doesn't helpbecause you have to change your code accordingly, and mistakes happenstake time and re-check

author: darkspr1te
author_rank: Frequent Contributor
timestamp: December 13, 2023, 05:38:43 am
content: Can you clarify light up the screen?If i take the wording right it's not Illuminating the display, or did you mean it's not displaying any graphics ?If you switch back to the other library provided by waveshare does it work ?There are often difference's in library's meaning that you cannot do a direct like for like copy paste when it comes to the parameters for any given call. having ported many of adafruits libs i can say this even more , while they all come from adafruit there is sometimes a disconnect or difference in the way they need to setup and called between libraries.Without having this lcd myself I can only guess here but the first few things i would do is first start with comparing the code in a general way ,so for the lcd init routine i would actualy first start at the arduino's h/w setup , in waveshare it's in the file DEV_config.cpp but i'll leave the exercise of finding that same lines in the adafruit library up to the reader.in the dev_config file you will see the GPIO setup and the SPI setup , what mode it uses etc.once you confirmed your hardware is setup correct by the software I would then move onto confirming the lcd commands for config are done too, for the waveshare it's in the file LCD_Driver , there is often similar lcd's out there that even if you send these commands wrong you will still get "something" on the screen even if it's just random, that at least means your hardware setup is correct, the software control of hardware is correct but the actual init values need tuning.So if you got absolutely nothing on the screen i would look at how the software configures the spi and gpio, if you get random display then i would look at the init routines.The adafruit library i note as usual support bitbash, default spi and specified spi (for devices where you are connected on a different spi port) so I personally would try the bitbash method to confirm the lib even works,exampleCode:/*from Header file - for referenceAdafruit_GC9A01A(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,int8_t _RST = -1, int8_t _MISO = -1);*/#define TFT_CS D10 // Chip select#define TFT_DC D7 // Data/command mode#define TFT_BL D6 // Backlight control#define TFT_MOSI D11 // SPI Out#define TFT_SCLK D13 //Clock out - note led should flash during operation here failure to do so means a issue#define TFT_MISO 0 //pin not actually used in bit bash as we dont read from the screen#define TFT_RST D8 // ResetAdafruit_GC9A01A tft(TFT_CS, TFT_DC,TFT_MOSI,TFT_SCLK,TFT_RST,TFT_MISO);the above code is all you need to change in the example , if all is good it should display your test code.if the above works then chances are you need to specify the SPI port in your setup , this is actually something i recommend as habit as some board designs may have hardware onboard connected to the spi ports (a lot of wave share boards do this) so you my wish to use a unpopulated spi port.darkspr1te

author: daisizhou
author_rank: Super Contributor
timestamp: December 13, 2023, 06:26:20 am
content: Thanks.Firstly, my physical connection has not changed (referring to the nano and GC9A01 connection lines)After I uploaded the following code, GC9A01 displayed normal, showing an analog clock pattern.Similarly, I uploaded Adaafruit_ The "graphicstest" example program for GC9A01A has no display and the screen display is black.My NANO and GC9A01 connections have always been in the same order as the image in the attachmentUnfortunately, I haven't been able to find Adaafruit yet_ GC9A01 has its GPIO and SPI settings,As described in the video, I will include the code TFT within the sample program_ Change DC 9 to DC 7, keep everything else the same as the videoCode:#include <GFX_Thaana.h>#include <TFT.h>#include <TFT_eSPI.h>#include "fonts.h"#include "time.h"#include "RTClib.h"RTC_DS3231 rtc;TFT_eSPI tft = TFT_eSPI();TFT_eSprite img = TFT_eSprite(&tft);#define color1 TFT_WHITE#define color2 0x8410#define color3 0x5ACB#define color4 0x15B3#define color5 0x00A3volatile int counter = 0;float VALUE;float lastValue=0;double rad=0.01745;float x;float y;float px;float py;float lx;float ly;int r=104;int sx=120;int sy=120;String cc={"45","40","35","30","25","20","15","10","05","0","55","50"};String days[]={"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};int start;int startP;const int pwmFreq = 5000;const int pwmResolution = 8;const int pwmLedChannelTFT = 0;int angle=0;bool onOff=0;bool debounce=0;String h,m,s,d1,d2,m1,m2;void setup() {if (! rtc.begin()) {Serial.println("Couldn't find RTC");}pinMode(2,OUTPUT);pinMode(0,INPUT_PULLUP);pinMode(35,INPUT_PULLUP);pinMode(13,INPUT_PULLUP);digitalWrite(2,0);ledcSetup(pwmLedChannelTFT, pwmFreq, pwmResolution);ledcAttachPin(5, pwmLedChannelTFT);ledcWrite(pwmLedChannelTFT, 200);tft.init();tft.setSwapBytes(true);tft.fillScreen(TFT_BLACK);img.setSwapBytes(true);img.createSprite(240, 240);img.setTextDatum(4);int b=0;int b2=0;for(int i=0;i<360;i++){x=(r*cos(rad*i))+sx;y=(r*sin(rad*i))+sy;px=((r-16)*cos(rad*i))+sx;py=((r-16)*sin(rad*i))+sy;lx=((r-26)*cos(rad*i))+sx;ly=((r-26)*sin(rad*i))+sy;if(i%30==0){start=i;b++;}if(i%6==0){startP=i;b2++;}}}int lastAngle=0;float circle=100;bool dir=0;int rAngle=359;void loop() {rAngle=rAngle-2;DateTime now = rtc.now();angle=now.second()*6;s=String(now.second());m=String(now.minute());h=String(now.hour());if(m.toInt()<10)m="0"+m;if(h.toInt()<10)h="0"+h;if(s.toInt()<10)s="0"+s;if(now.day()>10){d1=now.day()/10;d2=now.day()%10;}else{d1="0";d2=String(now.day());}if(now.month()>10){m1=now.month()/10;m2=now.month()%10;}else{m1="0";m2=String(now.month());}if(angle>=360)angle=0;if(rAngle<=0)rAngle=359;if(dir==0)circle=circle+0.5;elsecircle=circle-0.5;if(circle>140)dir=!dir;if(circle<100)dir=!dir;if(angle>-1){lastAngle=angle;VALUE=((angle-270)/3.60)*-1;if(VALUE<0)VALUE=VALUE+100;img.fillSprite(TFT_BLACK);img.fillCircle(sx,sy,124,color5);img.setTextColor(TFT_WHITE,color5);img.drawString(days[now.dayOfTheWeek()],circle,120,2);for(int i=0;i<12;i++)if(start+angle<360){img.drawString(cc,x[start+angle],y[start+angle],2);img.drawLine(px[start+angle],py[start+angle],lx[start+angle],ly[start+angle],color1);}else{img.drawString(cc,x[(start+angle)-360],y[(start+angle)-360],2);img.drawLine(px[(start+angle)-360],py[(start+angle)-360],lx[(start+angle)-360],ly[(start+angle)-360],color1);}img.setFreeFont(&DSEG7_Modern_Bold_20);img.drawString(s,sx,sy-36);img.setFreeFont(&DSEG7_Classic_Regular_28);img.drawString(h+":"+m,sx,sy+28);img.setTextFont(0);img.fillRect(70,86,12,20,color3);img.fillRect(84,86,12,20,color3);img.fillRect(150,86,12,20,color3);img.fillRect(164,86,12,20,color3);img.setTextColor(0x35D7,TFT_BLACK);img.drawString("MONTH",84,78);img.drawString("DAY",162,78);img.setTextColor(TFT_ORANGE,TFT_BLACK);img.drawString("VOLOS PROJECTS",120,174);img.drawString("***",120,104);img.setTextColor(TFT_WHITE,color3);img.drawString(m1,77,96,2);img.drawString(m2,91,96,2);img.drawString(d1,157,96,2);img.drawString(d2,171,96,2);for(int i=0;i<60;i++)if(startP+angle<360)img.fillCircle(px[startP+angle],py[startP+angle],1,color1);elseimg.fillCircle(px[(startP+angle)-360],py[(startP+angle)-360],1,color1);img.fillTriangle(sx-1,sy-70,sx-5,sy-56,sx+4,sy-56,TFT_ORANGE);img.fillCircle(px,py,6,TFT_RED);img.pushSprite(0, 0);}}

author: coromonadalix
author_rank: Super Contributor
timestamp: December 13, 2023, 11:42:03 am
content: 1st you call your librairiessecond you call your pins definitioni think you need to understand the arduino world ?and in the void setup you add you fonts graphics images etc ...your code sounds like you put everything in one place, hoping to make something working ?here's an example of the adafruit codewith edited pinout to suit your given imageNOW#define TFT_CS D10 // Chip select#define TFT_DC D7 // Data/command#define TFT_BL D8 // Backlight controlbut should be a reset functioni dont see "rst" calls ?WAS#define TFT_CS D1 // Chip select#define TFT_DC D3 // Data/command#define TFT_BL D6 // Backlight controlbut should be a reset functioni dont see "rst" calls ?see the changesmy guessing's since i dont know this lcdthe reset pin must be defined ? or notthe backlight pin must be defined ? or notstill miss the SCL and DIN assignments ?you have to comment out unneeded pinout assignment, it is clearly written in the ino codeother examples, and you took some picture from them i think ....https://eazytronic.com/gc9a01-with-arduino/https://dronebotworkshop.com/gc9a01/https://forum.arduino.cc/t/240x240-round-display-with-gc9a01-driver-undocumented-command/661217https://www.waveshare.com/wiki/1.28inch_LCD_Moduleand sadly the way i see, you have to check in the libraries for the pinouts ?? witch i don't find this practical

author: daisizhou
author_rank: Super Contributor
timestamp: December 13, 2023, 01:27:51 pm
content: OK,Please see my test videohttps://youtu.be/qNkt5T2ulJUI have never found the "Adatafruit_GC9A01A" documentation on these pins,Pin explanations, definitions, and how to connect themIn the video below, the author does not suggest reconnecting the pinsSo, I don't know how to connect them correctly in "Adatafruit_GC9A01A".

author: darkspr1te
author_rank: Frequent Contributor
timestamp: December 13, 2023, 04:17:20 pm
content: Did you try my example code above ?can you connect RST to 3.3v and try the code ? if rst is not used or pulled low or floating could cause a issue, tying it to 3.3v eliminates this issues and you can move onto other issues.To explain the pins in case you didnt know are as followsDC = Data /Command, what this does is in one state any data you send on the MOSI/SPI out pin is either data to put on screen or in a memory registry affecting behavior or a command e.g CMD = 0x2 will soft reset lcdRST = Reset, Tie to 3.3v as a test measureMOSI = Master out Slave in , this is the data output from the mcu to the screenMISO = Master In Slave Out , this is data from a device or screen, not used hereCS = Chip select, When this pin goes low the LCD knows you are talking to it, you can tie this to ground to test too in some case and the ship will always listen but can cause issues in some devices which use the change in chip select to do operations as well and not having that change will cause bad operationCLK = Clock signal, The lcd samples the MOSI pin to see if it's high or low,As far as documentation goes there is a lot out there but you need to search for it and in a lot of cases you have to learn about things like what SPI is to start to then understand how to read the .h and .cpp of the library to see how it's called in your code.if you look in the Adafruit_GC9A01A.h in the git hub you will see at line 106 it statesCode:Adafruit_GC9A01A(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,int8_t _RST = -1, int8_t _MISO = -1);it is defining the "bitbash" version of sending data to the lcd, this is often used because of no available spi port or quick testing. it means no on board mcu device to handle the lcd is setup other than the pins you pass to the code , in above example is says int8_t _CS , its integer 8 bit and the _CS is a reference used in the library but you must pass it the gpio pin number you have wired it too in this case CS is CHIP select,now pin numbers in arduino ide come in more than one name but mean the same thing, so when you for example dopinMode(2,OUTPUT);orpinMode(D0,OUTPUT);if you want a REALY in depth of what the pins mean then i do advise you read the data sheet, even if you dont understand it it yet they do in time make sense the more you read them.https://www.buydisplay.com/download/ic/GC9A01A.pdfNow i noticed from your video you have the version that is labeled different to the pictures so the pins are as followsBLK = BackLightCS = CS , Chip Select , Pin 10DC =DC , Data/Command , Pin 7RES = RST , Reset , pin 8 or Tie to 3.3vSCL = CLK , Clock , Pin 13 - led pin - should flashSDA = MOSI , Data out , pin 11Code:#define TFT_CS 10// Chip select#define TFT_DC 7 // Data/command mode#define TFT_BL D6 // Backlight control#define TFT_MOSI 11 // SPI Out AKA SDA#define TFT_SCLK 13 //Clock out AKA SCL - note led should flash during operation here failure to do so means a issue#define TFT_MISO -1 //pin not actually used in bit bash mode as we dont read from the screen#define TFT_RST 8 // AKA RES ,ResetAdafruit_GC9A01A tft(TFT_CS, TFT_DC,TFT_MOSI,TFT_SCLK,TFT_RST,TFT_MISO);darkspr1te

author: daisizhou
author_rank: Super Contributor
timestamp: December 13, 2023, 11:50:51 pm
content: Thanks.I added your suggestion in the code, and now the display screen is showing normally. Thank you