Introduction: Arduino TFT Display and Font Library

Picture of Arduino TFT Display and Font Library

I am quite a fan of the Arduino as there is so much software already available on the internet, this makes completing new projects easier!

Recently I bought a few cheap 1.8" TFT displays for a project, initially I could not get them working which was frustrating. Eventually I found that the ones I had bought used the Samsung S6D02A1 driver chip and I had been trying to use the wrong library.

After a brief search on the web I came across the Adafruit_QDTech library which worked really well. This library is used in conjunction with the Adafruit_GFX library. After trying some examples I was a little disappointed that only scaled blocky fonts were available - so I have modified the original libraries to add some new fonts and functions.

Update 2/2/2015:

I have now added a driver library below for the 2.2" TFT QVGA 240x320 pixel display with the ILI9341 driver. This has examples included.

Update 3/2/2015:

I have now added a driver library for the 1.8" TFT display based on the ST7735 driver along with examples.

Update 14/6/2015:

I have added a new library for the 2.2" TFT QVGA 240x320 pixel display with the ILI9341 driver. This library is called TFT_ILI9341 and is a stand alone library that does not need the support of another GFX library. Compatibility with the Adafruit GFX library has been maintained. See Step 8 of this Instructable.

Step 1: Wiring It Up

I used the Arduino UNO and linked it to the 1.8" S6D02A1 based display as follows:

  • UNO +5V to display pin 6 (VCC) and pin 7 (BL)
  • UNO 0V (GND) to display pin 8 (GND)
  • UNO digital pin 7 through a 1K2 resistor to display pin 1 (RST)
  • UNO digital pin 8 through a 1K2 resistor to display pin 3 (D/C)
  • UNO digital pin 9 through a 1K2 resistor to display pin 2 (CS)
  • UNO digital pin 11 through a 1K2 resistor to display pin 4 (DIN)
  • UNO digital pin 13 through a 1K2 resistor to display pin 5 (CLK)

The 1K2 resistors are required to protect the display being damaged by the 5V logic levels from the UNO, these limit the current flow. Ideally we could use a level shifter but the resistors work fine.

Update 2/2/2015

You can also now use the 2.2" QVGA TFT SPI display based on the ILI9341 driver. To use this display load the Adatfruit_IL9341_AS and Adafruit_GFX_AS libraries. Connect the display to the UNO as follows:

    • UNO +5V to display pin 1 (VCC)
    • UNO +5V through a 56 Ohm resistor to display pin 8 (LED)
    • UNO 0V (GND) to display pin 2 (GND)
    • UNO digital pin 7 through a 1K2 resistor to display pin 4 (RESET), add a 1K8 resistor from display pin 4 to GND
    • UNO digital pin 8 through a 1K2 resistor to display pin 5 (DC/RS), add a 1K8 resistor from display pin 5 to GND
    • UNO digital pin 9 through a 1K2 resistor to display pin 3 (CS), add a 1K8 resistor from display pin 3 to GND
    • UNO digital pin 11 through a 1K2 resistor to display pin 6 (SDI/MOSI), add a 1K8 resistor from display pin 6 to GND
    • UNO digital pin 13 through a 1K2 resistor to display pin 7 (SCK), add a 1K8 resistor from display pin 7 to GND

    It is important to include the 1K8 resistors to GND with this 2.2" display as otherwise it will not work. The 1K2 and 1K8 resistors are a "potential divider", acting as a logic level shifter so that the logic level at the display is reduced from 5V to around 3V. Pin 9 of the display does not need to be connected up.

    Some displays of this type do not have a LED series resistor built in so the 56 Ohm value above is needed to limit the LED current to about 50mA.

    Update 3/2/2015

    The 1.8" 128x160 pixel display based on the ST7735 driver is now also supported. To use this display load the Adafruit_ST7735_AS and Adafruit_GFX_AS libraries. Connect the UNO to the display as follows:

    • UNO +5V to display pin 1 (VCC) and pin 8 (LED)
    • UNO 0V (GND) to display pin 2 (GND)
    • UNO digital pin 7 through a 1K2 resistor to display pin 4 (RESET)
    • UNO digital pin 8 through a 1K2 resistor to display pin 5 (AO)
    • UNO digital pin 9 through a 1K2 resistor to display pin 3 (CS)
    • UNO digital pin 11 through a 1K2 resistor to display pin 6 (SDI)
    • UNO digital pin 13 through a 1K2 resistor to display pin 7 (SCK)

    Step 2: Loading the Libraries (updated 3/2/15)

    I have modified the Adafruit libraries and added the fonts. The fonts will be stored in FLASH so will use up some program space however a reasonable amount of space is still available, if you run out then use an Arduino Mega board.

    I am actually a hardware designer so the software updates could probably be improved, but they are working!

    The zip file contains the two libraries you will need. These have have new names (_AS appended) so they will coexist with any libraries you already have. There are 3 example programs included in the Adafruit_QDTech_AS library.

    I updated the libraries to version 5 on 2/2/2015, now individual fonts can be disabled to save FLASH memory if they are not all needed. To prevent particular font files being loaded simply edit the "Load_fonts.h" file within the "Adafruit_GFX_AS" library folder. Just comment out the fonts not needed by adding // to the beginning of the respective line. Also, in response to a question from a reader below, I have made the proportional fonts scalable just like the original simple Adafruit, this makes the fonts more blocky but providing the scale factor is not more than 2 the fonts still look reasonable. In the example TFT_Show_Font_ILI9341 I use the commands:

    tft.setTextSize(1); // For normal sized fonts

    tft.setTextSize(2); // For double sized fonts

    Other minor tweaks have been made so that the font background will be drawn as per original Adafruit font. The font drawing speed has also been improved. Minor tweaks have been made to the fonts, Font 4 has been reduced in height slightly to remove superfluous "whitespace" and a full stop "." has been added to the characters available in the large font 6.

    Minor tweaks to the fonts have been made and new example sketches have been added to show all font characters.

    Step 3: Example Programs

    Picture of Example Programs

    The example programs are:

    • TFT_Rainbow - gives some examples of drawing the fonts on the display
    • TFT_Clock - an analogue clock drawn with the standard Adafruit graphics routines plus a centred line of text in Font 4
    • TFT_Clock_Digital - a digital clock using the 7 segment display font and other font drawing examples.
    • TFT_Show_Font - draws the different fonts and characters on the screen

    Step 4: Library Functions and Fonts

    Here are the library functions that can be called:

    • int drawUnicode(unsigned int uniCode, int x, int y, int size);
    • int drawNumber(long long_num,int poX, int poY, int size);
    • int drawChar(char c, int x, int y, int size);
    • int drawString(char *string, int poX, int poY, int size);
    • int drawCentreString(char *string, int dX, int poY, int size);
    • int drawRightString(char *string, int dX, int poY, int size);
    • int drawFloat(float floatNumber,int decimal,int poX, int poY, int size);

    In summary, the X and Y parameters are the coordinates for the drawing.

    Each function returns the X position delta to the end of the printed characters.

    "size" is the font size:

    • Only font numbers 2,4,6,7 are valid
    • Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 - . : a p m
    • Font 7 is a 7 segment font and only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : .

    The fonts are proportionally spaced to give an improved appearance.

    The routine for floating point numbers uses a parameter "decimal" which defines the number of decimal places to show, this aids formatting and displaying sensor readings, the number is rounded, so for example if decimal = 3, then 3.14159 will display as 3.142 and 3.14 will display as 3.140

    drawCentreString will centre the string around the x position. convenient for tidy display formatting

    drawRightString will draw the string right justified to the x position, useful for labels that are followed by sensor readings printed afterwards.

    Update 2/2/2015:

    Added new library "Adafruit_ILI9341_AS" so a 2.2" TFT 240x320 pixel display can also be used.

    All fonts can now be scaled:

    tft.setTextSize(1); // For normal sized fonts
    tft.setTextSize(2); // For double sized fonts

    Also:

    drawUnicode(unsigned int uniCode, int x, int y, int size)

    is no longer in the latest libraries, please use:

    drawChar(char c, int x, int y, int size)

    instead.

    Step 5: Have Fun!

    Picture of Have Fun!

    I hope you find this Instructable useful!

    P.S. I am am not connected with Adafruit, but do check out their great products and look for the support on using the standard graphics library functions (these remain within the adapted libraries).

    Step 6: Requests...

    Here we have some responses to requests:

    1. A replacement Font32.c file with the Grave accent being drawn as a degree symbol.

    2. A Sketch that has a function to wrap text to next line or back to the top.

    A faster drawing ILI9341 library to try with any ATmega328 based Arduino can be found attached to my Instructable here.

    Step 7: Displaying Images Stored on an SD Card

    Picture of Displaying Images Stored on an SD Card

    I have now created a new Instructable for drawing bitmap image files stored on an SD Card on the display:

    https://www.instructables.com/id/Arduino-TFT-displa...

    This is compatible with the ILI9341 driver based TFT boards.

    Step 8: New Fast Library for the ILI9341 Based TFT Display With Run Length Encoded Fonts

    This new library is a standalone library that contains the TFT driver as well as the graphics functions and fonts that were in the GFX library. This library has significant performance improvements when used with an UNO (or ATmega328 based Arduino) and MEGA.

    Examples are included with the library, including graphics test programs. The example sketch TFT_Rainbow_one shows different ways of using the font support functions. This library now supports the "print" library so the formatting features of the "print" library can be used, for example to print to the TFT in Hexadecimal, for example:

    tft.println(57005, HEX);

    The larger fonts are now Run Length Encoded (RLE) so that they occupy less FLASH space, this frees up space for the rest of the sketch. A byproduct of the RLE approach is that the font drawing is also speeded up so it is a win-win situation.

    A new 72 point large Font 8 has been added that contains [space]1234567890:. characters.

    To use the F_AS_T performance option the ILI9341 based display must be connected to an UNO as follows:

    • UNO +5V to display pin 1 (VCC) and pin 8 (LED)
    • UNO 0V (GND) to display pin 2 (GND)
    • UNO digital pin 7 through a 1K2 resistor to display pin 4 (RESET), add a 1K8 resistor from display pin 4 to GND
    • UNO digital pin 9 through a 1K2 resistor to display pin 5 (DC/RS), add a 1K8 resistor from display pin 5 to GND
    • UNO digital pin 10 through a 1K2 resistor to display pin 3 (CS), add a 1K8 resistor from display pin 3 to GND
    • UNO digital pin 11 through a 1K2 resistor to display pin 6 (SDI/MOSI), add a 1K8 resistor from display pin 6 to GND
    • UNO digital pin 13 through a 1K2 resistor to display pin 7 (SCK), add a 1K8 resistor from display pin 7 to GND

    When using an UNO the CS line must be connected to pin 10 and DC line to pin 9, this is because the optimised code uses direct port access.

    When using the UNO comment out the MEGA_TFT_ILI9341 #define in the library Run_faster.h file.

    This library only supports hardware SPI, so pins 11 and 13 on the UNO must be used as listed above.

    To use the F_AS_T performance option the ILI9341 based display must be connected to an MEGA as follows:

    • MEGA +5V to display pin 1 (VCC) and pin 8 (LED) UNO 0V (GND) to display pin 2 (GND)
    • MEGA digital pin 44 through a 1K2 resistor to display pin 4 (RESET), add a 1K8 resistor from display pin 4 to GND
    • MEGA digital pin 48 through a 1K2 resistor to display pin 5 (DC/RS), add a 1K8 resistor from display pin 5 to GND
    • MEGA digital pin 47 through a 1K2 resistor to display pin 3 (CS), add a 1K8 resistor from display pin 3 to GND
    • MEGA digital pin 51 through a 1K2 resistor to display pin 6 (SDI/MOSI), add a 1K8 resistor from display pin 6 to GND
    • MEGA digital pin 52 through a 1K2 resistor to display pin 7 (SCK), add a 1K8 resistor from display pin 7 to GND

    When using a MEGA the CS line must be connected to pin 47 and DC line to pin 48, this is because the optimised code uses direct port access.

    When using the MEGA ensure the MEGA_TFT_ILI9341 #define in the library Run_faster.h file in not commented out.

    This library only supports hardware SPI, so pins 51 and 52 on the MEGA must be used as listed above.

    In the library Font 0 (GLCD font), 2, 4, 6 and 8 are enabled. Edit the Load_fonts.h file within the library folder to enable/disable fonts to save space.

    Remember: disabling fonts saves FLASH space, and disabling them means they cannot be displayed!

    TFT_ILI9341 library updated on 1st July 2015 to version 12, this latest version is attached here to step 8:

    1. Minor bug when rendering letter 'T' in font 4 without background fixed
    2. RLE fonts are now rendered without overlap (improves rendering speed and stops flicker of adjacent character)

    Step 9: TFT_ILI9341 Library Updated 31/7/15

    TFT_ILI9341 library has been updated to version 14 beta, this latest version is attached below.

    1. Text algnment, the datum for drawing strings and numbers can be changed with a new function: tft.setTextDatum(datum); See example sketch included "TFT_String_Align"

    2. Performance improvements, in particular line drawing is much faster now (thanks Spellbuilder)

    3. There is a new "User_Setup.h" file inside the library where all the settings can be controlled, eg. pins used for the TFT interface and the fonts loaded. See the comments in the header file. The pins are defined in this header so to invoke the custom library the pin references must be removed from legacy sketches so it reads: TFT_ILI9341 tft = TFT_ILI9341(); // Invoke custom library

    4. The FastPin.h header has been adopted from the FastLED library, this allows any control pins to be used for CS, DC and RST whilst still getting the best pin toggle performance (thanks Marstom)

    This v14b is a beta version as there is a minor bug in the drawFloat() function that I need to fix!

    This library has been developed for my own hobby use. If you do find a problem with it then please report bugs here. TTFN

    Step 10: TFT_ILI9341 Library Now on Github

    Picture of TFT_ILI9341 Library Now on Github

    As I have been making minor tweaks to the ILI9341 library (and because it has proved to be popular!) I have put the TFT_ILI9341 library on Github. You can down load the latest here:

    https://github.com/Bodmer/TFT_ILI9341

    Using the Download Zip button is probably the easiest method if you do not have a GitHub client loaded.

    A request has been posted to the Arduino team to have it listed in the IDE Library Manager.

    Typically performance is 3 times faster than the standard Adafruit GFX library (see table for speed comparison) and up to 20 times faster than UTFT. So the graphics drawing performance is now about as good as it is going to get on a humble UNO/AVR Arduino!

    Full 320 x 240 screens are cleared in 174ms, raw image files can be pulled off an SD Card and drawn in 400ms using the tweaked version of the SdFat library here:

    https://github.com/Bodmer/TFT_SdFat

    I have also created a touch screen library for the 2.4" ILI9341 TFT display fitted with the XPT2046 touch controller. The touch library can be downloaded here:

    https://github.com/Bodmer/TFT_Touch

    I will be creating a more comprehensive instructable at a future date to document all the font and formatting features of the graphics library.

    Step 11: Update: June 2016 - More Libraries on GitHub

    I have improved the performance of the ST7735 and S6D02A1 libraries. Copies are available here:

    TFT_ST7735 library.

    and here:

    TFT_S6D02A1 library.

    Comments

    Rolo664u (author)2015-07-06

    Hi, nice job ! I have it running now on an UNO now with a 2,2 inch display. Never had a library before that fitted in the UNO and had such nice characters !

    I'm now trying to port it to a STM Nucleo board where I have loads of Flash available. In the code I see fonts 1,3, and 5 mentioned but the are not provided. Do you have these fonts available ? Would like to try them when I have the Nucleo up and running. I use the non RLE fonts.

    Thanks !

    Bodmer (author)Rolo664u2015-07-07

    Hi, thanks for your feedback.
    The font numbers 1, 3 and 5 were reserved for intermediate sizes of the same font style (aka similar to Helvetica), but I did not need these sizes in the end and never created the required files. If you have a particular need then I may be able to create new files but you will need to be patient as I spend less time tinkering with electronics and software in the summer!

    mayank_alive (author)2017-10-06

    Hi Bodmer, thanks for sharing the info. I was trying my hands with 1.8inch screen using ST7735 driver. But unfortunately i am stuck with this screen (). Can you please help me with the same?

    I have checked the connections like hundred times, even viewed signals on logic sniffer. Infact even bought official Arduino LCD board (1.8inch) but still getting the same screen. It would be great if you can help :-)

    Bodmer (author)mayank_alive2017-10-09

    It looks like the screen has a different driver chip to the ST7735.

    I suggest you wire the Arduino barnd TFT to the UNO and follow the official Arduino site online instructions for that display and use the recommended libraries. Once that is working we can progress to one of my adapted libraries.

    Bodmer

    Scigor (author)2017-07-19

    Hi, nice library! Tested on Arduino Nano v3 with a 1.8" 128x160 TFT LCD Shield Module for Esplora, and works like a charm.

    SteveBar (author)2017-05-16

    Hi Bodmer,

    Awesome work and quite a long thread! :-) I read through most of it hoping for some info, but didn't.

    I am using a ST7735 display on a TeensyLC. I am using the TFT_ST7735.h lib from github. I get a ton of FastPin errors from the compiler, I added a few below. I tried commenting out the #include <TFT_FastPin.h> in my sketch as well as the TFT_ST7735.h file but no luck. I am using pins 13 for SCLK and 11 for MOSI (SPI0 on the LC) I defined the other 3 pins in the User_Setup.h file. I have a few questions below but feel free to expound on the topic and ignore the Q's. :-)

    1) Can I use this lib on the LC?

    2) Do I need to use FastPin, if yes, is there an LC version?

    3) Does the Adafruit_ST7735_AS.h fix or get around this?

    Thanks so much!

    Steve

    PS It's so nice to see the civil discourse in this thread! Some others are frightening!

    C:\Users\Steve B\Documents\Arduino\libraries\TFT_ST7735-master\TFT_ST7735.cpp: In constructor 'TFT_ST7735::TFT_ST7735(int16_t, int16_t)':

    C:\Users\Steve B\Documents\Arduino\libraries\TFT_ST7735-master\TFT_ST7735.h:83:19: error: 'FastPin' was not declared in this scope

    #define TFT_DC_D FastPin<TFT_DC>::hi()

    ^

    C:\Users\Steve B\Documents\Arduino\libraries\TFT_ST7735-master\TFT_ST7735.cpp:50:3: note: in expansion of macro 'TFT_DC_D'

    TFT_DC_D;

    momosh17 (author)SteveBar2017-07-19

    Hi

    I like this libraries, and i think it's perfect for my project, but i like to use it with Teensy 3.x, so please let me know, if you had a like converting for Teensy_LC?

    Thank you in advance

    SteveBar (author)SteveBar2017-05-16

    Update: I got the Adafruit_ST7735_AS & Adafruit_GFX_AS.h libs to work. The font draws a ton faster than the orig lib!!! I was wondering if the justification was an issue in this lib. I'm using the display to show the current value of an encoder and the numbers seem to be left justified regardless of the function I use. So as the count goes from 1's to 10's to 100's it displays left to right. So while counting back down the number starts in the hundreds column, and leaves the previous LeastSigDigs visible, making it always look like a 3 digit number. I think it would be a good idea to migrate to the TFT lib. Any help would be appreciated.

    Thanks,

    Steve

    Bodmer (author)SteveBar2017-05-25

    The library was not written to be compatible with Teensy boards so you have done well to convert it. The drawRightString() function should plot the text right justified. It worked with the stock Arduino boards.

    Hope your project is a success.

    beic (author)2017-07-01

    Hi there, please, tell me, why do you need those resistors?!

    barista (author)beic2017-07-16

    The logic level of the display is 3.3v and most arduino models use 5v. The resistors basically facilitate the conversion. ;)

    beic (author)barista2017-07-16

    I didn't know that, I have the Red board display version and I didn't put any resistors and it worked on the UNO.

    Anyway, how can I avoid the refresh flickering on the screen?

    Regards

    padouet (author)2017-06-14

    Hello,
    I try to transform your very good job from ILI9341 for ILI9342 (320x240, inverted color, miroring text), but I can not.
    Can you help me please ?

    fabianbambam (author)2017-04-26

    Hello, I will use your code with my QVGA 2.2 TFT SPI 240x320, like the one that I have attached to this message.

    I saw your electrical connection but in the ILI9341 Datasheet says that needs to be supplied the TFT with 3.3V, considering this, how do yo connect the TFT screen with the Arduino Uno?

    I mean, it's still being connected with this diagram connection? How do you protect the board with 5v signals?

    I was testing with 5v momentarily before but nothing happens, then I realize that the ILI9341 works with 3.3v signals and I now I don't know if I got damaged the TFT LCD screen, I'm now quite scared & paranoid with tests now:(

    I've attached a document with the interpretation in schematics


    • UNO +5V to display pin 1 (VCC) and pin 8 (LED)
    • UNO 0V (GND) to display pin 2 (GND)
    • UNO digital pin 7 through a 1K2 resistor to display pin 4 (RESET), add a 1K8 resistor from display pin 4 to GND
    • UNO digital pin 9 through a 1K2 resistor to display pin 5 (DC/RS), add a 1K8 resistor from display pin 5 to GND
    • UNO digital pin 10 through a 1K2 resistor to display pin 3 (CS), add a 1K8 resistor from display pin 3 to GND
    • UNO digital pin 11 through a 1K2 resistor to display pin 6 (SDI/MOSI), add a 1K8 resistor from display pin 6 to GND
    • UNO digital pin 13 through a 1K2 resistor to display pin 7 (SCK), add a 1K8 resistor from display pin 7 to GND
    Bodmer (author)fabianbambam2017-04-27

    The display is fitted with a regulator so you can connect 5V to the VCC pin. The signal lines (SCK etc) however require 3.3V logic levels, so you need those resistors as you have drawn. The resistors act as a voltage divider so the display gets the right logic levels from a 5V UNO.

    Some displays do not have a current limit resistor for the LED, so it best to add one:
    UNO +5V through a 56 Ohm resistor to display pin LED

    manu75 (author)2017-04-10

    nice job.Does this lib works on mcufriend 2.4tftlcd and mega, i looking for and working behind.waiting for ur reply.

    logmore (author)2017-02-18

    A quick question for you, is your Adafruit_GFX_AS library a standalone replacement for the Adafruit_gfx Library?? can it be used as a direct replacement to gain access to you new fonts ?

    Bodmer (author)logmore2017-02-23

    It should be compatible. Look at the graphicstest example and you will see the small changes needed to call up the library.

    benwingrove (author)2017-01-15

    Will this work with the Adafruit 3.5" 320x480 Color TFT Touchscreen Breakout, I believe it uses the HX8357D chipset?

    I have heard the Adafruit library is very sloooow.

    Bodmer (author)benwingrove2017-01-18

    I have not created any optimized libraries that support the HX8257D display :-(

    The Adafruit libraries have been written to provide generic support to as many Adafruit products as possible and have effectively been written to aid the sales of those products (would you buy a display if there was no supporting library?). Optimising for particular display+processor combinations would lead to lots of different hardware specific implementations that would need to be tested and managed. In practice a lot of users do not need a high performance, for example you might only look at a temperature reading on the display a couple of times a day once the project is built, so it depends what you want to do.

    Krakenwak (author)2017-01-16

    Hi Bodmer,

    I'm very impressed with the RLE font encoding & proportional spacing.

    If you were to rotate "some" of the font chars 90 degrees before encoding I think you would achieve a higher compression. You could then use a bit-field - One bit for each font char - to specify whether it had been rotated. Just food for thought.

    Excellent work!

    Bodmer (author)Krakenwak2017-01-16

    Thanks for the feedback.

    Yes, I did consider that as characters have a lot of long vertical strokes, however the way the TFT's expect data is a raster scan in rows, so a horizontal encoding fits well with this scheme and allows characters to be streamed very quickly.

    Cheers

    Krakenwak (author)Bodmer2017-01-17

    Hi Bodmer,

    Actually what I meaning to suggest was the use of the hardware Row/Col command register to effect the rotation of data from the Micro-Controller to the frame buffer. Although I use the SSD1963 the ST7735 & ILI9341 both appear to support Row/Col transpositions.

    Although my post is nothing to do with Arduino or Drivers, I really think the font compression has a lot of "possibly" untapped potential for Micro Controllers in general. Because so much of the frame buffer control is hardware controlled and once setup all we have to do is keep writing the particular rectangle, I have now started to think of the font chars less as individual blocks of rows & cols but more in the form of a long data string with embedded commands. This thinking then tends to lead me to think about utilizing words as well as bytes to hold data.

    As an aside, I'm using an STM32411RE with a SSD1963 and a 800x600 TFT. For a long time the best frame rate I could achieve was about 2 fps even using maximum compiler optimization. After looking at the assembler output I found a few "pushes & pop's" going on in the "clear screen loop" on closer examination I found there were still some register access call's going on that should have been in-line, after hard-coding the register access, the frame rate shot-up to over 60fps. Sometimes have a snoop at the assembler output really pays off.

    Bodmer (author)Krakenwak2017-01-18

    OK, yes this RAM write coordinate frame rotation was considered and tried out but it complicates things at the rendering level and the compression benefits are small in the grand scheme of things (compared to the big improvement when using the RLE method. Also for some reason the "wiping" of text onto the screen seemed worse for visual appeal, which might seem counter-intuitive.

    I have used the RAM frame of reference rotation when rendering BMP images as they draw from the bottom up.

    I also had the intent of encoding anti-aliased fonts using a variant of the Run Length methods and using another flag bit plus a 4 bit pixel brightness. When rendering text you would then pre-calculate the 16 pixel colours based on the foreground and background colours, then the 4 bit value in the RLE values would be used to look up the pixel colour.

    For larger fonts yet another flag bit could be used for flagging a 8 bit or 16 bit encoded values, and yet another flag for embedded commands like swap colours, etc etc

    Though these possibiloities are all very interesting I only tend to work on stuff I need for my own projects, or if someone is paying me to do it!

    joad (author)2016-12-27

    Hi, thanks for the good instructions.

    I have a question, I'm missing a "-" char(45) sign in 7seg font. How can I add it?

    I have found h c files but I do not understand how to edit a font.

    Thanks

    /Johan

    Bodmer made it! (author)joad2017-01-01

    Swap the Font7srle.c file for the one attached.

    joad (author)Bodmer2017-01-04

    Thanks, but I was looking for a "-" matching the 7-seg font.

    Any tips on how to edit or create new fonts will be gratefully appreciated.

    Bodmer (author)joad2017-01-15

    A character is drawn as a raster scan within a box size of the
    characters width and height. The RLE format is a byte, the top bit is a
    flag, the least significant 7 bits are a 7 bit number (0-127). If the
    flag is 1 then foreground pixels are plotted, if it is 0 the background
    pixels are plotted. The number of pixels to plot is the 7 bit number +
    1.

    So, for example, the encoded sequence "0x81, 0x1F" means plot 2 pixels in foreground then 32 pixels in background.

    A user has sent me a Java app that does the RLE encoding of various font formats but I have not tried it yet. You could manually generate a single character using some squared paper and a pencil and replace the one in the above file.

    AndréA117 (author)2016-05-29

    Hi Bodmer,

    this is great but I have a 2.8" ILI9341 TFT with XPT2046 touch controller connected to a NodeMCU 1.0 (ESP-12E), do you think you could adapt this libraries to work with my board? I'm new to all of this so I don't even know if it's possible...

    Thanks!

    Bodmer (author)AndréA1172017-01-10

    If you are still interested then I have finally got around to porting the ILI9341 library to the NodeMCU! Performance is very impressive!

    You can find a copy of the library here:

    https://github.com/Bodmer/TFT_ILI9341_ESP

    bomb192uk (author)Bodmer2017-01-12

    Awesome library, it was set up within minutes and super fast! Now my display is looking good and super smooth :-)

    Bodmer (author)bomb192uk2017-01-13

    Hi, thanks for the feedback. Good luck with your project.

    bomb192uk (author)2017-01-12

    Great library, so fast and full of features.

    One question, is there any plan or could you add support for the ESP8266? The libraries that are available for the esp8266 (beyond the Adafruit one) are ok but the text functions of your library seem much faster and more efficient and it would be nice to be able to use them.

    bomb192uk (author)bomb192uk2017-01-12

    Sorry, just seen you're reply below from a few days ago. I will download and test :-)

    AnthonyC7 (author)2016-10-11

    Great writ up! One question, how may I upload custom images to scroll through?

    Bodmer (author)AnthonyC72017-01-01

    Images of any significant size take up a lot of space so you would need to look at using an SD card to store them. I have an instructable that may help:

    https://www.instructables.com/id/Arduino-TFT-displa...

    AleksejsMirnijs (author)2016-10-05

    Hi! This really great and fast library! I get working on 2,4" TFT display on hardware SPI (http://www.buydisplay.com/default/color-2-4-inch-t...). Is there any opportunities to add others fonts?

    Thanks!

    Bodmer (author)AleksejsMirnijs2017-01-01

    It is not easy to add new fonts due to the way they are encoded for speed.

    I do plan to update the ILI9341 library soon to add in the Adafruit Free Fonts.

    Bodmer (author)2016-08-30

    Have you got the DS3231 connected and working with a library example?

    I have used the "DS3231_Simple" library so that is one I recommend:

    https://github.com/sleemanj/DS3231_Simple

    Once you have one of the examples running and talking to the DS3231 post back here.

    jaig11 (author)2016-07-30

    Hai am using 2.4'' tft screen not from adafruit...
    bt am using adafruit library...this is my 1st tym using this.....

    when i upload the graphictest.ino code....it 's showing the following error in serial port

    "
    TFT LCD test

    Using Adafruit 2.8" TFT Breakout Board Pinout

    TFT size is 240x320

    Unknown LCD driver chip: 0

    If using the Adafruit 2.8" TFT Arduino shield, the line:

    #define USE_ADAFRUIT_SHIELD_PINOUT

    should appear in the library header (Adafruit_TFT.h).

    If using the breakout board, it should NOT be #defined!

    Also if using the breakout, double-check that all wiring

    matches the tutorial.

    "

    i hv connected all pins as said in the code..

    can u pls help in this case...

    Bodmer (author)jaig112016-08-27

    Hi, just noticed this has gone unanswered for a while...

    Unfortunately I can't help you on this occasion.

    I suggest you ask for help on the Arduino forum in the "Displays" section. On the forum describe the problem, post a link to the vendor of your display, and post photos of the front and back of your display, this will help folk identify which display driver is on your board and tell you how to get it running.

    TTFN

    uli96 (author)2016-08-07

    Hi,

    thanks for this cool library! I needed something like this
    for a STM32F103 board with a OLED-Display (128x64 with SSD1306 controller). At
    first it did work only with FONT2 and when I tried FONT4 I only got the
    first character displayed. After some investigation I narrowed it down
    to the gap-value in the drawUnicode function, it returned bad values. I
    changed the definition from char to int since it is supposed to also
    store negative gap values and voila it worked.

    I used version 7

    Uli

    Bodmer (author)uli962016-08-08

    OK, thanks.

    In Arduino land a char is a signed value so it works OK. Since writing the library I have moved on to using different type designations like int16_t, uint16_t etc to make the code more portable and less compiler dependent.

    In later variants of the library I use Run Length Coding for the larger fonts so less FLASH is needed and also to speed up rendering on windowed plot area displays, but on an STM32 you probably are not bothered about that.

    Good luck with your project.

    jeff1608 (author)2016-07-27

    Great tutorial, it help me out a lot. Thanks

    hamberg82 (author)2016-07-22

    Hello Bodmer, nice work!

    I am trying to replace some unused characters with the swedish chartacters å,ä and ö in Font 4. Thought it would be easy by just adding some dots into the a and o bitmaps, but sadly, I cannot figure out how the RLE encoding works. Can you give me a hint?

    Bodmer (author)hamberg822016-07-24

    A character is drawn as a raster scan within a box size of the characters width and height. The RLE format is a byte, the top bit is a flag, the least significant 7 bits are a 7 bit number (0-127). If the flag is 1 then foreground pixels are plotted, if it is 0 the background pixels are plotted. The number of pixels to plot is the 7 bit number + 1.

    So, for example, the encoded sequence "0x81, 0x1F" means plot 2 pixels in foreground then 32 pixels in background.

    hamberg82 (author)Bodmer2016-07-26

    Thanks a lot!

    feddar (author)2016-07-23

    Thanks! It looks promising. I can't seem to get it working with a 2.4" ILI9341 display from ebay. (http://www.ebay.com/itm/291549777432?_trksid=p2057...)

    Would you please be able to tell me if it should work and I am just hooking it up incorrectly, or am I barking up the wrong tree?

    Thanks!

    feddar (author)feddar2016-07-23

    Got it going. I had my voltage divider resistors wrong. Now all is well. Thanks so much for your work. It is quite a bit faster than the original from Adafruit.

    feddar (author)feddar2016-07-23

    Now, I'm trying to get the touch screen working. The screen prompts work, but my taps don't register. Do I need to use voltage dividing resistors for the touch pins as well? I tried, but it doesn't seem to work. Can you please point me in the right direction. Much appreciated.