Using RGB 888 instead of RGB 565 with ILI9431 TFT display

Hi There :slight_smile:

I have a 2.2" QVGA TFT color screen connected to an Arduino pro mini 3v3 8MHz using hardware SPI.
I used the following code to make the display work and plot on position 0.0 a blue square.

int xpos = 0; //position of cursor x direction 
int ypos = 0; // position of cursor y direction
int color = 31; value 31 represents 0000 0000 0001 1111 or  0x001F which is in RGB 565 format: full Blue
 
#include "SPI.h"
#include <Adafruit_ILI9341.h>

#define TFT_CLK 13
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() 
{
tft.begin();
}

void loop(void) {

tft.drawRect(xpos,ypos, 1, 1, color); // (x position , y position , rectangle width,  reactangle length, Color in RGB 565 format) 

}

Now the problem:

The variable "color" wants RGB565 (16bit) format data.

I want a function that accepts RGB888(24bit) format data :smiley:

The reason for this is that i than easily can apply 1 8 bit variable for each color ( red, green, blue).

So i was tinking, isnt there a function like shown below for this ILI9431 driver?

screen.background(red,green,blue);// Red,green,blue values in 8 bit

This function in above code is from the Arduino TFT example which uses RGB888 input and controls a rgb565 tft display.

Another idea would be to convert RGB888 data with some code/math to RGB565. But i prefer to us a function which just accepts RGB888.

Kind regards

You can display 666 i.e. with 3 SPI bytes per pixel.
Most 9341 libraries use 565 i.e. 2 SPI bytes per pixel.

Your panel is not capable of 888. Nor is the ILI9341 controller.

Yes, you can change the mode on the fly. e.g. reg(0x3A)=0x06 each pixel is 666. reg(0x3A)=0x05 each pixel is 565.

Note that your Adafruit_ILI9341 library will only use 565.

And it is generally faster to use tft.color565(r, g, b) than to send the third byte.
And it is really painful to convert all 565 pixel writes into 666.

David.