< async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"">

Friday, March 20, 2015

Quickly test an ILI9341 TFT display with an arduino [quick test]

ADVERTISEMENT
ili9341 tft display with arduino promini 3.3volt/8mhz
The small and reasonably priced  tft display using ili9341 display driver is a useful addon for several portable projects which need a small and beautiful display. There are certain hiccups while connecting and using it for the first time with an arduino. In a previous post, i have used the same display with raspberry pi on a raspbian (can be see here). Hooking the display with an arduino is also not that difficult if you know a few important things. So am sharing my experience here to start with the display at the fastest way. First and foremost, we need a library to control the display (or a sort of driver for the arduino micrcontroller). To start with i used the one from github (from gmtii) which can be downloaded here. If you haven't added libraries before please read this article which explains on how to add a library to arduino. The simple explanation is , download the zip file, extract, rename the folder as ili9341 and paste it in arduino-version/libraries folder.

Important Notes on connecting the ili9341 tft display to Arduino


1) This display uses 3.3 volts! So when i used this display with an arduino uno at 5volt, i got a white screen , with nothing else!! So i ended up getting an arduino pro mini which works on 3.3 volt. So you need a level shifter , if you intend to use it at 5volt. A simple solution for testing is to use two 1.5 volt batteries (3volt) and connect the ground to ground of an arduino uno and positive to vcc (5v)of a uno. This worked in my case for testing the display. I recommend a level shifter for stable results.

2) The led pin needs a resistor to control the current ( i used a 47 ohm resistor). Display works without this but you may risk a damage in the long run.

3) Wiring is simple, follow the one given in github page 

+----------------+
| (Arduino: TFT) |
+----------------+
| D4 : RESET     |
| D5 : CS        |
| D6 : D/C       |
| D7 : LED       |
| D11 : MOSI     |
| D12 : MISO     |
| D13 : SCK      |
+----------------+

4) For testing , there is an example folder with some sample sketches and just load one of them. See figure below


4) For example drawCircles will output the first figure in this blog post (red and blue circles)


Advanced features like landscape mode, additional fonts and rotating the display


The library listed above will provide some basic functionality. But the sketch memory size is relatively small in terms of flash usage (max 30-32k on atmega328). But an other library called ucglibrary offers a lot more features and fonts. This can be downloaded here (ucglib). Use the same steps for library installation. If you have the same wiring as above, open an example sketch under the ucglib (Hellow world) and then

1) Add  Ucglib_ILI9341_18x240x320_HWSPI ucg( 6,  5,  4); 

and in setup() of the sketch , add the following line to turn the backlight on

pinMode(7, OUTPUT);
digitalWrite(7, HIGH);

To set the display in landscape mode, use 

ucg.setRotate90()

preferably in the setup of the code. See example below

 #include <SPI.h>  
 #include "Ucglib.h"  
 /*  
  Hardware SPI Pins:  
   Arduino Uno          sclk=13, data=11  
   Arduino Due          sclk=76, data=75  
   Arduino Mega     sclk=52, data=51  
  >>> Please uncomment (and update) one of the following constructors. <<<   
 */  
 Ucglib_ILI9341_18x240x320_HWSPI ucg( 6, 5, 4);  
 void setup(void)  
 {  
  pinMode(7, OUTPUT);  
  digitalWrite(7, HIGH);  
  delay(1000);  
  ucg.begin(UCG_FONT_MODE_TRANSPARENT);  
  ucg.clearScreen();  
  ucg.setRotate90();  
 }  
 void loop(void)  
 {  
  ucg.setFont(ucg_font_ncenR14r);  
  ucg.setColor(255, 255, 255);  
  ucg.setColor(255, 0, 0);  
  ucg.setColor(1, 255, 0,0);  
  ucg.setPrintPos(0,25);  
  ucg.print("Hello World!");  
  ucg.setPrintPos(1,50);  
  ucg.print("Hello World!");  
  delay(500);   
 }  

end

6 comments:

  1. you refer to pin 7 for LED in wiring and text, but output to pin 10 in code?

    ReplyDelete
    Replies
    1. Yes, it should be 7, otherwise display may stay dark. Thanks for the correction

      Delete
  2. I'm using an Arduino Nano which has a 3.3v output.
    When I run any of the samples the display comes on but only a white screen. Any suggestions?

    ReplyDelete
    Replies
    1. It should be black. Double check the connections ( mosi,miso, sck, cs). Check the voltages with a multmeteter.

      Delete
    2. Driving myself nuts here. I have verified the voltages and connections.
      I even tried an uno/display combo that had worked in the past and all I get is a white screen no matter what example I use. Very frustrating.

      Delete
    3. You should power the display from a separate power supply. I encounter the same behavior when power from Nano. An external 3.3V for the display should do the job.

      Delete