lcd ili9341

I have lcd ili9341 3.2inch SPI Module ILI9341 SKU:MSP3218 - LCD wiki

i need to display Arabic character can anyone try this ?

// IMPORTANT: LCDWIKI_SPI LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.

//This program is a demo of displaying string

//when using the BREAKOUT BOARD only and using these hardware spi lines to the LCD,
//the SDA pin and SCK pin is defined by the system and can't be modified.
//if you don't need to control the LED pin,you can set it to 3.3V and set the pin definition to -1.
//other pins can be defined by youself,for example
//pin usage as follow:
//                  CS  DC/RS  RESET  SDI/MOSI  SDO/MISO  SCK  LED    VCC     GND
//Arduino Mega2560  A5   A3     A4      51        50      52   A0   5V/3.3V   GND

//Remember to set the pins to suit your display module!

/***********************************************************************************
 @attention

 THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
 WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
 TIME. AS A RESULT, QD electronic SHALL NOT BE HELD LIABLE FOR ANY
 DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
 FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
 CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
**********************************************************************************/

#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_SPI.h> //Hardware-specific library

//paramters define
#define MODEL ILI9341
#define CS   A5
#define CD   A3
#define RST  A4
#define LED  A0   //if you don't need to control the LED pin,you should set it to -1 and set it to 3.3V

//the definiens of hardware spi mode as follow:
//if the IC model is known or the modules is unreadable,you can use this constructed function
LCDWIKI_SPI mylcd(MODEL, CS, CD, RST, LED); //model,cs,dc,reset,led
//if the IC model is not known and the modules is readable,you can use this constructed function
//LCDWIKI_SPI mylcd(240,320,CS,CD,RST,LED); //model,cs,dc,reset,led

//define some colour values
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF




void setup()
{
 mylcd.Init_LCD();
 mylcd.Fill_Screen(RED);

}

void loop()
{
 mylcd.Set_Text_Mode(0);



 mylcd.Set_Text_colour(WHITE);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("E", 30, 150);

 mylcd.Set_Text_colour(BLUE);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("l", 55, 150);

 mylcd.Set_Text_colour(GREEN);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("w", 80, 150);

 mylcd.Set_Text_colour(CYAN);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("a", 110, 150);

 mylcd.Set_Text_colour(MAGENTA);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("l", 135, 150);

 mylcd.Set_Text_colour(YELLOW);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("y", 160, 150);

 mylcd.Set_Text_colour(BLACK);
 mylcd.Set_Text_Size(5);
 mylcd.Print_String("!", 190, 150);

 delay(500);
}

i don't have a problem to display this word "Elwaly" with English but i need to replace it with "الوالي"

Do you have to use LCDWIKI ?

Life is much easier with GFX style libraries e.g. Adafruit_ILI9341

#include <Adafruit_ILI9341.h>

Adafruit_ILI9341 tft(10, 9, 8); //CS, DC, RST

#include <U8g2_for_Adafruit_GFX.h>
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;

#define TFT_BLACK 0x0000
#define TFT_WHITE 0xFFFF

void setup()
{
    tft.begin();
    u8g2_for_adafruit_gfx.begin(tft);                 // connect u8g2 procedures to Adafruit GFX
    u8g2_for_adafruit_gfx.setFontDirection(0);       // left to right
    if (tft.width() < tft.height()) tft.setRotation(1);
    u8g2_for_adafruit_gfx.setFontMode(0);                 // use u8g2 transparent mode (this is default)
    u8g2_for_adafruit_gfx.setForegroundColor(TFT_WHITE);  // apply Adafruit GFX color
    u8g2_for_adafruit_gfx.setBackgroundColor(TFT_BLACK);  // apply Adafruit GFX color
}

char perfect[] = "الإنكليزية مثالية.";
char mycow[] = "لقد بقيت البقرة";
char hercalf[] = "العجل لها هو البقرة";
char ahmadelwaly[] = "الوالي";


void UTF8_rt_lft(int x, int y, const char *u8str)
{
    char buf[5], c, n;
    while (c = *u8str) {
        switch (c & 0xF0) {   //escape sequences
            case 0xC0: n = 2; break;
            case 0xD0: n = 2; break;
            case 0xE0: n = 3; break;
            case 0xF0: n = 4; break;
            default: n = 1; break;
        }
        memcpy(buf, u8str, n); //copy one glyph at a time
        buf[n] = 0;   //terminate with NUL
        u8str += n;
        uint8_t len = u8g2_for_adafruit_gfx.getUTF8Width(buf);
        x -= len;     //calc new posn for glyph
        u8g2_for_adafruit_gfx.drawUTF8(x, y, buf);
    }

}

void showmsgs(const uint8_t *font, int x, int y)
{
    u8g2_for_adafruit_gfx.setFont(font);  // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
    //u8g2_for_adafruit_gfx.drawUTF8(0, y += 20, mycow);
    //u8g2_for_adafruit_gfx.drawUTF8(0, y += 20, hercalf);
    UTF8_rt_lft(x, y += 20, perfect);
    UTF8_rt_lft(x, y += 20, mycow);
    UTF8_rt_lft(x, y += 20, hercalf);
    UTF8_rt_lft(x, y += 20, ahmadelwaly);
}

void loop()
{
    int x = tft.width();                                // write from right
    tft.fillScreen(TFT_BLACK);
    showmsgs(u8g2_font_cu12_t_arabic, x, 0);
#ifndef AVR
    showmsgs(u8g2_font_10x20_t_arabic, x, 80);
    showmsgs(u8g2_font_unifont_t_arabic, x, 160);
#endif
    delay(2000);
}

David.

I'm using this display with Rinky-Dink's library (UTFT + URTOUCH)
and i didnt see any other languages in the website.

if you dont have many words to display i'd suggust just creating images and displaying them
not a very hard thing to do.

thanks david , but error compiling for arduino mega board

but error compiling for arduino mega board

So post the error and we may be able to help. Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

I built on a 3.3V Uno:

Using library Adafruit_ILI9341 at version 1.5.5 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_ILI9341 
Using library Adafruit_GFX_Library at version 1.7.5 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.12\hardware\arduino\avr\libraries\SPI 
Using library U8g2_for_Adafruit_GFX at version 1.7.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\U8g2_for_Adafruit_GFX 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_779337/Hello_Arabic.ino.elf"
Sketch uses 21680 bytes (67%) of program storage space. Maximum is 32256 bytes.
Global variables use 308 bytes (15%) of dynamic memory, leaving 1740 bytes for local variables. Maximum is 2048 bytes.

Please compare my library version numbers with your IDE Library Manager

I will update my Adafruit libraries. Adafruit are always changing them.

David.

Edit. With updated libraries:

Using library Adafruit_ILI9341 at version 1.5.5 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_ILI9341 
Using library Adafruit_GFX_Library at version 1.8.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.12\hardware\arduino\avr\libraries\SPI 
Using library U8g2_for_Adafruit_GFX at version 1.7.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\U8g2_for_Adafruit_GFX 
Using library Adafruit_BusIO at version 1.3.2 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.12\hardware\arduino\avr\libraries\Wire 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_779337/Hello_Arabic.ino.elf"
Sketch uses 22426 bytes (69%) of program storage space. Maximum is 32256 bytes.
Global variables use 415 bytes (20%) of dynamic memory, leaving 1633 bytes for local variables. Maximum is 2048 bytes.

it works good but the alphabets Separated " أ ل و ا ل ي " like this . and i need it like this " الوالي "

I built on a Uno which has limited Flash memory. You can afford to try two more fonts on your Mega2560

    showmsgs(u8g2_font_10x20_t_arabic, x, 80);
    showmsgs(u8g2_font_unifont_t_arabic, x, 160);

You will need to change the print positions. Or just remove my "other" messages.

If you are unhappy with all the fonts you will have to write your own.

David.

You give to me the line that i will follow, Thanks David.

Do you have any idea how to use arduino-persian-reshaper Library to reshape the text

There must be hundreds of Arabic fonts available in Arabic speaking countries.
Obviously not so many in Western Europe.

If there is a Font that you like, post a link. Someone might add it to the U8g2 fonts.

Most languages write from left to right. Individual letters are distinct from each other.
It is easy to render individual letters. Not so easy to modify strokes to join up with the next letter.

I wrote the UTF8_rt_lft() function. You could improve it. e.g. by checking for adjacent letters that need kerning.

David.

Thanks david for your replay , i saw this on GitHub - idreamsi/arduino-persian-reshaper: Simple Reconstruct Persian/Arabic letters for use in the Arduino IDE and OLED/LCD display with a 8x8 font and try to adjust it with ili9341 but i can't

ahmadelwaly:
Thanks david for your replay , i saw this on GitHub - idreamsi/arduino-persian-reshaper: Simple Reconstruct Persian/Arabic letters for use in the Arduino IDE and OLED/LCD display with a 8x8 font and try to adjust it with ili9341 but i can't

I ran that sketch on the 128x64 SSD1306. It looks horrible. I could run it on ILI9341 but it would still look bad.

It is difficult to make attractive text with an 8x8 font. At least you have more pixels to play with on the ILI9341.

I presume that you have always had traditional mechanical typewriters. These have a fixed number of letters and tend to have equal spacing between letters.

I presume that Arabic newspapers were typeset with special hot-metal machines before computers were common.

Computer Word Processors give much more flexibility for "setting" each letter. And can hold a large number of letters. e.g. special combinations. In English "ae" is sometimes typeset as a single special letter.

Be realistic. A Uno and a 240x320 screen is limited for Font storage and Font rendering. You have to make compromises.

David.

Hello ,, how i can display this variable

const uint16_t my_kerning_table[] = {
	/* first char, second char, gap reduction value */
	0x646, 0x627, 4, /* ن and ا */
	0x627, 0x647, 5, /* ا and ه */
	0x647, 0x62C, 6, /* ه and ج */
	0x645, 0x627, 3, /* م and ا */
	0x627, 0x644, 4, /* ا and ل */
	0x644, 0x633, 2, /* ل and س */

	/* this line terminates the table */
	0xffff, 0xffff, 0xffff
};

in this function UTF8_rt_lft(x, y += 30, my_kerning_table);

I know nothing about Arabic letters. I just used the Arabic font to calculate each letter width and then display right-to-left.

Yes, you could check for adjacent letters. Adjust the kerning.

If you give me some example text, I can adjust the spacing. e.g.
example with correct spacing.
example with wrong spacing.

Please understand that Arabic is worse than Double-Dutch (for me)

David.

Example with correct spacing " اهلا بكم في العالم "
Example with wrong spacing " ا ه ل ا ب ك م ف ي ال ع ال م "

Example with correct spacing " احمد خالد الوالي "
Example with wrong spacing " اح م د خ ا ل د ال و ال ي "

Thanks david for your help

The problem solved :smiley: :smiley:

I put your correct and wrong examples into Google Translate. They had two different messages.

e.g. " احمد خالد الوالي "
" اح م د خ ا ل د ال و ال ي "

translated as

Ahmed Khaled Al-Wali
"The one who is the father of God and the One"

Anyway, I wrote a function that applied a kerning correction when it found two special adjacent letters.
Depending on which of the three Arabic fonts was used, the kerning was too severe for the first font.

But it seems that you don't want kerning but replace some letters with narrower versions. e.g. J becomes |
i.e. you lose the long Elephant's trunk.

How did you "solve" your problem. Please post your solution.

David.

Arabic Presentation Forms-B — Unicode Character Table , I used this unicode , if the letters in the middle has a different code of the letters in the first or the end of the words so i choose the unicode depends on the the position of the letters

"أحمد خالد الوالي " char Ahmed[] = "\u2000\u2000\uFE83\uFEA3\uFEE3\uFEAA\u2000\uFEA7\u0627\uFEDF\uFEAA\u2000\u0627\uFEDF\u0648\u0627\uFEDF\uFEF2";