Colour confusion issue with unbranded 160x80 tft and Adafruit library

You don’t say which library you are using. Adafruit_ST7735 ?

   tft.invertDisplay(1);    //for most GFX libraries

If you quote the library, we can show you how to match the panel by default.

David.

Sorry, forgot to include that. But yes, I’m using the Adafruit ST7735 libraries.

#include <Adafruit_GFX.h>         // Core graphics library
#include <Adafruit_ST7735.h>      // Hardware-specific library
#include <Adafruit_ImageReader.h> // Image-reading functions

Any ideas, anyone? Still struggling with this.

Quote library version(s)
Quote which library example.

Did you try tft.invertDisplay(1);
Did you try tft.invertDisplay(0);

Did it change colours?

David.

david_prentice:
Quote library version(s)
Quote which library example.

Did you try tft.invertDisplay(1);
Did you try tft.invertDisplay(0);

Did it change colours?

David.

Hi David,

This is one of the first things I tried. It did change the colours, but not in the way you might expect. Black and white obviously changed, but the RGB remained incorrect, but in a different way.

My apologies. Inverted colours are:

WHITE->BLACK
GREEN->MAGENTA
RED->CYAN
BLUE->YELLOW

Your image seems to show RED->YELLOW which is an impossibility.

So you need invert display AND swap Red and Blue.
e.g. use ST77XX_MADCTL_RGB or ST7735_MADCTL_BGR in tft.setRotation()

It is not uncommon to have a panel with inverted colours.
It is very unusual to have a panel with BGR instead of RGB.

Please can you post your sketch. Or at least paste the setup() function to your message.

David.

Hey,

did you get this fixed?
I seem to have a similarly strange display (this one, to be exact).

When I tft.invertDisplay(true) I get the following colors correctly:

  • Black
  • white
  • green

Red and blue stay inverted.

the suggestion of using ST7735_MADCTL_BGR in tft.setRotation() did not work, as this constant does not appear to be defined in Adafruit_ST77xx.h

Cheers,
Alex

So you need invert display AND swap Red and Blue.
e.g. use ST77XX_MADCTL_RGB or ST7735_MADCTL_BGR in tft.setRotation()

The advice in #6 is correct.
Adafruit_ST7735.h includes Adafruit_ST77xx.h so both macros are available.

From Adafruit_ST7735.cpp setRotation() method

    if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) {
      madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB;
    } else {
      madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST7735_MADCTL_BGR;
    }

Please run the IDE Library Manager. Report the Adafruit_ST7735 and Adafruit_GFX version numbers.

David.

Hi David,

apologies, you were right all along.

After initializing with
tft.initR(INITR_GREENTAB);
tft.setRotation(ST7735_MADCTL_BGR);

all colors are as expected.

I was confused as the display I have is a 0.96" 160x80 TFT, so I assumed I had to initialize with INITR_MINI160x80, which is obviously not the case.

Thanks a lot for the sage advice!

Cheers,
Alex

Ok, maybe I was too hasty...

In order to get correct colors I actually need to initialize with

  tft.initR(INITR_GREENTAB);
  tft.setRotation(ST7735_MADCTL_BGR);
  tft.invertDisplay(true);

However, initializing with INITR_GREENTAB sets the display dimensions to 128x160, which is 48 pixels too wide for my 80x160 pixel display...

I tried to understand a little how the Adafruit library does the initialization, but I couldn't really see a way to get the correct screen size AND correct BRG madcontrol together.

Libraries are installed using platformio:
"Adafruit ST7735 and ST7789 Library" @ 1.5.15
Adafruit GFX Library @ 1.7.5

I'm driving the display using an ESP12-F Devkit v3

Any further advice in this matter?

Cheers,
Alex

Hi!

I have some of those "buggy" displays (0.96") and — before finding these hints in the forum — I defined the colors matching the display.

// Color definitions (correct)
// #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 DGRAY 0x2945
// #define LGRAY 0x528A
// #define ORANGE 0xFC02

// Color definitions for displays with buggy color system
#define BLACK 0xFFFF
#define BLUE 0x07FF
#define RED 0xFFE0
#define GREEN 0xF81F
#define CYAN 0x001F
#define MAGENTA 0x07E0
#define YELLOW 0xF800
#define WHITE 0x0000
#define DGRAY 0x528A
#define LGRAY 0x2945
#define ORANGE 0xFC02

I know, it's not the expert's way, but it works. 8)

Edit C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_ST7735_and_ST7789_Library\Adafruit_ST7735.cpp to change the ".kbv" commented lines

void Adafruit_ST7735::initR(uint8_t options) {
  ...
  } else if (options == INITR_MINI160x80) {
    _height = ST7735_TFTWIDTH_80;
    _width = ST7735_TFTHEIGHT_160;
    displayInit(Rcmd2green160x80);
    _colstart = 26; //24; //.kbv
    _rowstart = 1; //0; //.kbv
    //invertDisplay(1);  //.kbv enable if you have inverted colours
  } else {
  ...
void Adafruit_ST7735::setRotation(uint8_t m) {
  ...
  switch (rotation) {
  case 0:
    if ((tabcolor == INITR_BLACKTAB) /*|| (tabcolor == INITR_MINI160x80) */) { //.kbv
  ...
  case 1:
    if ((tabcolor == INITR_BLACKTAB) /*|| (tabcolor == INITR_MINI160x80)*/) { //.kbv
  ...
  case 2:
    if ((tabcolor == INITR_BLACKTAB) /*|| (tabcolor == INITR_MINI160x80)*/) { //.kbv
  ...
  case 3:
    if ((tabcolor == INITR_BLACKTAB) /*|| (tabcolor == INITR_MINI160x80)*/) { //.kbv
  ...

This should give you correct colours and rotations for the Ebay display.

I presume that Adafruit are using a "different" 80x160 display.
It would possibly be better to add a new "xxxTAB" sequence

YMMV

David.

1 Like

david_prentice:
[...]

I presume that Adafruit are using a "different" 80x160 display.
It would possibly be better to add a new "xxxTAB" sequence

YMMV

David.

Just a short notice: My displays, bought via chinese marketplace, have blue tabs ...

Sensor

You write in your first post:

The first thing I noticed when I started playing around was that the screen's zero position was off slightly. I'm using Adafruit libraries, so I just went in and modified the screen offset.

How did you actually change this screen zero position setting?

Compare the item on your desk with photos from message, link, Ebay shop, ...
Always say which display you have. e.g. quote message#, link, Ebay shop, ...

Read #12

If you have a problem, say so.

David.

david_prentice

Thank you very much - your reply helped me.
For me it was not clear the offset problem was also solved in the post #12.

But it is I can no use my 160x80 displays.

Seriously. It is wise to to say: My display is exactly like photo in #0
Or My display is exactly like link in #7

This is less effort than posting your specific link (URL).

Especially for readers on a phone or tablet.

David.

david_prentice

If you say so.

david_prentice & AF
thank you very much, your reply helped me.
all is well...