loading
1 Comments

Tell us about yourself!

Complete Your Profile
  • How to use 2.4 inch TFT LCD SPFD5408 with Arduino Uno and Mega

    Hi All,i recently buy an LCD 2.4" , and i had some issues because i had not enougth information. My issues was to drive this part with and arduino Mega or Uno , and i had on the beginning a white screen , after some problem solved , text inverted , offsets...After reseach , the chip on the LCD screen is ST7781 and i done some modifications on the configuration of driver to make it works.To resume , in the file : ADAFRUIT_TFTLCD.cpp add these line :(based on the librairie provided by arduino 1.6.9).........#define ID_7781 0................//ADD DRIVER 7781 - configuration based on datasheet of ST7781static const uint16_t ST7781_regValues[] PROGMEM = {0x000D,0x0000,0x0001,0x0100, 0x0002,0x0700, 0x0003,0x1028, 0x0008,0x0302, 0x0009,0x0000, 0x000A,0x0008, //*******POWER C...see more »Hi All,i recently buy an LCD 2.4" , and i had some issues because i had not enougth information. My issues was to drive this part with and arduino Mega or Uno , and i had on the beginning a white screen , after some problem solved , text inverted , offsets...After reseach , the chip on the LCD screen is ST7781 and i done some modifications on the configuration of driver to make it works.To resume , in the file : ADAFRUIT_TFTLCD.cpp add these line :(based on the librairie provided by arduino 1.6.9).........#define ID_7781 0................//ADD DRIVER 7781 - configuration based on datasheet of ST7781static const uint16_t ST7781_regValues[] PROGMEM = {0x000D,0x0000,0x0001,0x0100, 0x0002,0x0700, 0x0003,0x1028, 0x0008,0x0302, 0x0009,0x0000, 0x000A,0x0008, //*******POWER CONTROL REGISTER INITIAL*******// 0x0010,0x0790, 0x0011,0x0005, 0x0012,0x0000, 0x0013,0x0000, //delayms(50, //********POWER SUPPPLY STARTUP 1 SETTING*******// 0x0010,0x12B0, // delayms(50, 0x0011,0x0700, //delayms(50, //********POWER SUPPLY STARTUP 2 SETTING******// 0x0012,0x008C, 0x0013,0x1700, 0x0029,0x0022,0x002B,0x0010, //frame control // delayms(50, //******GAMMA CLUSTER SETTING******// 0x0030,0x0000, 0x0031,0x0505, 0x0032,0x0205, 0x0035,0x0206, 0x0036,0x0408, 0x0037,0x0000, 0x0038,0x0504,0x0039,0x0206, 0x003C,0x0206, 0x003D,0x0408, // -----------DISPLAY WINDOWS 240*320-------------// 0x0050,0x00EF,0x0051,0x0000, 0x0052,0x013F, 0x0053,0x0000, //-----FRAME RATE SETTING-------// 0x0060,0x2700, 0x0061,0x0001, 0x0090,0x0055, //RTNI setting//-------DISPLAY ON------// 0x0007,0x0133, 0x0001,0x0100, };///REPLACE THE the begin() fonction by this one:void Adafruit_TFTLCD::begin(uint16_t id) { uint8_t i = 0; reset(); delay(200);////MOD FOR ST7781if(id == 0x7781) { uint16_t a, d; driver = ID_7781; CS_ACTIVE; while(i < sizeof(ST7781_regValues) / sizeof(uint16_t)) { a = pgm_read_word(&ST7781_regValues[i++]); d = pgm_read_word(&ST7781_regValues[i++]); if(a == TFTLCD_DELAY) delay(d); else writeRegister16(a, d); } setRotation(rotation); setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1);}else if((id == 0x9325) || (id == 0x9328)) { uint16_t a, d; driver = ID_932X; CS_ACTIVE; /*while(i < sizeof(ILI932x_regValues) / sizeof(uint16_t)) { a = pgm_read_word(&ILI932x_regValues[i++]); d = pgm_read_word(&ILI932x_regValues[i++]);*/ while(i < sizeof(ST7781_regValues) / sizeof(uint16_t)) { a = pgm_read_word(&ST7781_regValues[i++]); d = pgm_read_word(&ST7781_regValues[i++]); if(a == TFTLCD_DELAY) delay(d); else writeRegister16(a, d); } setRotation(rotation); setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); } else if (id == 0x9341) { uint16_t a, d; driver = ID_9341; CS_ACTIVE; writeRegister8(ILI9341_SOFTRESET, 0); delay(50); writeRegister8(ILI9341_DISPLAYOFF, 0); writeRegister8(ILI9341_POWERCONTROL1, 0x23); writeRegister8(ILI9341_POWERCONTROL2, 0x10); writeRegister16(ILI9341_VCOMCONTROL1, 0x2B2B); writeRegister8(ILI9341_VCOMCONTROL2, 0xC0); writeRegister8(ILI9341_MEMCONTROL, ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR); writeRegister8(ILI9341_PIXELFORMAT, 0x55); writeRegister16(ILI9341_FRAMECONTROL, 0x001B); writeRegister8(ILI9341_ENTRYMODE, 0x07); /* writeRegister32(ILI9341_DISPLAYFUNC, 0x0A822700);*/ writeRegister8(ILI9341_SLEEPOUT, 0); delay(150); writeRegister8(ILI9341_DISPLAYON, 0); delay(500); // *** SPFD5408 change -- Begin // Not tested yet //writeRegister8(ILI9341_INVERTOFF, 0); //delay(500); // *** SPFD5408 change -- End setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); return; } else if (id == 0x8357) { // HX8357D driver = ID_HX8357D; CS_ACTIVE; while(i < sizeof(HX8357D_regValues)) { uint8_t r = pgm_read_byte(&HX8357D_regValues[i++]); uint8_t len = pgm_read_byte(&HX8357D_regValues[i++]); if(r == TFTLCD_DELAY) { delay(len); } else { //Serial.print("Register $"); Serial.print(r, HEX); //Serial.print(" datalen "); Serial.println(len); CS_ACTIVE; CD_COMMAND; write8(r); CD_DATA; for (uint8_t d=0; d<len; d++) { uint8_t x = pgm_read_byte(&HX8357D_regValues[i++]); write8(x); } CS_IDLE; } } return; } else if(id == 0x7575) { uint8_t a, d; driver = ID_7575; CS_ACTIVE; while(i < sizeof(HX8347G_regValues)) { a = pgm_read_byte(&HX8347G_regValues[i++]); d = pgm_read_byte(&HX8347G_regValues[i++]); if(a == TFTLCD_DELAY) delay(d); else writeRegister8(a, d); } setRotation(rotation); setLR(); // Lower-right corner of address window } else { driver = ID_UNKNOWN; return; }}////////////////////////////////////////////////////////////////in your skecth file change tft.begin(0xXXXX) by tft.begin(0x7781)It will be works fine , i hope this help!ipowerkhe

    View Instructable »