problem with ili9341

Hi, I display the time and date on a LCD color display, but I was unable properly refresh the display.

At the end of my program , I added the " ucg.clearScreen (); " but the display is refreshed every four seconds , and this is not practical.

here my code

#include <SPI.h>
#include "Ucglib.h"
#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9 , /*cs=*/ 10, /*reset=*/ 8);

void setup(void)
    // rotation de 90°
    ucg.setColor(0, 3, 6, 20 );
  ucg.setColor( 1, 13, 22, 66 );
  ucg.setColor( 2, 21, 37, 115 );
  ucg.setColor( 3, 29, 50, 150 );
   // The following lines can be uncommented to set the date and time
 // rtc.setDOW(Dimanche);     // Set Day-of-Week to SUNDAY
 // rtc.setTime(14, 22, 0);    // Set the time to 12:00:00 (24hr format)
 // rtc.setDate(13, 9, 2015);   // Set the date to January 1st, 2014


void loop(void)
  // affiche le jour
ucg.setColor(255, 255, 255);

 // affiche la date 
ucg.setColor(255, 255, 255);

 // affiche l'heure 
ucg.setColor(255, 255, 255);


I’m also using a ILI9341 TFT but I get better results using the Adafruit libs.
Maybe you wish to try them instead (you have to #include 2 Adafruit libs plus SPI.h ):

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9340.h>

GitHub - adafruit/Adafruit_ILI9340: This is a library for the Adafruit 2.2" SPI display. // it also fits for ILI94341
GitHub - adafruit/Adafruit-GFX-Library: Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from //

Good news is, Adafruit uses hardware SPI: faster than by software and SD cards can be run on the same bus without extra pins (opposite to UTFT).

But anyway, clearing the whole display is always extremely slow. Usualyy cheap TFT displays don’t have a video RAM buffer so for clearing they write “black” to all pixels.
Better to overwrite each specific line before writing to this line again, Adafruit libs do that by setting the cursor to the related line and then print the line:


Can i have the manual to this library ?

Try with this library: ILI9341_due/MEGA/UNO

For DS3231, try this

about the ILI9341_due/MEGA/UNO:

where can I find libs for different font sizes and geometric graphs to draw (lines, circles, rectangles, by shape and fill-shape) ? Comparable to Adafruit or UTFT or ucglib libs?

is it on github?

ArthurD: about the ILI9341_due/MEGA/UNO:

where can I find libs for different font sizes and geometric graphs to draw (lines, circles, rectangles, by shape and fill-shape) ? Comparable to Adafruit or UTFT or ucglib libs?

is it on github?

Documentation here. Github here. You can create any fonts you like from ttf fonts, read section "Creating Custom Fonts" and "Custom fonts on AVR" in the documentation.

New fonts:

Example: DS3231 + ILI9341 2.4" + Arduino MEGA

#include <Wire.h>
#include <SPI.h>
#include <ILI9341_due_gText.h>
#include <ILI9341_due.h>
#include "fonts\allFonts.h"

#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10


ILI9341_due_gText t1(&myTFT);  //for date
ILI9341_due_gText t2(&myTFT);  //for hour
char TX[50];

//DS3231 RTC
#define DS3231_I2C_ADDRESS 0x68

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
  return( (val/10*16) + (val%10) );
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
  return( (val/16*10) + (val%16) );

void setup()
  bool result = myTFT.begin();
  Serial.print("TFT begin successful: ");
  Serial.println(result ? "YES" : "NO");


  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,27,6,2,14,9,15);   //  day 2 =  Monday

void loop()

 byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,

  t1.defineArea(100, 110, 220, 50);
  t1.setFontColor(ILI9341_WHITE, ILI9341_BLACK);
  sprintf(TX, "20%02d / %02d / %02d", year, month,dayOfMonth);
  t1.drawString(TX, gTextAlignMiddleCenter);

  t2.defineArea(0, 0, 320, 240);
  t2.setFontColor(ILI9341_RED, ILI9341_BLACK);
  sprintf(TX, "%02d:%02d:%02d", hour, minute,second);
  t2.drawString(TX, 75, 110);  

//RTC DS3231
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
  // sets time and date data to DS3231
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)

void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek,
byte *dayOfMonth, byte *month, byte *year)
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec( & 0x7f);
  *minute = bcdToDec(;
  *hour = bcdToDec( & 0x3f);
  *dayOfWeek = bcdToDec(;
  *dayOfMonth = bcdToDec(;
  *month = bcdToDec(;
  *year = bcdToDec(;
//RTC DS3231

that's amazing, thanks for your inputs! I'm a little confused about all that though, so

1) - is this code - for AVRs - for standard DUE - or for DMA DUE

in the source above and in the examples at github ?


2) will the DMA and the SPI clock diver set to 2 affect the SD card functionality when plugged to the same SPI port or will there be issues to be expected ?

The library is for AVR, Due and it also supports DMA in Due. All of the examples work on Due, some of them will not fit into AVR memory (if you're not using Mega) but those that fit will work. The code for Due and AVR is the same.

Not sure what library you use for "SD card functionality" but if you look at sdFatTftBitmap example where I am using SD card to read images (via SDFat library) then you can set TFT and SD card SPI clock dividers independently (TFT divider in ILI9341_due_config.h and SD card divider in sdFatTftBitmap.ino - SD_SPI_SPEED). That works without conflicts (if you use different CS pin for TFT and SD card of course). If you use some other library and you get conflicts then you can try to turn on SPI transactions in both libraries (in ILI9341_due it's in ILI9341_due_config.h - ILI_USE_SPI_TRANSACTION).

hi, I'm just testing your lib - it's amazingly fast!

1 question which arose about how to get the current cursor position. In my old Adafruit ILI9340 lib there is the function tft.getCursorX(); tft.getCursorY();

is there something in your lib, too?

and 1 more question:

do you have also a lib for ILI9225 Displays? (I have 3 of them which actually need to be speeded up a lot)

I had no need for getCursorX and getCursorY so that's why it's not there. What do you need it for? And I do not have a lib for ILI9225, I only created one for ILI9341 because that's the displays I bought.

it's for setting the cursor to write at a calculated place and store that variable value for immediate or later follow-up writings or for linefeed etc. to use a print command like on stdout by automatic wordwrap (e.g., printing strings of variable lenght which perhaps exceed the display width or height).

But also by manually calculating it via font size width/height I cannot write at a position (x,y). A tft.printxy(x,y,string) function would be needed, perhaps there is one but I didn't get it working.

ok, if I get the time I'll add those functions in. Btw. there are two functions that I do not seem to have documented, charWidth and stringWidth:

uint16_t charWidth(uint8_t c); uint16_t stringWidth(const char* str); uint16_t stringWidth(const __FlashStringHelper *str); uint16_t stringWidth(const String &str);

charWidth will return you width of a specific char and stringWidth the width of a whole string. Both are calculated for your currently set font.

There is printAt(x,y,string)

+1 +1 +1 +1