Cannot get display to fully work

by using this code:

// include TFT and SPI libraries
#include <TFT.h>  
#include <SPI.h>

// pin definition for Arduino UNO
#define cs   10
#define dc   7
#define rst  9


// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

void setup() {

  //initialize the library
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
  //set the text size
  TFTscreen.setTextSize(2);
  TFTscreen.invertDisplay(1);

  Serial.begin(9600);
}

void loop() {
  Serial.print(TFTscreen.height());
  Serial.print("x");
  Serial.println(TFTscreen.width());

  //generate a random color
  int redRandom = random(0, 255);
  int greenRandom = random (0, 255);
  int blueRandom = random (0, 255);
  
  // set a random font color
  TFTscreen.stroke(redRandom, greenRandom, blueRandom);
  
  // print Hello, World! in the middle of the screen
  TFTscreen.text("Hello, World!", 6, 57);
  
  // wait 200 miliseconds until change to next color
  delay(200);
}

Whole screen should be drawn over with black, but what actually happens is that arduino thinks that the screen is 128x160px instead of 320x240px. The part that arduino does nothing about is filled with noise. The display I'm using is Waveshare 10684 and my arduino is uno.

Which part of the screen does it actually use?

Which part is that?

Top left? Bottom right? etc ...

Looks like the libraries you are using only work for 160x128 TFT. You may need to use a different library.

The size of the screen it set by these lines

#define ST7735_TFTWIDTH  128
#define ST7735_TFTHEIGHT 160

in this file

You could find this file on your PC and change the values to see if that helps.

According to the Waveshare page here

the controller chip is

LCD CONTROLLER ST7789

so perhaps you are lucky that even part of the screen works, because the library is intended for use with ST7735 controller chip.

1 Like

Have you read this page?

1 Like

top left

I have read it but the library included is different from what they've shown in the wiki and arduino ide doesn't detect it.

So the library provided by Waveshare does not work with a Waveshare display? Have you asked Waveshare for help about this?

Did you try editing the file I suggested?

1 Like

Yes, but as you said. This is not the valid chip the library was made for. And expanding the values just made left and top sides be halfway filled with black.

What does that mean? Can you post a photo?

What do you see on serial monitor?


This is what the display shows with the use of modified library and same code.

I see. :thinking:

What if you change this line

TFTscreen.text("Hello, World!", 80+6, 120+57);

UPDATE

I have (I think) finished dealing with issues, here is how I've done it.

  1. Install this:
    https://www.waveshare.com/w/upload/f/f9/2inch8_TFT_Touch_Shield_code2.zip

from the Arduino/lib/LCD copy all files and put in a folder "LCD" in your arduino libraries

this code will allow you to draw on the whole screen

#include <stdint.h>
#include <LCD.h>
#include <SPI.h>

void setup()
{
    SPI.setDataMode(SPI_MODE3);
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV4);
    SPI.begin();
    
    Tft.lcd_init();                                      // init TFT library
    
    Tft.lcd_draw_rect(30, 40, 150, 100, RED);
    Tft.lcd_draw_circle(120, 160, 50, BLUE);
    Tft.lcd_draw_line(30, 40, 180, 140, RED);
    
    Tft.lcd_draw_line(30, 220, 210, 240, RED);
    Tft.lcd_draw_line(30, 220, 120, 280, RED);
    Tft.lcd_draw_line(120, 280, 210, 240, RED);
}

void loop()
{
  
}

Very big thank you to @awneil and @PaulRB for helping me on this crazy journey of making this display work, lol.

1 Like

Just wonderful that waveshare has named the library for their TFT display LCD. You will need to be careful that you do not have any of the numerous libraries for actual LCD displays installed, LCD.h is going to be a very common header file name and the compiler is not particularly smart about using the correct one.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.