Go Down

Topic: mcufreind sheild tft lcd not working (Read 324 times) previous topic - next topic

nishchey

Aug 26, 2019, 05:17 pm Last Edit: Aug 26, 2019, 05:20 pm by nishchey
my lcd screen is not working every time i upload a coad either a error comes or my screen does not do anything .
my code is:
#define LCD_CS A3    
#define LCD_CD A2    
#define LCD_WR A1  
#define LCD_RD A0    
// you can also just connect RESET to the arduino RESET pin
#define LCD_RESET A4
//Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF

#include "TFTLCD.h"

TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

void setup(void) {
 Serial.begin(9600);
 Serial.println("8 Bit LCD test!");
 tft.reset();
 uint16_t identifier = tft.readRegister(0x0);
 if (identifier == 0x9325) {
   Serial.println("Found ILI9325");
 } else if (identifier == 0x9328) {
   Serial.println("Found ILI9328");
 } else {
   Serial.print("Unknown driver chip ");
   Serial.println(identifier, HEX);
 //  while (1);
 }
 tft.initDisplay();
 tft.fillScreen(RED);
 delay(100);
 tft.fillScreen(GREEN);
 delay(100);
 tft.fillScreen(BLUE);
 delay(100);
 tft.fillScreen(WHITE);
 delay(100);
// testtext(RED);
//testlines(CYAN);
 //delay(500);
 //testfastlines(RED, BLUE);
 //delay(500);
 //testdrawrects(GREEN);
// delay(500);
 //testfillrects(YELLOW, MAGENTA);
// delay(500);
// tft.fillScreen(BLACK);
//  testfillcircles(10, MAGENTA);
//  testdrawcircles(10, WHITE);
//  delay(500);
//  testtriangles();
//  delay(500);
//  testfilltriangles();
//  delay(500);
//  testRoundRect();
//  delay(500);
//  testFillRoundRect();
}
double yy=0;
void loop(void) {
 double y=0;
// for (uint8_t rotation=0; rotation<4; rotation++) {
   tft.setRotation(1);
   testtext(RED);
   delay(1000);
// }
   for (double i=1; i<398; i++)
 {
   tft.drawPixel(i,119+(sin(((i*0.9)*3.14)/180)*95),RED);//sin
   tft.drawLine(199, 15, 199, 224,RED);  
   tft.drawLine(1, 119, 398, 119,RED);
   tft.drawPixel(i,119+(cos(((i*0.9)*3.14)/180)*95),RED);   //cos
    y=119+(tan(((i*0.9)*3.14)/180));
   if ((y>15) && (y<224))
   tft.drawPixel(i,y,RED);
 }
    for (double i=1; i<398; i++)
 {
   yy=yy+i;
   Serial.println(yy);
 }
 delay(5000);
}
void testFillRoundRect() {
 tft.fillScreen(BLACK);
 
 for (uint16_t x=tft.width(); x > 20 ; x-=6) {
   tft.fillRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8,  tft.Color565(0, x, 0));
}
}

void testRoundRect() {
 tft.fillScreen(BLACK);
 
 for (uint16_t x=0; x < tft.width(); x+=6) {
   tft.drawRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.Color565(x, 0, 0));
}
}

void testtriangles() {
 tft.fillScreen(BLACK);
 for (uint16_t i=0; i<tft.width()/2; i+=5) {
   tft.drawTriangle(tft.width()/2, tft.height()/2-i,
                    tft.width()/2-i, tft.height()/2+i,
                    tft.width()/2+i, tft.height()/2+i, tft.Color565(0, 0, i));
 }
}

void testfilltriangles() {
 tft.fillScreen(BLACK);
 
 for (uint16_t i=tft.width()/2; i>10; i-=5) {
   tft.fillTriangle(tft.width()/2, tft.height()/2-i,
                    tft.width()/2-i, tft.height()/2+i,
                    tft.width()/2+i, tft.height()/2+i,
                    tft.Color565(0, i, i));
   tft.drawTriangle(tft.width()/2, tft.height()/2-i,
                    tft.width()/2-i, tft.height()/2+i,
                    tft.width()/2+i, tft.height()/2+i, tft.Color565(i, i, 0));    
 }
}
void testtext(uint16_t color) {
 tft.fillScreen(BLACK);
 tft.setCursor(0, 20);
 tft.setTextColor(color);
 tft.setTextSize(1);
 tft.println("Hello World!");
 tft.setTextSize(2);
 tft.println(yy);
 tft.setTextSize(3);
 tft.println(0xDEADBEEF, HEX);
}

void testfillcircles(uint8_t radius, uint16_t color) {
 for (uint16_t x=radius; x < tft.width(); x+=radius*2) {
   for (uint16_t y=radius; y < tft.height(); y+=radius*2) {
     tft.fillCircle(x, y, radius, color);
   }
 }  
}

void testdrawcircles(uint8_t radius, uint16_t color) {
 for (uint16_t x=0; x < tft.width()+radius; x+=radius*2) {
   for (uint16_t y=0; y < tft.height()+radius; y+=radius*2) {
     tft.drawCircle(x, y, radius, color);
   }
 }  
}


void testfillrects(uint16_t color1, uint16_t color2) {
tft.fillScreen(BLACK);
for (uint16_t x=tft.width()-1; x > 6; x-=6) {
  //Serial.println(x, DEC);
  tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
  tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
}
}

void testdrawrects(uint16_t color) {
tft.fillScreen(BLACK);
for (uint16_t x=0; x < tft.width(); x+=6) {
  tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(BLACK);
  for (uint16_t y=0; y < tft.height(); y+=5) {
    tft.drawHorizontalLine(0, y, tft.width(), color1);
  }
  for (uint16_t x=0; x < tft.width(); x+=5) {
    tft.drawVerticalLine(x, 0, tft.height(), color2);
  }
 
}

void testlines(uint16_t color) {
  tft.fillScreen(BLACK);
  for (uint16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, 0, x, tft.height()-1, color);
  }
  for (uint16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, 0, tft.width()-1, y, color);
  }
 
  tft.fillScreen(BLACK);
  for (uint16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
  }
  for (uint16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, 0, 0, y, color);
  }
 
  tft.fillScreen(BLACK);
  for (uint16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, tft.height()-1, x, 0, color);
  }
  for (uint16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
  }

  tft.fillScreen(BLACK);
  for (uint16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
  }
  for (uint16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
  }
}


void testBars() {
 uint16_t i,j;
 for(i=0; i < tft.height(); i++)
 {
   for(j=0; j < tft.width(); j++)
   {
     if(i>279) tft.writeData(WHITE);
     else if(i>239) tft.writeData(BLUE);
     else if(i>199) tft.writeData(GREEN);
     else if(i>159) tft.writeData(CYAN);
     else if(i>119) tft.writeData(RED);
     else if(i>79) tft.writeData(MAGENTA);
     else if(i>39) tft.writeData(YELLOW);
     else tft.writeData(BLACK);
   }
 }
}


david_prentice

First off.   What ID is reported on the Serial Terminal ?

It is always wise to post a link to the actual display e.g. Ebay sale
Or a photo of the pcb side (where the pins are and any printed model, text etc)

Please edit your post to use Code Tags.
There are instructions "How to use Forum"

David.

nishchey

Alright actually i am a beginer. :-)

https://www.amazon.in/gp/product/B00YSGG088/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

can you also guide me about using tft with arduino

david_prentice

Thanks for the link.   It looks like it is an Indian seller.

It shows photos of the original Mcufriend shield pcb.   (which is good)
I suspect that your pcb does not match the photo.

Please read the Forum instructions.

Please install MCUFRIEND_kbv library via the IDE Library Manager.

Run all the examples.   Most will show something on the Serial Terminal (9600 baud)

David.

nishchey

THNAKS DAVID WORKED THEM OUT TOO AND IT WORKED OUT FINE BUT HOW CAN I MAKE MORE CODES AND WHICH LIBRARIES TO USE FOR THE CODE I JUST FIGURED THAT ONLY ADAFRUIT GFX, MCUFRIEND AND ADAFRUIT TOUCH SCREEN IS WORKING

david_prentice

What ID is reported by MCUFRIEND_kbv ?

You should find that 90% of Uno programs on the Internet will work with your screen and MCUFRIEND_kbv.

If you tell us the ID,  we can tell you about other libraries that will work.

David.

CrossRoads

@nishchey, please turn off your Caps Lock. That comes across as shouting.
Thank you.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nishchey

Hello David i have solved the tft problem but most of the codes are made up of adafruit or spdf5408 libraries how can i make a code for mcufreind the id is 0x7783

david_prentice

The only Arduino libraries that support your Sitronix ST7781 controller (ID = 0x7783)
MCUFRIEND_kbv
SWTFT

If you had a more popular controller e.g. ILI9325 (ID = 0x9325) you would find that almost every TFT library supports it.

Any "GFX" style library will work with code written for Adafruit_GFX style graphics.

You just change the hardware library include and associated constructor e.g.

Code: [Select]

#include "TFTLCD.h"
TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);


to

Code: [Select]

#include "MCUFRIEND_kbv.h"
MCUFRIEND_kbv tft;   // knows the Shield wiring

// you can also use this constructor but the arguments are ignored
MCUFRIEND_kbv tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);


or

Code: [Select]

#include "SWTFT.h"
SWTFT tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);


David.

nishchey

thanks a lot david can you also  give me a example code.

david_prentice

File->Examples->MCUFRIEND_kbv->examples

Please quote example name and problem.

You can do the same thing for SWTFT.    I did not write SWTFT

There is no point in writing your own sketch until you have run all the library examples.

There are lots of sketches on the Internet that use TFT shields like yours.
Post a link to the sketch you want to use.

David.

Go Up