SPI TFT display/When it goes wrong/20. When the colours are wrong
When it goes wrong · 20 of 20

When the colours are wrong

Red arriving as blue is a colour-order fault. Black arriving as white is an inversion fault. Red arriving as yellow looks like a third kind and is really both at once — and each one takes a single call to fix.

Diagnose it before you change anything

Fill the screen with pure red, then green, then blue, and leave a black bar somewhere you can see. Then read the symptom.

Asked for, and shown
setColorOrder()
Symptom
Black comes out
black
The call to make
setColorOrder()
Look at black first. If black is still black, only the colour order is wrong and one call fixes it. If black has come out white, the panel is inverted — and if red is arriving as yellow, both are wrong at once, which is not a third kind of fault but the first two stacked. Invert red and you get cyan; swap cyan’s channels and you get yellow.

Three symptoms, three causes, and the black bar is what separates them.

Black is the tell

If black is still black, only the channel order is wrong. The panel wants its three colour channels in the opposite order from the one being sent, so red and blue trade places and green — which sits in the middle — is unaffected. That is setColorOrder().

If black has come out white, the panel is inverted. Every value is being displayed as its opposite, which is a single bit in the controller and a single call: setInverted().

If red is arriving as yellow, both are wrong at once. It looks exotic and it is not: invert red and you get cyan, then swap cyan's channels and you get yellow. Two calls, and the arithmetic is worth following once so the symptom is recognisable on sight.

The two calls, and when

Both are single register writes, so they work at any time, before or after begin(), on every controller in these boards. A test sketch can sweep them without recompiling.

LB_Display display(LB_TFT_18);

void setup() {
  display.begin();
  display.setColorOrder(LB_Display::COLOR_BGR);   // red and blue swapped
  display.setInverted(true);                      // black coming out white
}

setColorOrder() still returns a bool so that older sketches compile; it is always true. printInfo() reports both settings and marks either one (forced) when you have overridden the table.

Why this article exists at all

The panel table that makes every other part of this book a one-line change is honest about its own limits: the colour order and inversion flags in it have not been measured on these boards. The library's own file says so in a warning at the top, and marks the colour order of one panel outright as unverified. The old Arduino sketches and the old MicroPython scripts disagreed about it, and nobody noticed for a long time because the test drew unlabelled colour bars. You cannot tell red from blue in a bar with no caption.

This book does not print the flags for that reason. What is true whatever they turn out to be is the symptom table above. Run the self-test, look at the named screens, and if a board is wrong you now know which call to reach for.

And if it is a board we sell, say so rather than working around it in your sketch. The value belongs in panels.yaml, where both languages pick it up and the next person does not have to find it again.

When it does not work

Red comes out blue but black is still black

Colour order only. The panel expects its three channels in the opposite order from the one the driver is sending. One call to setColorOrder fixes it, and you can make it at any time, before or after begin(), on every board.

Everything looks like a photo negative

Inversion. The controller's invert bit is the wrong way round for this glass, which is a property of the panel rather than of your code. setInverted(true) or setInverted(false) flips it, live, either before or after begin().

Red comes out yellow, green magenta, blue cyan

Both faults at once, which is not a third kind of fault. Invert red and you get cyan; swap cyan's channels and you get yellow. Call setColorOrder and setInverted both, and check the black bar as you go: black coming out white is the inversion, and fixing it first leaves a plain red-blue swap.

The colours were fine and a new batch of boards is wrong

That happens: the glass in front of a controller can be wired differently between production runs. Fix it in your sketch to get moving, then report it, because the right place for the value is the library's panel table where both the Arduino and MicroPython sides pick it up.

Where this goes next

The other half of running any of this from a 5 V board — which converter, and which way round.

Logic level converters →

Edit this page — content/books/lcd/when-the-colours-are-wrong.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

This page covers several products. Choose yours to see the right discussions.

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →