SPI TFT kit/When it goes wrong/12. When the colours are wrong
When it goes wrong · 12 of 12

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.

One exception, on two panels

Both fixes are live register writes on the ST7789 and ST7796 panels — the 2.0, 2.4, 2.8 and 3.5 inch — so a test sketch can sweep them without recompiling.

The 0.96 inch and the 1.8 inch are ST7735, where the drawing library underneath takes colour order as a constructor argument rather than a register write. On those two, setColorOrder() has to come before begin(). It returns false if you call it too late rather than quietly doing nothing, so a wrong-looking panel and a false in the log are the same problem.

LB_Display display(LB_TFT_18);

void setup() {
  display.setColorOrder(LB_Display::COLOR_BGR);   // before begin() on ST7735
  display.begin();
  display.setInverted(true);                      // any time, on any panel
}

Why this article exists at all

The panel table that makes every other part of this kit a one-line change is honest about its own limits: the colour order and inversion flags in it have not been measured on a kit panel. The library's own file says so in a warning at the top, and it flags the 1.8 inch outright as unverified — the old Arduino sketches and the old MicroPython scripts disagreed about that panel, 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.

So treat the flags as very likely right and immediately checkable. Run the self-test, look at the labelled bars, and if a panel is wrong you now know which call to reach for.

And if it is a panel 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 on the ST7789 and ST7796 panels you can make that call at any time — it is a live register write.

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.

setColorOrder returns false on my 0.96 or 1.8 inch

Those two are ST7735 panels, and the underlying library takes colour order as a constructor argument rather than a register write — so it has to be set before begin. The call returns false rather than failing silently, which is the whole reason it has a return value. Move it above begin and it will take.

The colours were fine and a new batch of panels 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/spi-tft-kit/when-the-colours-are-wrong.mdx

Community

Questions about this product

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

Ask a question ↗

SPI TFT LCD Display Kit, 6-Pack from 0.96 to 3.5 inch

Loading 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