tft.setTextColor(ST7735_BLUE); but TFT shows text color Red

I put in my TFT 1.8" code; tft.setTextColor(ST7735_BLUE); but the text in the TFT is RED, someone could guide me about it.
the library is Adafruit_ST7735.h.

Thank you in advance.

What happens when you set tft.setTextColor(ST7735_RED);? It may be a matter of how the byte order is sent on the wire but you haven’t said what Particle device you are using, what pins, etc.? You didn’t say exactly what display you are using either. Did you buy it from Adafruit?

Sorry i´m using a Photon P0 and TFT 1.8" spi 128X160 of China, image
The code is :

#include <Adafruit_ST7735.h>
#define cs   A2
#define dc   A1
#define rst  A0 
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); // hardware spi

void setup()
{
	tft.initR( INITR_REDTAB );  // enciende la pantalla
     
	tft.fillScreen(ST7735_BLACK);

    tft.setCursor(0, 50);
    tft.setTextColor(ST7735_WHITE);
    tft.setTextWrap(true);
    tft.fillScreen(ST7735_BLACK);
    tft.print("Ejemplo de manejo de una pantalla TFT.");     
    tft.print("                          "); 
    tft.print("Example.");
   delay(5000);
tft.fillScreen(ST7735_WHITE);
}

void loop() {
    delay(1000);
    tft.setCursor(10, 20);
    tft.setTextColor(ST7735_RED);
    tft.setTextSize(4);
    tft.print("HI."); 
    delay(1000);
    tft.setCursor(20, 80);
    tft.setTextColor(ST7735_BLUE);
    tft.setTextSize(2);
    tft.print("IOT."); 
}

TFT pins are
SDA (MOSI) = A5
SCL (SCK) = A3
SS (CS) = A2
DC = A1 (Command/Data Selection)
RES (RST) = A0 (LCD controller reset, active low )

I had never used the Adafruit library, only TFT for Arduino, and I’m doing a test

Great. Much better details. When you set text to red, does it display red?

No When i set text color RED, the text change to BLUE

also the same thing occur with the green and yellow, and vice versa.
So for example check this :

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_ST7735.h>

#define cs   A2
#define dc   A1
#define rst  A0 

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); // hardware spi

void setup()
{
	tft.initR( INITR_GREENTAB );
     
	tft.fillScreen(ST7735_BLACK);

    tft.setCursor(0, 0);
    tft.setTextColor(ST7735_WHITE);
    tft.setTextWrap(true);
    tft.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla");     
    
    tft.drawLine(0, 0, tft.width()-1, tft.height()-1, ST7735_YELLOW);
    tft.drawLine(tft.width()-1, 0, 0, tft.height()-1, ST7735_YELLOW);

    tft.drawPixel(0, tft.height()/2, ST7735_GREEN);

}

void loop() {

}

That is an example of jenschr of Particle Community,

Particle Web IDE

Are black and white displayed correctly?
Otherwise you could try tft.invertDisplay(true)

You could also try one of the alternative init functions tft.initB(), tft.initG(), tft.initR(INITR_REDTAB) or tft.initR(INITR_BLACKTAB) for alternative endianness of the display’s color buffer.

2 Likes

Sounds like your display wants the RGB bytes sent in reverse order from the Adafruit display defaults.

This leads me to believe that the bit order of the colors is also reversed. Follow @ScruffR's advice to change the byte and bit orders, or just invert the display.

2 Likes

Thanks ninjatill and ScruffR, I thought it was a mistake of mine, but apparently is from the library

How did you establish that?

2 Likes

I really do not know the library very well, I’m starting to know it, but in Arduino the same thing happened to me, at this moment I have done is to define the colors to avoid that, I really do not consider it an error, probably there is something I have not achieved understand but this is I have added to my code:

#define ST7735_BLACK 0x0000
#define ST7735_RED 0x001F
#define ST7735_GREEN 0x07E0
#define ST7735_WHITE 0xFFFF
#define ST7735_BLUE 0xF800
#define ST7735_CYAN 0x07FF
#define ST7735_YELLOW 0xFFE0
#define ST7735_MAGENTA 0xF81F
every color name is related with the Hexdecimal value

The "mistake" (if any) is with the TFT manufacturer not conforming to the Adafruit library defaults... or I suppose it's your mistake since you are using a non-Adafruit display with an Adafruit library. However, as ScruffR states, the Adafruit library has a tools to allow you to correct the library behavior to match the TFT workings. How you fix is up to you, but at least we understand what it going on.

4 Likes

Hi @utlaiotlabelectronic

This is a fairly common packed RGB format in a 16-bit word with B-G-R from high to low in the library and 5-bits for B, 6-bits for G, and 5-bits for R.

You could reverse the color definitions by hand so that RED was 0xF800 etc.

3 Likes

ok, I understand, it’s something related to compatibility, due to the TFT that I’ve been using

Thanks ninjatill, ScruffR and bko,

1 Like