Lib for the new LCD Display with ILI9341 controller

Dependents:   TFT_Test_ILI9341 touch_piirto TFT_banggood TFT_Test_ILI9341-a-fish ... more

You are viewing an older revision! See the latest version

Homepage

Table of Contents

    Lib for 320*240 Pixel LCD with ILI9341 controller. Based on MI0283QT-9 datasheet.

    The lib is using the 4 line serial data interface. The IM pins have to be set to 1110 (IM3-IM0) to use this mode.

    If you use the TFT Proto from MikroElektronika http://www.mikroe.com/eng/products/view/474/tft-proto-board/ you have to connect :

    MBEDDisplay
    + 3,3V3,3V
    GNDGND
    mosiSDI
    misoSDO
    sckRS
    csCS
    resetRST
    dcWR/SCL
    GNDIM0
    +3,3VIM1 IM2 IM3
    GNDDB0 - DB17
    GNDRD

    The backlite LED need a resistor to limit the current. You can use two 10R resistors parallel to get 5R driven by 3.3V.

    Watterott is also selling a ILI9341 based QVGA TFT : http://www.watterott.com/de/MI0283QT-2-Adapter

    Unfortunately this adapter is set to 9 bit SPI mode via the mode pins IM0-IM3. If you want to patch this - like I have done - you have to desolder the TFT from the pcb to cut some traces. This is a flexible print. Only for people with soldering skills ! You also have to get access to pin 36 for the dc signal. Cut the GND connection. You can use the level converter used for the LCD_LED signal. Mosfet Q1 can be driven with a logic signal without converter. Watterott will change this in a future revision.

    How to get nice looking fonts ?

    To print characters to a graphic screen we need a font. To code a font by paper is ok for a small lcd, but for a 320*240 pixel display we need bigger fonts. A 12*12 pixel font is readable, but a lot of work to construct.

    Fonts can be made with the GLCD Font Creator also from http://www.mikroe.com .

    With this program you can load a window font and convert it into a c-array. To use this Font with my lib you have to add 4 parameter at the beginning of the font array. - the number of byte / char - the vertial size in pixel - the horizontal size in pixel - the number of byte per vertical line (it is vertical size / 8 ) You also have to change the array to char[]. After that you can switch between different fonts with set_font(unsigned char* font); The horizontal size of each character is also stored in the font. It look better if you use bigger fonts or italic. The letter M is wider than a l.

    Here are some Fonts from me : http://mbed.org/users/dreschpe/code/TFT_fonts/

    The small made for the mbed lab board : http://mbed.org/users/dreschpe/code/LCD_fonts/

    And from Peter Holzleitner : http://mbed.org/users/pholzleitner/code/SourceCodePro31-SB/

    Text commands :

    You can use the claim() function to redirect the output to stdout or stderr to the TFT. After claim(stdout) you can simply use the printf function to print to the TFT.

    • locate(x,y); function is used to setup the cursor position. x,y are the pixel position. This was changed from row,column in older lib !

    There are two parameter to setup the color of the text :

    • background(color);
    • foreground(color); All color are 16bit: R5 G6 B5.
    • set_orientation(); This command select one of the 4 directions to use the display. This command is also working on the graphical commands.

    Graphic commands :

    • cls(); Fill the screen with background color
    • pixel(x,y,color); set a single pixel at x,y with color
    • line(x0,y0,x1,y1,color); draw a line from x0,y0 to x1,y1 with color
    • rect(x0,y0,x1,y1,color); draw a rectangle x0,y0 to x1,y1 with color
    • fillrect(x0,y0,x1,y1,color); draw a filled rectangle
    • circle( x0,y0,radius ,color); draw a circle around x0,y0 with radius
    • fillcircle(x0,y0,radius ,color); draw a filled circle around x0,y0 with radius
    • Bitmap(x0,y0,w,h,*bitmap); paint a bitmap with width w and high h starting at x0,y0 (upper left corner)
    • BMP_16(x0,y0,*bmp); paint a bmp file out of the internal drive

    How to transfer a grafic to the mbed ?

    The hard way - but fast to load :

    Load from mbed flash. To construct a bitmap array we can use gimp. http://www.gimp.org/ Load a image (edit and resize) and save it as BMP. You have to select the option 16 bit R5 G6 B5 !

    To convert this file into a c-array you can use the hex-editor winhex. (http://www.x-ways.net/winhex/index-m.html) The eval version can handle the small files. We don`t need the bmp header. Mark the data starting at offset 0x46 to the end of file. Use "edit -> copy block -> C Source" to export this data as C array. Paste the data into a C file into the mbed compiler. The editor will generate a array of char[]. To use 16 bit DMA on this we have to put a __align(2) in front of the definition. To put it into Flash we change it to static const unsigned char bmp[]{...}

    __align(2)
    static const unsigned char bmp[]{
          0xCB, 0x5A, 0x5C, 0xE7,....
    
    };
    

    The easy way - but slower to load:

    With the BMP_16 command we can load a picture out of the internal drive to the display.

    • BMP_16(x0,y0,"test.bmp"); paint test.bmp out of the internal drive to x0, y0

    simply copy test.bmp to mbed usb drive - saved with the options 16 bit R5 G6 B5 and load it.


    All wikipages