Wrong code or bad board?

I'm new to the forum and not sure where I have an issue. Bought the Uno board and a tft board, and uploaded the following code but do not get the text to show up. as soon as I plug the board in to the USB port, I just get a blank white screen.

Any ideas on if I have an issue with the code, or possibly a bad Uno or tft board?
I appreciate any help to get me started :slight_smile:

Here is the code:


#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0

#define LCD_RESET 10



#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

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

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
tft.setCursor(100, 206);
      tft.setTextColor(RED, BLACK);
      tft.print("Hello World!");
}

Setup initializations are missing from the display
See an example of the library used in your sketch to learn how to initialize.

Some thing like this.... tft.begin();

To test your display use examples from the libraries.

RV mineirin

Thanks, I added the tft.begin and now get flashing red, so I know both boards are working, and just need to read up a bit more to get the coding down.

I uploaded the graphicstest from the examples as suggested, and only get a blank white screen. Has anyone else encountered this? Has me wondering again if it is a bad tft board.

Hi, @rmurray1620
Welcome to the forum.
Can you please post a link to data/spec of the TFT Display please?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Tom,
Here is a link to where I bought the board, but I don't see any specs. Lesson learned on my end with this :slight_smile:

https://www.shophedel.com/collections/screen-and-displays/products/60050

Your link shows a regular "Mcufriend Uno Shield".
These come with random TFT controllers. Adafruit_TFTLCD library only supports the more common controllers like ILI9325, ILI9341.

Install MCUFRIEND_kbv via the IDE Library Manager.
This library supports many more controllers.
Run all of the library examples.
Quote the example by name if you have a problem.

David.

1 Like

Great, thank you David for the help!

I installed the MCUFRIEND_kbv and ran the library examples, but still nothing other than the white screen. My guess now is the board is no good.

Surely the examples would have printed something on the Serial Terminal. The
C:\Users\...\Documents\Arduino\libraries\Mcufriend_kbv\extras\mcufriend_how_to.txt file offers some tips.

LCD_ID_readreg.ino or diagnose_TFT_support.ino would be the obvious examples.

David.

Just reran the LCD_ID_readreg.ino and diagnose_TFT_support.ino files and still nothing but a white screen. Going to try a few other ideas to see if I can get anything else to show up before I ask for more help.

Hi,
I have the same display;

Running the kbv graphic tester, I have found that the ID for mine is 0x9329.
The ID read by the program is not the correct ID.
Here is the testpattern code with the ID edited, so it should run.
I have set the monitor baud at 115200.

/*
   generate testcard similar to BMP
*/

#include <Adafruit_GFX.h>
#if defined(_GFXFONT_H_)           //are we using the new library?
#include <Fonts/FreeSans9pt7b.h>
#define ADJ_BASELINE 11            //new fonts setCursor to bottom of letter
#else
#define ADJ_BASELINE 0             //legacy setCursor to top of letter
#endif
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define RGB(r, g, b) (((r&0xF8)<<8)|((g&0xFC)<<3)|(b>>3))

#define GREY      RGB(127, 127, 127)
#define DARKGREY  RGB(64, 64, 64)
#define TURQUOISE RGB(0, 128, 128)
#define PINK      RGB(255, 128, 192)
#define OLIVE     RGB(128, 128, 0)
#define PURPLE    RGB(128, 0, 128)
#define AZURE     RGB(0, 128, 255)
#define ORANGE    RGB(255,128,64)

#include <stdio.h>

uint16_t ID;
uint8_t hh, mm, ss; //containers for current time

uint8_t conv2d(const char* p)
{
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9') v = *p - '0';
  return 10 * v + *++p - '0';
}

void setup(void)
{
  Serial.begin(115200);
  Serial.println("===testcard_kvb  ID = 0x9329 By TomGeorge 2021===");
  tft.reset();
  ID = tft.readID();
  Serial.print("ID read from the TFTLDC = 0x");
  Serial.println(ID, HEX);
  //    if (ID == 0xD3D3) ID = 0x9481; // write-only shield
  //   if (ID == 0xD3D3) ID = 0x9486; // write-only shield
  ID = 0x9329;
  Serial.print("Working TFT ID = 0x");
  Serial.println(ID, HEX);
  tft.begin(ID);
  tft.setRotation(1);
  tft.fillScreen(BLACK);
#if defined(_GFXFONT_H_)
  tft.setFont(&FreeSans9pt7b);
#endif
  hh = conv2d(__TIME__);
  mm = conv2d(__TIME__ + 3);
  ss = conv2d(__TIME__ + 6);

}

void loop(void)
{
  int16_t x, y, dx, dy, radius = 108, idx;
  uint16_t w, h, len, mask;
  uint16_t colors[8] = { BLACK, WHITE, YELLOW, CYAN, GREEN, MAGENTA, RED, BLUE };
  uint16_t height, width;
  width = tft.width();
  height = tft.height();
  tft.fillRect(0, 0, 7, 3, WHITE);
  tft.fillRect(313, 0, 7, 3, WHITE);
  tft.fillRect(0, 237, 7, 3, WHITE);
  tft.fillRect(313, 237, 7, 3, WHITE);
  for (y = 0, w = 18, h = 3; y < 240; y += 13 * w + h) {
    for (x = 25; x < 320 - 18; x += 2 * w) {
      tft.fillRect(x, y, w, h, WHITE);
    }
  }
  for (x = 0, w = 7, h = 18; x < 320; x += 17 * h + w) {
    for (y = 21; y < 240 - 18; y += 2 * h) {
      tft.fillRect(x, y, w, h, WHITE);
    }
  }
  tft.fillRect(7, 3, 17 * 18, 13 * 18, GREY);
  for (x = 7, y = 0, w = 1, h = 240; x < 320; x += 18) {
    tft.fillRect(x, y, w, h, WHITE);
  }
  for (x = 0, y = 3, w = 320, h = 1; y < 240; y += 18) {
    tft.fillRect(x, y, w, h, WHITE);
  }
  tft.fillRect(26, 22, 17, 99, TURQUOISE);
  tft.fillRect(26, 120, 17, 99, PINK);
  tft.fillRect(44, 22, 17, 35, AZURE);
  tft.fillRect(44, 184, 17, 35, ORANGE);
  tft.fillRect(260, 22, 17, 35, AZURE);
  tft.fillRect(260, 184, 17, 35, ORANGE);
  tft.fillRect(278, 22, 17, 99, OLIVE);
  tft.fillRect(278, 120, 17, 99, PURPLE);

  for (dx = radius; dx > -radius; dx--) {
    w = sqrt(radius * radius - dx * dx);
    y = 120 - dx;
    dy = (y - 3) / 18;
    mask = 7;
    colors[0] = (dy == 3) ? DARKGREY : BLACK;
    switch (dy) {
      case 0:
      case 1: idx = 1; len = 0; break;
      case 2: idx = 0; len = 0; break;
      case 3: idx = 0; len = 13; mask = 1; break;
      case 4:
      case 5: idx = 2; len = 38; break;
      case 6:
      case 7:
      case 8: idx = 0; len = 0; break;
      case 9: for (idx = 2; idx < 8; idx++) {
          //dy = 0xFF >> (7 - idx);
          dy = (idx - 2) * 51;
          colors[idx] = tft.color565(dy, dy, dy);
        }
        idx = 2; len = 38; break;
      case 10: idx = 1; len = 0; break;
      case 11:
      case 12: colors[2] = YELLOW; idx = 2; len = 0; break;
    }
    if (len == 0)
      tft.fillRect(160 - w, y, w * 2, 1, colors[idx]);

    else {
      if (mask == 1) idx = 1 + (w) / len;
      dy = w % len;
      for (x = 160 - w; x < 160 + w; idx++) {
        tft.fillRect(x, y, dy, 1, colors[idx & mask]);
        x += dy;
        if (x + len > 160 + w) dy = w % len;
        else dy = len;
      }
    }

  }
  for (x = 72, y = 129, dx = 5, dy = 0; dx > 0; x += 2 * dx) {
    tft.fillRect(x, y, dx, 36, WHITE);
    dy += dx * 2;
    if (dy >= 36) {
      dy = 0;
      dx--;
    }
  }
  tft.fillRect(160 - 8, 5 * 18 + 3, 17, 3 * 18, BLACK);
  for (x = 3 * 18 + 7, y = 6 * 18 + 3, w = 1, h = 18; x < 160 + 108; x += 18) {
    tft.fillRect(x, y, w, h, WHITE);
  }
  tft.fillRect(160 - 108, 120, 108 * 2, 1, WHITE);
  tft.fillRect(160, 5 * 18 + 3, 1, 3 * 18, WHITE);
  tft.fillRect(108, 2 * 18 + 3, 6 * 18, 18, WHITE);
  //    tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
  tft.fillRect(160 - 8, 11 * 18 + 3, 17, radius - 18 * 9 / 2, RED);
  tft.setCursor(160 - 36, 24 + ADJ_BASELINE);
  tft.setTextColor(BLACK);
  tft.setTextSize(1);
  tft.print("320x240");
  tft.setCursor(109, 43 + ADJ_BASELINE);
  tft.setTextColor(BLACK);
  tft.setTextSize(1);
  tft.print("ID=0x");
  tft.print(ID, HEX);
  tft.setTextColor(WHITE, BLACK);
  //    tft.setFont(NULL);
  //    tft.setTextSize(2);
  while (1) {
    if (++ss > 59) {
      ss = 0;
      mm++;
      if (mm > 59) {
        mm = 0;
        hh++;
        if (hh > 23) hh = 0;
      }
    }
    char buf[20];
    sprintf(buf, "%02d:%02d:%02d", hh, mm, ss);
    tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
    tft.setCursor(128, 187 + ADJ_BASELINE);
    tft.print(buf);
    delay(1000);
  }
}

I hope this works for you as well.

Tom... :grinning: :+1: :coffee: :australia:
PS. Sorry for the image quality, not my best phone.

@ rmurray1620,
@ TomGeorge,

Please run LCD_ID_readreg.ino from the examples.

Set your Serial Terminal to 9600 baud.
Please Copy-Paste the output from the Serial Terminal to your message.

Most example programs will use 9600 baud as an internationally accepted standard baud rate.

@ TomGeorge,

Of course you can use 115200 baud if you prefer. It just means that examples will not run out of the box. You would have to edit examples for Serial.begin(115200);

It is much easier to say I have run testcard_kbv.ino from the examples with these alterations e.g.

  Serial.begin(115200);
  Serial.println("===testcard_kvb  ID = 0x9329 By TomGeorge 2021===");
  tft.reset();
  ID = tft.readID();
  Serial.print("ID read from the TFTLDC = 0x");
  Serial.println(ID, HEX);
  //    if (ID == 0xD3D3) ID = 0x9481; // write-only shield
  //   if (ID == 0xD3D3) ID = 0x9486; // write-only shield
  ID = 0x9329;
  Serial.print("Working TFT ID = 0x");

I have not attempted to diff the rest of your code.

David.

Hi,

Here is the testpattern code with the ID edited, so it should run.
I have set the monitor baud at 115200.

What is wrong with just copy and pasting my code into the IDE and uploading and running it?
Have you tried the code?
All you have to do is change the baud rate on your monitor screen.

Tom... :grinning: :coffee: :coffee: :coffee: :coffee: :australia:

Hi,
If you are upset about this;

Serial.println("===testcard_kvb  ID = 0x9329 By TomGeorge 2021===");

I do this to most of my codes so that when I run them, the IDE monitor tells me the filename of the code it is running and the version.
For reference, this is the back of the display;


The two display drivers are SM245TS.
Sorry not the drivers..

Tom... :grinning: :coffee: :coffee: :coffee: :coffee: :australia:

What is returned by tft.readID(); ?

Please run LCD_ID_readreg.ino and copy-paste it to your message.

Hi,

What is it supposed to do?
Have you tried my code?
This is what appears in my monitor;

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 00 00 ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 00 93 40 Manufacturer ID
reg(0x0009) 04 04 61 00 00 Status Register
reg(0x000A) 08 08 Get Power Mode
reg(0x000C) 66 66 Get Pixel Format
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x0070) 00 00 Panel Himax HX8347-A
reg(0x00A1) 00 FF 00 FF 00 RD_DDB SSD1963
reg(0x00B0) 00 00 RGB Interface Signal Control
reg(0x00B4) 00 00 Inversion Control
reg(0x00B6) 00 00 00 00 00 Display Control
reg(0x00B7) 00 00 Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 00 00 00 00 00 00 00 00 Panel Control
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA
reg(0x00CC) 00 00 Panel Control
reg(0x00D0) 40 40 01 Power Control
reg(0x00D2) 40 40 01 40 40 NVM Read
reg(0x00D3) 00 00 93 40 ILI9341, ILI9488
reg(0x00D4) 00 00 00 00 Novatek ID
reg(0x00DA) 00 00 RDID1
reg(0x00DB) 93 93 RDID2
reg(0x00DC) 40 40 RDID3
reg(0x00E0) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA-P
reg(0x00E1) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA-N
reg(0x00EF) 00 00 00 00 00 00 ILI9327
reg(0x00F2) 00 00 00 00 00 00 00 00 00 00 00 00 Adjust Control 2
reg(0x00F6) 00 00 00 00 Interface Control

Tom.. :grinning: :coffee: :coffee: :coffee: :coffee: :coffee: :coffee: :coffee: :australia:

You have an Ilitek ILI9340 Controller.

Please install MCUFRIEND_kbv via the IDE Lrary Manager

I suggest that you remove any library installed from elsewhere.

Now that I know you have an ILI9340 I can try your pasted code on an ILI9340 Shield. I am sure that I will get the same result as you. But it would fail on a different controller

David.

Hi,

What do you mean, how many different displays do you have?

But it would fail on a different controller

Ofcourse that will happen, that is why the library has so many different parameters.

I fail to see the real object of this thread, I thought you wanted to get a library, code that would give you a readable display.
Why do you need to know what driver I have, you just stated that if mine was wrong it won't work.

PLEASE tell me why you didn't try my code WHEN I posted it.
Why waste posts????

Tom... :grinning: :coffee: :coffee: :coffee: :coffee: :mogadon: :australia: