Mcufriend 2. 4 TFT Display interfacing with Arduino Uno

Dear Sirs,

Greetings!!

Am new learner.I have newly bought 2.8 inch ILI9341 TFT.I have tried Mr.David mcufriend library, TFT was directly mounted on Uno enjoyed with learning.But when it comes to physical wiring interface with Arduino,got stucked.Googled & tried many example but in vain.

Could you please guide me how to do interface wiring?
Model picture attached

Following code from Github is used:

// Mr. prenticedavid
// MCUFRIEND_kbv/button_simple.ino at master · prenticedavid/MCUFRIEND_kbv · GitHub

#if 1

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button on_btn, off_btn;

int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT); //because TFT control pins
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
return pressed;
}

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

void setup(void)
{
#if defined(arm) || defined(ESP32) //default to 12-bit ADC
analogReadResolution(10); //Adafruit TouchScreen.h expects 10-bit
#endif
Serial.begin(9600);
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
Serial.println("Calibrate for your Touch Panel");
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(0); //PORTRAIT
tft.fillScreen(BLACK);
on_btn.initButton(&tft, 60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2);
off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2);
on_btn.drawButton(false);
off_btn.drawButton(false);
tft.fillRect(40, 80, 160, 80, RED);
}

/* two buttons are quite simple
*/
void loop(void)
{
bool down = Touch_getXY();
on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
off_btn.press(down && off_btn.contains(pixel_x, pixel_y));
if (on_btn.justReleased())
on_btn.drawButton();
if (off_btn.justReleased())
off_btn.drawButton();
if (on_btn.justPressed()) {
on_btn.drawButton(true);
tft.fillRect(40, 80, 160, 80, GREEN);
}
if (off_btn.justPressed()) {
off_btn.drawButton(true);
tft.fillRect(40, 80, 160, 80, RED);
}
}
#endif

Not sure what that meant. Plug it into the arduino directly, making sure to match the 3.3V pin on display to the 3.3V pin on Arduino.

I literally just seconds ago removed an mcufriend display from my Mega2560 board. It works just fine. Coincidence is a weird thing :slight_smile:

Sir,I did that & worked with many examples of mcufriend library, when i tried for wiring btween Uno and TfT totally failed.As I need Arduio pins for other components like relay,some physical switches

It's possible that the signals are getting distorted if you use longer wiring. That seems unlikely, but there are some arduino peripherals that just barely work and the slightest change causes them to fail.

In any case, the mcufriend parallel interface uses almost all the available Uno pins (I believe there are only two I/O pins unused). I use it with a Mega so that way I have access to more I/O. I have always used it inserted directly into the device, never tried extending the wiring.

I couldnt understand,how many Pins actually needs for mcufriend library as I need atleast 8 spare pins from uno.As far as wire length concern hardly 10 inch long wires are being used.

You will need to connect GND, 5V, 3.3V, and all pins marked with LCD_. The SD card slot needs the additional four pins marked with SD_. If you only need the display, that leaves D0, D1, D10, D11, D12, D13, and A5 free. The LCD_RST can be tied to the arduino RESET (through a 10K resistor if you really want to be cautious), that will free up A4 and allow the use of the I2C bus.

Thanks for Your response,One quick question which Pin is XP,YP,YM & XM...on TFT

Commonly A1, A2, D6, and D7, although I'm not sure of the specific order.

Install the MCUFRIEND_kbv library and run the diagnose_Touchpins example sketch, that will display the pin arrangement on the serial monitor.

Thanks Mr.David.. I will do it.

Sir,

Does above TFT shown in Pic ( spiflash written on it) standard SPI compatible?

Mostly Red Color TFT have clearly written mcufriend.com ,which is clear that TFT LCD uses parallel interface.

I'm not that familiar with the displays, someone else will need to answer that question.

Will these pins be unused after having Display and Touch functionality both (SD card not required) ?
Thanks

As far as I know they will be unused by the display shield. D0 and D1 are used for Serial, so you cannot use those if you are using Serial.

Thanks for your prompt response.
What I understood is,I can have Touch & Display both and Mentioned will be spare for other use.
Aren`t these?

Thanks

Correct.

1 Like

Thank you Sir

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.