3
\$\begingroup\$

I am playing with 3,5" (400x240 chinese unknown 8-bit controller driven) TFT display which is placed into Arduino Mega 2560 R3 board.

My final goal is taking .raw data from SD card and drawing it on display.

What I have done so far:

- My drawing method in the sketch:

void LoadImage(File& file)
{
    for (int y = 0; y < SCREEN_HEIGHT && file.available(); y++) {
        uint16_t buf[SCREEN_WIDTH];
        for (int x = SCREEN_WIDTH - 1; x >= 0; x--) {
            byte l = file.read();
            byte h = file.read();
            buf[x] = ((uint16_t)h << 8) | l;
        }
        myGLCD.drawPixelLine(0, y, SCREEN_WIDTH, buf);
    }
}

- For reference drawPixelLine method's implementation from UTFT library:

void UTFT::drawPixelLine(int x, int y, int sx, uint16_t* data)
{
    unsigned int col;
    cbi(P_CS, B_CS);
    setXY(x, y, x+sx-1, y);
    for (int tc=0; tc<sx; tc++)
    {
        char* p = (char*)&data[tc];
        LCD_Write_DATA(*(p + 1), *p);
    }
    sbi(P_CS, B_CS);
}
void UTFT::setXY(word x1, word y1, word x2, word y2)
{
    if (orient==LANDSCAPE)
    {
        swap(word, x1, y1);
        swap(word, x2, y2)
        y1=disp_y_size-y1;
        y2=disp_y_size-y2;
        swap(word, y1, y2)
    }
        LCD_Write_COM(0x2a);
        LCD_Write_DATA(x1>>8);
        LCD_Write_DATA(x1);
        LCD_Write_DATA(x2>>8);
        LCD_Write_DATA(x2);
        LCD_Write_COM(0x2b);
        LCD_Write_DATA(y1>>8);
        LCD_Write_DATA(y1);
        LCD_Write_DATA(y2>>8);
        LCD_Write_DATA(y2);
        LCD_Write_COM(0x2c);                             
}

My current rendering:

current result

Desired image:

enter image description here

TFT Lcd and Mega Board enter image description here

UPDATE1

I ran henningan test from utft library, drawing sin/cos graph and simple squares

enter image description here

Here is attempt to render yellow square 100x100 raw data

enter image description here

\$\endgroup\$
4
+50
\$\begingroup\$

Looking at the SetXY function, it seems the controller might be ILI9341. Here's a datasheet for that controller: http://www.newhavendisplay.com/app_notes/ILI9341.pdf.

There's two points that strike me at this time; hopefully as new information becomes available, I can extend the answer.

First of all, are the definitions for SCREEN_WIDTH, and SCREEN_HEIGHT correct? It looks to me like they might not be.

Secondly, what pixel data format, e.g. how many bits per pixel, do you set for the LCD. Usually these kinds of LCDs accept data in formats such as RGB565 (16 bits per pixel), BGR233 (8 bits per pixel) or RGB666 (18 bits per pixel). The code for DrawPixelLine suggests that the data is 8 bits per pixel; in my experience this is quite rare, although the striking thing in your image is that the colors seem to be correct. Having the wrong pixel format would explain a lot.

It's rather odd that there seem to be two different entities for the screen height: SCREEN_HEIGHT and disp_y_size. Are you sure both are correct?


Edit: Based on the ILI9341 datasheet; that controller doesn't support 8-bit pixel depth. Also you declare your data buffer to be of type u_int16. However, in the line draw function, that buffer is cast into an array of char. And I think that in the Arduino (AVR), a char is 8 a bits data type. This would cause incorrect indexing to your data buffer.

\$\endgroup\$
1
\$\begingroup\$

Your controller is a ILI9481 Ver.2.0. If you detach TFT PCB and read the sheet you will find the information you need. Try these settings from the ILI9481 controller code located in the library UTFT \ ... \ ... \ ILI9481 \ initlcd.h

code: initlcd.h

case ILI9481:  //ver.2.0
LCD_Write_COM(0x11);   //0x11
delay(20);
LCD_Write_COM(0xD0);   //(0xD0)
LCD_Write_DATA(0x07);  //(0x07)
LCD_Write_DATA(0x41);  //(0x42)
LCD_Write_DATA(0x1D);  //(0x1B)

LCD_Write_COM(0xD1);   //(0xD1)
LCD_Write_DATA(0x00);  //(0x00)
LCD_Write_DATA(0x2B);  //(0x07)
LCD_Write_DATA(0x1F);  //(0x10)

LCD_Write_COM(0xD2);   //(0xD2)
LCD_Write_DATA(0x01);  //(0x01)
LCD_Write_DATA(0x11);  //(0x02)

LCD_Write_COM(0xC0);   //(0xC0) //Panel Driving Setting / Set Default Gamma
LCD_Write_DATA(0x00);  //(0x10)
LCD_Write_DATA(0x3B);  //(0x3B)
LCD_Write_DATA(0x00);  //(0x00)
LCD_Write_DATA(0x02);  //(0x02)
LCD_Write_DATA(0x11);  //(0x11)

//Display_Timing_Setting for Normal Mode
    LCD_Write_COM(0xC1);    //
LCD_Write_DATA(0x10);   //Line inversion,DIV1[1:0]
LCD_Write_DATA(0x10);   //RTN1[4:0]
LCD_Write_DATA(0x88);   //BP and FP 


LCD_Write_COM(0xC5);    //(0xC5) //Frame Rate Control / Set frame rate
LCD_Write_DATA(0x03);   //(0x03)

LCD_Write_COM(0xB6);    // Display Function Control
LCD_Write_DATA(0x00);
LCD_Write_DATA(0x22);   // 0x42 = Rotate display 180 deg.
LCD_Write_DATA(0x3B);


LCD_Write_COM(0xC8);   //(0xC8) //Gamma Setting / Set Gamma
LCD_Write_DATA(0x00);  //(0x18)
LCD_Write_DATA(0x14);  //(0x32)
LCD_Write_DATA(0x33);  //(0x36)
LCD_Write_DATA(0x10);  //(0x45)
LCD_Write_DATA(0x00);  //(0x06)
LCD_Write_DATA(0x16);  //(0x18)
LCD_Write_DATA(0x44);  //(0x37)
LCD_Write_DATA(0x36);  //(0x75)
LCD_Write_DATA(0x77);  //(0x77)
LCD_Write_DATA(0x00);  //(0x54)
LCD_Write_DATA(0x0F);  //(0x0C)
LCD_Write_DATA(0x00);  //(0x00)

    LCD_Write_COM(0x21);   // Display Inversion ON 0x21 / 0x20 inversion OFF
LCD_Write_DATA(0xC8);  // C8     

    LCD_Write_COM(0xE4);   // 
LCD_Write_DATA(0xA0);  // 

    LCD_Write_COM(0xF0);   // 
LCD_Write_DATA(0x01);  //

//======RGB IF setting========
//RGB OR SYS INTERFACE
    LCD_Write_COM(0xB4);
LCD_Write_DATA(0x10);  //RGB / BGR

    LCD_Write_COM(0xC6);
LCD_Write_DATA(0x1B);
//============================ 


LCD_Write_COM(0x36);   //(0x36) //set_address_mode MIROR IMAGE LENDSCAPE
LCD_Write_DATA(0x0D);  //(0x0D) //MIROR AND ORIENTATION IMAGE 0x0C change ORIENTATION 
//Page Address Order:Top to Bottom,Column Address Order:Right to Left,Page/Column Order:Normal Mode,Line Address Order:LCD Refresh Top to Bottom

LCD_Write_COM(0x3A);   //(0x3A) //set_pixel_format
LCD_Write_DATA(0x55);  //(0x55) //DBI:16bit/pixel (65,536 colors)

LCD_Write_COM(0x2A);   //(0x2A) //set_column_address
LCD_Write_DATA(0x00);  //(0x00)
LCD_Write_DATA(0x00);  //(0x00)
LCD_Write_DATA(0x01);  //(0x)1)
LCD_Write_DATA(0x3F);  //(0x3F)

LCD_Write_COM(0x2B);   //(0x2B) //set_page_address
LCD_Write_DATA(0x00);  //(0x00)
LCD_Write_DATA(0x00);  //(0x00)
LCD_Write_DATA(0x01);  //(0x01)
LCD_Write_DATA(0xE0);  //(0xE0)

LCD_Write_COM(0x13);   //(0x13) //NORMAL DISPLAY 

    delay(120);
LCD_Write_COM(0x29);   //(0x29) //set_display_on / display on
break;
\$\endgroup\$
-1
\$\begingroup\$

I had the same problem. The solution is:

Change in ILI9841 intlcd.h:

LCD_Write_COM(0x36);
LCD_Write_DATA(0x0A);

TO

LCD_Write_COM(0x36);
LCD_Write_DATA(0x4A);
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.