Monday, July 27, 2015

2.2 or 2.4 or 2.8 inch SPI TFT LCD ILI9341 to Arduino Uno

Over the weekend I figured out how to interface a 2.8 inch SPI TFT that has a ILI9341 chip to an Arduino Uno.  All it takes is eight 1K resistors.  Most people use a 4050 IC.  Here is the schematic.

I am using the Adafruit ILI9341 driver found at: https://github.com/adafruit/Adafruit_ILI9341
Note that the Adafruit LCD has level shifters for 5 volts built into it.

Here is a video of it working on Youtube.

Here is a video of the LCD being used as an oscilloscope.


Here are a couple of still pictures, only 6 of the 8 bits are connected for these pictures.


Here is the code for a more basic oscilloscope.

/************************************
 2.8 SPI PIND TFT Oscope Simple
 Reads the D0-D7 pins using PIND,
 and shows the value on the screen.
 Created 27 july 2015 by Bob Davis
**************************************/
//#include  // Arduino LCD library
#include
#include "Adafruit_ILI9341.h"
#include "Adafruit_GFX.h"

// pin definition for the Uno LCD
#define TFT_DC 9
#define TFT_CS 10
// Use hardware SPI (on Uno, #13=clk, #11=mosi) and the above for CS/DC
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_ILI9341 tft = Adafruit_ILI9341();

//// set up variables
int Input=0;
byte Sample[320];
int trigger=64;

void setup(){
  // initialize rotate and clear the display
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setRotation(1);
  // Set the font size
  tft.setTextSize(2);
  // D input pins
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
}

void loop(){
  // wait for a positive going trigger
  for (int timeout=0; timeout < 1000; timeout++){
    Input = PIND;
    if (Input < trigger) break;  }
  for (int timeout=0; timeout < 1000; timeout++){
    Input = PIND;
    if (Input > trigger) break;  }
  // quickly collect the data with no delay
  for (int xpos=0; xpos <320; xpos++){
  Sample[xpos]=PIND;
  // display the collected data
  for (int xpos=0; xpos <319; xpos++){
  // erase the old and draw new line
    tft.drawLine(xpos+1, 0, xpos+1, 240, ILI9341_BLACK);
    tft.drawLine(xpos, (Sample[xpos]*2), xpos+1, Sample[xpos+1]*2, ILI9341_WHITE);
  }
}
// End of program

There is more info on the analog to digital converter at http://bobdavis321.blogspot.com/2015/06/arduino-5msps-oscilloscope-revisited.html

11 comments:

  1. The 50% resistor divider you created provides 2.5V to the LCD powered at 3.3V.
    Using 1K and 560 Ohm would be a much closer match (3.2V to the LCD) and the increased drive strength would allow you to run the LCD communications at higher speeds.

    ReplyDelete
  2. Using a 1K and a 2K resistor would also work. However the driver IC is actually rated to run on 2.5 volt or 3 volt logic so 2.5 volts works fine.

    ReplyDelete
  3. Hi, I used your schematic for my project and it works perfectly.
    Than you !

    http://yl4bs.blogspot.fr/2017/02/cheap-data-logger-v3-independent-data.html

    ReplyDelete
  4. Hai

    At the pinmode. What should i put on the input? Or is it just a copy and paste and it should work fine?

    ReplyDelete
  5. that code makes no sense and is flooded with errors/typos

    ReplyDelete
  6. It is tricky to get code to display correctly on blogspot.

    ReplyDelete
  7. There is an extra "include" just delete it.

    ReplyDelete
  8. hello Bob,

    i have rearranged my connections as per your drawing . Hope it solves my problem which is explanied below.

    https://www.avrfreaks.net/forum/ili9341-tft-display-28-white-screen-issue

    ReplyDelete
  9. hello Bob,

    i have rearranged my connections as per your drawing . Hope it solves my problem which is explanied below.

    https://www.avrfreaks.net/forum/ili9341-tft-display-28-white-screen-issue

    ReplyDelete
  10. hello Bob,

    i have rearranged my connections as per your drawing . Hope it solves my problem which is explanied below.

    https://www.avrfreaks.net/forum/ili9341-tft-display-28-white-screen-issue

    ReplyDelete