Pages: 1 [2] 3 4 ... 11   Go Down
Author Topic: LCD display with ILI9341 driver on Arduino  (Read 42336 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Friends, I have a TFT with 2.2SP ili9341 (even that has nid69ita) working on nano and I can make it work with the sketch below (using 22k resistors instead of using cd4050). I tried to use the librarie suggested by chisco and pinout suggested by nid69ita and then the TheCoolest and none of them worked. Can anyone help me?

Code:

/*==========================================================================
The LCD connection is the same as Nokia LCD5110 and  is a鈥? Bit Pant Demo鈥?
Just for ElecFreaks TFT01-2.2SP, which use SPI serial port and 240x320 pixel.
The driver is ILI9341.
 
by Elecfreaks
==========================================================================*/
#include "pins_arduino.h"
//USAR O PINO 8 DO TFT PARA DETERMINAR O BRILHO DO DISPLAY
#define LCD_WR    9   //SCL -     PINO 7 DO TFT
#define LCD_RS   10   //SDA -     PINO 6 DO TFT
#define LCD_DC   11   //A0 -      PINO 5 DO TFT
#define LCD_REST 12   //RESET -   PINO 4 DO TFT
#define LCD_CS   13   //CSE     - PINO 3 DO TFT

volatile uint8_t *P_SCK, *P_MOSI, *P_DC, *P_RST, *P_CS;
volatile uint8_t B_SCK, B_MOSI, B_DC, B_RST, B_CS;
 
void LCD_Writ_Bus(char data)
{
  *P_CS &= ~B_CS;
  for (unsigned char c=0; c<8; c++)
  {
if (data & 0x80)
*P_MOSI |= B_MOSI;
else
*P_MOSI &= ~B_MOSI;
data = data<<1;
*P_SCK &= ~B_SCK;
asm ("nop");
*P_SCK |= B_SCK;
  }
  *P_CS |= B_CS;
}
 
void LCD_Write_COM(char VL) 
{   
  digitalWrite(LCD_DC,LOW);
  LCD_Writ_Bus(VL);
}
 
void LCD_Write_DATA(char VL)   
{
  digitalWrite(LCD_DC,HIGH);
  LCD_Writ_Bus(VL);
}
 
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
   LCD_Write_COM(0x2a);
   LCD_Write_DATA(x1>>8);
   LCD_Write_DATA(x1);
   LCD_Write_DATA(x2>>8);
   LCD_Write_DATA(x2);
 
   LCD_Write_COM(0x2b);
   LCD_Write_DATA(y1>>8);
   LCD_Write_DATA(y1);
   LCD_Write_DATA(y2>>8);
   LCD_Write_DATA(y2);
 
   LCD_Write_COM(0x2C);         
}
 
void LCD_Init(void)
{
        P_SCK = portOutputRegister(digitalPinToPort(LCD_WR));
        B_SCK = digitalPinToBitMask(LCD_WR);
P_MOSI = portOutputRegister(digitalPinToPort(LCD_RS));
B_MOSI = digitalPinToBitMask(LCD_RS);
P_DC = portOutputRegister(digitalPinToPort(LCD_DC));
B_DC = digitalPinToBitMask(LCD_DC);
P_RST = portOutputRegister(digitalPinToPort(LCD_REST));
B_RST = digitalPinToBitMask(LCD_REST);
P_CS = portOutputRegister(digitalPinToPort(LCD_CS));
B_CS = digitalPinToBitMask(LCD_CS);
 
        *P_RST &= ~B_RST;
delay(10);
*P_RST |= B_RST;
 
        LCD_Write_COM(0xCB); 
        LCD_Write_DATA(0x39);
        LCD_Write_DATA(0x2C);
        LCD_Write_DATA(0x00);
        LCD_Write_DATA(0x34);
        LCD_Write_DATA(0x02);
 
        LCD_Write_COM(0xCF); 
        LCD_Write_DATA(0x00);
        LCD_Write_DATA(0XC1);
        LCD_Write_DATA(0X30);
 
        LCD_Write_COM(0xE8); 
        LCD_Write_DATA(0x85);
        LCD_Write_DATA(0x00);
        LCD_Write_DATA(0x78);
 
        LCD_Write_COM(0xEA); 
        LCD_Write_DATA(0x00);
        LCD_Write_DATA(0x00);
 
        LCD_Write_COM(0xED); 
        LCD_Write_DATA(0x64);
        LCD_Write_DATA(0x03);
        LCD_Write_DATA(0X12);
        LCD_Write_DATA(0X81);
 
        LCD_Write_COM(0xF7); 
        LCD_Write_DATA(0x20);
 
        LCD_Write_COM(0xC0);    //Power control
        LCD_Write_DATA(0x23);   //VRH[5:0]
 
        LCD_Write_COM(0xC1);    //Power control
        LCD_Write_DATA(0x10);   //SAP[2:0];BT[3:0]
 
        LCD_Write_COM(0xC5);    //VCM control
        LCD_Write_DATA(0x3e);   //Contrast
        LCD_Write_DATA(0x28);
 
        LCD_Write_COM(0xC7);    //VCM control2
        LCD_Write_DATA(0x86);   //--
 
        LCD_Write_COM(0x36);    // Memory Access Control
        LCD_Write_DATA(0x48);   //C8    //48 68绔栧睆//28 E8 妯睆
 
        LCD_Write_COM(0x3A);   
        LCD_Write_DATA(0x55);
 
        LCD_Write_COM(0xB1);   
        LCD_Write_DATA(0x00); 
        LCD_Write_DATA(0x18);
 
        LCD_Write_COM(0xB6);    // Display Function Control
        LCD_Write_DATA(0x08);
        LCD_Write_DATA(0x82);
        LCD_Write_DATA(0x27); 
/*
        LCD_Write_COM(0xF2);    // 3Gamma Function Disable
        LCD_Write_DATA(0x00);
 
        LCD_Write_COM(0x26);    //Gamma curve selected
        LCD_Write_DATA(0x01);
 
        LCD_Write_COM(0xE0);    //Set Gamma
        LCD_Write_DATA(0x0F);
        LCD_Write_DATA(0x31);
        LCD_Write_DATA(0x2B);
        LCD_Write_DATA(0x0C);
        LCD_Write_DATA(0x0E);
        LCD_Write_DATA(0x08);
        LCD_Write_DATA(0x4E);
        LCD_Write_DATA(0xF1);
        LCD_Write_DATA(0x37);
        LCD_Write_DATA(0x07);
        LCD_Write_DATA(0x10);
        LCD_Write_DATA(0x03);
        LCD_Write_DATA(0x0E);
        LCD_Write_DATA(0x09);
        LCD_Write_DATA(0x00);
 
        LCD_Write_COM(0XE1);    //Set Gamma
        LCD_Write_DATA(0x00);
        LCD_Write_DATA(0x0E);
        LCD_Write_DATA(0x14);
        LCD_Write_DATA(0x03);
        LCD_Write_DATA(0x11);
        LCD_Write_DATA(0x07);
        LCD_Write_DATA(0x31);
        LCD_Write_DATA(0xC1);
        LCD_Write_DATA(0x48);
        LCD_Write_DATA(0x08);
        LCD_Write_DATA(0x0F);
        LCD_Write_DATA(0x0C);
        LCD_Write_DATA(0x31);
        LCD_Write_DATA(0x36);
        LCD_Write_DATA(0x0F);
*/
        LCD_Write_COM(0x11);    //Exit Sleep
        delay(120);
 
        LCD_Write_COM(0x29);    //Display on
        LCD_Write_COM(0x2c);   
}
 
void Pant(char VL)
{
  int i,j;
  Address_set(0,0,240,320);
  for(i=0;i<320;i++)
  {
    for (j=0;j<480;j++)
    {
      LCD_Write_DATA(VL);
    }
  }
}
 
void setup()
{
  unsigned char p;
  for(p=8;p<14;p++)
    pinMode(p,OUTPUT);
  LCD_Init(); 
}
 
void loop()

  Pant(0xFF);   
  Pant(0xF0);   
  Pant(0xE0); 
  Pant(0x05); 
  Pant(0x1F);   
  Pant(0x00);   
}

Logged

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 77
Posts: 4661
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@thecoolest. Thanks for information about SD.

Hi @daniel. You tried the library on Nano or other Arduino boards?
For me the code you posted is strange. I already see it before but in the comment part there are some information for me very strange.
SCL and SDA are the names of pin for I2C wiring and not for SPI. The pin for SPI are MOSI/MISO/SCK and SS o CS
Pins SCL,SDA,MISO,MOSI and SCK are fixed in every Arduino (not the same on Uno or Mega).
Other pins can be assigned every you want. But not this special pins.

Are you sure to know the Nano pinout? Can you see this very good pdf:
http://www.pighixxx.com/downloads/arduino-nano/
http://forum.arduino.cc/index.php?topic=151646.0
« Last Edit: September 25, 2013, 02:12:52 am by nid69ita » Logged

my name is IGOR, not AIGOR

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@nid69ita, thanks for the answers.

I looked at the links you showed me and did exactly as you suggested, put a CD4050 and tested before the other sketch already worked with the resistors.
I put the sketch TFT_text (see below the code and TFT.h and TFTv2.h) and it worked, but the screen flickers(flashes quickly as if the arduino pin resetting) and the image is mirrored. So I tried to use the TFTv2 did not work.
Reviewed the TFT_text and found nothing related to blinks (see the video in ).
Another detail when I change cd4050 for resistors the screen does not work.
Any idea?

Thank you!

Code:
#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8 
// CS pin 3 of tft conected in arduino pin 10
// RST pin 4 of tft conected in arduino pin 8
// D/C pin 5 of tft conected in arduino pin 9
// MOSI pin 6 of tft conected in arduino pin 11
// SCLK pin 7 of tft conected in arduino pin 13

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
//TFT TFTscreen = TFT(cs, rst, dc); //not work
//TFT TFTscreen = TFT(dc, cs, rst); //not work
//TFT TFTscreen = TFT(dc, rst, cs); //not work
//TFT TFTscreen = TFT(rst, cs, dc); //not work
//TFT TFTscreen = TFT(rst, dc, cs); //not work

// char array to print to the screen
char sensorPrintout[4];

void setup() {
 
  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
 
  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255,255,255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ",0,0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(5);
}

void loop() {

  // Read the value of the sensor on A0
  String sensorVal = String(analogRead(A0));
 
  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

  // set the font color
  TFTscreen.stroke(255,255,255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0,0,0);
  TFTscreen.text(sensorPrintout, 0, 20);
}

* TFT.h (0.76 KB - downloaded 208 times.)
* TFT.cpp (0.47 KB - downloaded 198 times.)
* TFTv2.h (5.38 KB - downloaded 208 times.)
* TFTv2.cpp (13.95 KB - downloaded 233 times.)
Logged

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 77
Posts: 4661
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@daniel, I tried also with my Arduino Nano V.3 (a clone) and it work.
My Arduino Nano is at 5V, so I used my little conversion board.

I attach the library I used (a file rar). The library you post is different from my. I tested on Nano using the example named text.ino
In this library pins are fixed (obviously for SCK/MISO/MOSI):
D4 :  RESET
D5 :  CS
D6 :  D/C
D7 :  LED
D11 : MOSI
D12 : MISO
D13 : SCK


In the TFT.h you attach, there is a note:
Code:
/// The Arduino LCD is a ST7735-based device. .....
class TFT : public Adafruit_ST7735 {
public:
  TFT(uint8_t CS, uint8_t RS, uint8_t RST);

It is based and call also other library from Adafruits. But refer to ST7735 !?!?

The constructor is fixed: CS, RS (dc??), RST   so this can work
Code:
//TFT TFTscreen = TFT(cs, rst, dc); //not work

* ili9341.rar (379.37 KB - downloaded 574 times.)
« Last Edit: September 26, 2013, 08:58:12 am by nid69ita » Logged

my name is IGOR, not AIGOR

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@nid69ita Thank you very much, I used the file you sent me and works fine!!!

I would like to make a few more questions (will its helpful to many here in the forum):
* How do I change the type font (when I use font size 10 and she gets big square to form the character)?
* How can I change the orientation from portrait to landscape?
* How can rotate 180° ?
* How can I include the SD card on Arduino? CS must use another pin, right? as I proceed in the sketch and the Arduino?
  Thank you for your help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I was finally able to get this easily going with a 5v pro mini and Adafruit library, so there's no need to level convert.  smiley-fat
Logged

0
Online Online
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I was finally able to get this easily going with a 5v pro mini and Adafruit library, so there's no need to level convert.  smiley-fat

Did the adapter board have level converters built in?  If not then you are likely to fry the
ILI9341, its definitely only spec'd for 3.3V maximum (most modern LCD controllers are
a smaller process and 3.3V I/O these days).  It may work for a while, but could fail
without warning.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,
I've the same tft lcd screen with Arduino uno and CD4050 I was able to start it.
I don't use adafruit's library but that:
https://github.com/gmtii/ili9341-arduino
It works perfectly and it's nice, but the problem is that I can not find the instructions to turn it 180 degrees.
Someone has succeeded?
Thank you.
Logged

Pennsylvania
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,
I've the same tft lcd screen with Arduino uno and CD4050 I was able to start it.
I don't use adafruit's library but that:
https://github.com/gmtii/ili9341-arduino
It works perfectly and it's nice, but the problem is that I can not find the instructions to turn it 180 degrees.
Someone has succeeded?
Thank you.

I've modified Seeed's libraries to include text rotation on the Version 2 LCD.  Go here: http://forum.arduino.cc/index.php?topic=150900.0

Regards,
-__-
Logged

Software's good, software's impressive, but it's hardware that does the work.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I was finally able to get this easily going with a 5v pro mini and Adafruit library, so there's no need to level convert.  smiley-fat

Did the adapter board have level converters built in?  If not then you are likely to fry the
ILI9341, its definitely only spec'd for 3.3V maximum (most modern LCD controllers are
a smaller process and 3.3V I/O these days).  It may work for a while, but could fail
without warning.

You are right that the TFT does need 3.3V. and I did rush my tests so sorry. I bought both a 5V and 3.3 pro mini (and a CD4050) and created a test pcb (3.3V Pro Mini with raw 5V):

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Friend,
     I have this items:
         a) New Pro Mini atmega328 5V 16M Replace ATmega128 http://www.bricogeek.com/shop/233-arduino-pro-mini-328-5v-16mhz.html
         b) 2.2" Serial SPI TFT LCD Module Display 240*320 Chip ILI9340C+PCB Adapter SD Card http://www.ebay.es/itm/200952295233?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
         c)  4-Channel 5V-3.3V Level Converter  http://www.ebay.es/itm/Adafruit-4-Channel-5V-3-3V-Level-Converter-for-Raspberry-Pi-GPIO-Arduino-etc-/181225596332?pt=UK_Computing_Other_Computing_Networking&hash=item2a31e325ac&_uhb=1

        I had bad experience with previous nokia 5110 LCD interfacing 3.3v and 5V. I'm wondering if I'm going to have any problem with 3.3v transceiver, and also was thinking to use 74HC541. To do the test I need if you can give me some links to a hello world software and library for this LCD, since I didn't find much on the web. Do you think it's going to work with arduino mini in software SPI emulation? Thanks!
     
Logged

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 77
Posts: 4661
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For me your TFT is identical to mine. And I think french vendor write a wrong indication about controller.
As I writed in posts before, I used this:
https://github.com/gmtii/ili9341-arduino

For Nokia I have and I used  with Adafruits libraries:
http://learn.adafruit.com/nokia-5110-3310-monochrome-lcd
Logged

my name is IGOR, not AIGOR

Not USA
Offline Offline
Full Member
***
Karma: 1
Posts: 123
Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm also trying to get this 2.2 TFT to work, with little sucess.

Can someone who has got this to run just go through and clarify a few points:

Arduino type used
Library used
Which pins to connect : SD0(MISO), LED, SCK, SDI(MOSI), D/C, RESET, CS, GND, VCC

If you used a level converter to go to 3.3v, and what pins need to be 3.3v or is it all of them?

I've got an uno and no level converter chip.

Cheers if you can lock this down for me smiley
Logged

3D Artist,Modeler, Texturer, Animator, Electronics and Robotics, Programming C, VB, Website Design, Flash animator

Too many hobbies?

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 77
Posts: 4661
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino Uno and Arduino Nano (328 chip)

Here pin connection:
http://forum.arduino.cc//index.php?topic=181679.msg1406299#msg1406299
exactly 8 post before this.

For converter:
http://forum.arduino.cc//index.php?topic=181679.msg1404056#msg1404056
page 1 of this thread.
Logged

my name is IGOR, not AIGOR

Greece - Thessaloniki
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone! I bought an LCD based on ILI9341 driver but none of the available arduino examples worked to my Arduino pro mini.
I used the CD4050 level converter (5V -> 3.3V) and a LD33V ( 5V to 3.3V voltage regulator).
Still the LCD denied to work.

So, I examine the source code of  TFTv2.cpp and TFTv2.h files. I saw that the LCD's Reset pin was not initialized.
Then I add the following 2 lines to TFTv2.h files:
Code:
#define TFT_RST_LOW  {DDRD |= 0x10;PORTD &=~ 0x10;} //Added by Vassilis Serasidis (18 Oct 2013)
#define TFT_RST_HIGH {DDRD |= 0x10;PORTD |=  0x10;}  //Added by Vassilis Serasidis (18 Oct 2013)

and these 3 lines to TFTv2.cpp:

Code:
void TFT::TFTinit (void)
{
      TFT_RST_LOW; //Added by Vassilis Serasidis (18 Oct 2013)
      delay(200);  //Added by Vassilis Serasidis (18 Oct 2013)
      TFT_RST_HIGH; //Added by Vassilis Serasidis (18 Oct 2013)
      SPI.begin();
       ...
       ...
}

After that all examples worked just fine!

You can download the library and the examples I used from https://dl.dropboxusercontent.com/u/3680094/SeeedTFTv2.zip
« Last Edit: October 18, 2013, 10:33:32 am by Serasidis » Logged

Pages: 1 [2] 3 4 ... 11   Go Up
Jump to: