St7735 0.96" 160x80 shows wrong colors

#include <Adafruit_GFX.h>    // Core graphics library
#include <splash.h>
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <SPI.h>

#include "bitmaps.h"

#define TFT_CS  10
#define TFT_RST 9
#define TFT_DC 8


const uint16_t BLACK = 0x0000;
const uint16_t WHITE = 0xffff;
const uint16_t BLUE = 0x001f;
const uint16_t RED = 0xf800;
const uint16_t YELLOW = 0xffe0;
const uint16_t GREEN = 0x07e0;


Adafruit_ST7735 display = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  display.initR(INITR_MINI160x80);
  display.setRotation(3);
  display.invertDisplay(true);

  display.setCursor(0, 0);
  display.setTextSize(3);
  display.fillScreen(BLACK);
  
  //display.drawBitmap(0, 0, boot_logo, 160, 80, BLUE);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  display.setCursor(0, 0);
  display.setTextColor(WHITE);
  display.fillScreen(BLACK);
  display.print("Testing");

  delay(1000);
  display.setCursor(0, 0);
  display.setTextColor(BLUE);
  display.fillScreen(BLACK);
  display.print("Testing");

  delay(1000);
  display.setCursor(0, 0);
  display.setTextColor(RED);
  display.fillScreen(BLACK);
  display.print("Testing");

  delay(1000);
  display.setCursor(0, 0);
  display.setTextColor(YELLOW);
  display.fillScreen(BLACK);
  display.print("Testing");

  delay(1000);
  display.setCursor(0, 0);
  display.setTextColor(GREEN);
  display.fillScreen(BLACK);
  display.print("Testing");
  
}

This is my code and as you can see I printed "Testing" in different colors. The order should be White-Blue-Red-Yellow-Green but the actual results were different. It was White-Red-Blue-Cyan-Green. And it seems like red and blue need to be swapped. Also, I inverted the display because 0x0000 showed white and 0xffff showed nothing. And that seems to be right because green showed green just fine. Anyone know how I can change red and blue?

Sure, break the hex codes into binary, then you can deduce which bits belong to which primary colour.

Here's another way. Swap the primary definitions of RED and BLUE;

so you have

const uint16_t RED = 0x001f;
const uint16_t BLUE = 0xf800;

then mix the others:

const uint16_t YELLOW = RED | GREEN;

No, you don't.

Most controllers have a register bit that controls RGB or BGR colour mapping.

The library should set it to match your particular panel. i.e. with the appropriate tft.initR() argument.

Ebay 160x80 displays must use a different panel to the Adafruit 160x80 displays.

It is much easier to give an accurate reply to a display question when you post a link to the actual display that you have bought.

David.

Perfect. Even so, I think it's a neat trick to do colour mixing:

const uint16_t YELLOW = RED + GREEN;

even

const uint16_t WHITE = RED + GREEN + BLUE;

At first I thought about that but I will upload my project to github once it's done so if I change the definitions people using the adafruit displays won't be able to use my code.

I live in Korea so I ordered the display from Coupang. Here is the link
https://www.coupang.com/vp/products/5860372824?vendorItemId=77506171138&sourceType=MyCoupang_my_orders_list_product_image&isAddedCart=

I couldn't find any 160x80 with BGR configuration so I changed it myself. Thanks

I am not sure whether you are talking about my suggestion. If you are, it's fully compatible with either RGB or RBG. The difference is only in the codes you use for the primary colors RED and BLUE. The result of defining it my way, is not at all different than the result of defining it the original way.

In reply #2, I show definitions for both the original RGB, and the modified RBG. Any color mixing by definition such as

const uint16_t WHITE = RED + GREEN + BLUE;

using logical or, or addition, is completely indifferent to which one of RGB or RBG you use.

In other words, my suggestion is not to change from RGB or any other format to any other format; it's just to use a different method to assemble the non-primary colours. The only difference between mine and the original, is that the original codes were calculated manually.

I was talking about your suggestion. I did try changing the definition for RED and BLUE and then mixing it for other colors and of course it worked. But what I meant was that I will post this project on github when I'm done with it so if I solve my problem by mixing the colors, the code will work for me and other people who bought a BGR type display, but for the people who use adafruit RGB display, it won't. And as you can see above, I solved my problem by editing the library itself. Thatway I don't have to change the code and make other people confused.

What I mean, is that you can use the colour mixing technique I showed, without changing the RGB to BGR at all. It would have no effect on the generated code, which would run identically.

I don't think it would confuse any developers that read it - or it shouldn't. :slight_smile: Because it is more explicit and understandable than what is there now.

All it does is take

const uint16_t BLACK = 0x0000;
const uint16_t WHITE = 0xffff;
const uint16_t BLUE = 0x001f;
const uint16_t RED = 0xf800;
const uint16_t YELLOW = 0xffe0;
const uint16_t GREEN = 0x07e0;

re-arrange and spruce up

const uint16_t BLUE = 0x001f;
const uint16_t RED = 0xf800;
const uint16_t GREEN = 0x07e0;
const uint16_t BLACK = 0;
const uint16_t YELLOW = RED + GREEN;
const uint16_t CYAN = GREEN + BLUE;
const uint16_t MAGENTA = RED + BLUE;
const uint16_t WHITE = RED + BLUE + GREEN;

did you even read my comment? I said I do understand what you are saying and I even tried doing it. And of course it worked. I know enough basic stuff to know color mixing. But, I WILL POST THIS PROJECT TO GITHUB WHEN I'M DONE. So, I can't touch the code itself to fix the problem. Ok? I know I sound kinda mean but it seems like you're not really reading my comment carefully.

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