Go Down

Topic: Can't get TFT SPI 2.8" Display to work with Arduino Mega 2560 Pro (Read 1 time) previous topic - next topic

coby1kenobi

Hi! I've been banging my head trying to get the TFT SPI 2.8" display with touch to work with an Arduino Mega 2560 Pro.
I got the display from https://shopee.ph/TFT-LCD-240x320-2.8-Module-ILI9341-i.20469516.827034804
I have the wiring as such:
TFT_DC 43
TFT_CS 53
TFT_MOSI 51
TFT_CLK 52
TFT_RST 49
TFT_MISO 50
TFT_TCS 41

I'm using a TXB0104 bi-directional level shifter to bring 5v down to 3.3v for the SPI, MOSI, MISO, and CLK pins only since there are only 4 pins available. (I have placed an order for an 8-Channel level shifter though) The rest of the pins, DC, CS, and Touch CS are shifted using resistors. It might be possible that the display is not working properly because the CS, DC pins only tap 3v instead of 3.3v. I don't have the specific resistors to make the voltage 3.3v.

I attempted to use the Adafruit_ILI93141 library but I haven't been able to get it to work for a week now. I'd really appreciate any finger-pointing in the right direction.

david_prentice

I do not know what TCB0104 is.
TXS0104 is a 4-bit level shifter from Texas Instruments

Please post a schematic of your wiring.   With values of the resistors etc.
A photo is handy too.

If everything is connected correctly your display should work with the Mega2560.
Extra eyes should help spot your wiring problem.

You also need to use compatible libraries e.g. Adafruit_ILI9341.h with HW SPI constructor.   XPT2046_TouchScreen.h

David.

coby1kenobi

Sorry, I made a typo. It should be TXB0104, not TCB0104. It will be replaced soon by an 8ch level shifter from texas instruments, the TXS0108E. 

May I ask what software I can use to make a schematic? I have attached a photo of my wiring though it is not very good. 

I am using the following libraries:
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046_Touchscreen.h"

The connections that cannot fit in the level shifter I have now are in between one 1k resistor and 220R resistor + another 1k resistor. I may have messed the previous up. Assuming this is fixed when the new level shifter arrives, can I ask if the connections I provided in the first post are alright?


david_prentice

Some advice:

Place any 10k resistors between Blue GND rail and breadboard rows.

Plug the screen into the breadboard.  It will lie above those 10k.

Place the 4k7 resistors across the breadboard gutter.

Connect external wires from the Arduino to the 4k7.

Even if you use a TXS0104 module you can have a similar arrangement.   i.e. with display pins neatly plugged into breadboard rows.

Yes,  4k7 + 10k would be a suitable potential divider.   But you could get away with 1k0 + 1k0.   After all,  the ILI9341 is 2.8V - 3.3V device.

You can solder two 1k0 to make a 2k0 and it will still fit neatly on the breadboard.

Forget about  the Touch pins for the moment.
Wire the TFT pins neatly.   Run Adafruit_ILI9341 examples. 
 
Remember to use the TFT_RST argument in the constructor.   Some Adafruit examples are designed to trip up users of Chinese Red SPI displays.

Oh,  if you really want to use Rats Nest wiring,  please make a table of each connection and wire colour.

David.

TFTLCDCyg

Check thread by thread there is no other option, when you use cables for prototype you must take care of many connections.

My "headache free" recommendation for this type of TFT on MEGA or UNO, is to use a CD4050BE.




I suggest creating a shield with a UNO type PCB.

To minimize wiring failures, it is best to solder all wires. To make it more comfortable to handle the TFT, use a 14-pin female header
ft81xmania.com/comunidad/

david_prentice

I agree 100% with making a ProtoShield.   Then it will work with any regular Arduino as well as evaluation boards from NXP, ST, TI, ...

The OP is using a Mega2560_Pro which does not match anything else in the world.
But since it has headers on a 2.54mm matrix you can use regular Protoboard.   Mount appropriate lengths of female header sockets and solder the connecting wiring.

CD4050 has 6 channels.
TXS0108 has 8 channels.

Personally,   I prefer using a proper 3.3V MCU in the first place.   Then buffers are not needed.

David.

TFTLCDCyg

The point is that most of us started with an arduino UNO or a MEGA, so we thought at some point of installing a TFT, but with the passage of time something else is needed: TFT´s speed, versatility with image handling , use of a TFT with touch panel, size, durability, ability to be used in sunlight, etc.

Don't get me wrong, they are excellent plates, mature and with a large number of libraries available; However, with the passage of time, the projects become specialized and require features that those first boards do not have, one of them compatibility with 3.3V logic, speed, MCU size, WiFi, among others.

However, having a special shield to handle this type of economical screens (SPI, with 3.3V logic) on MCU of 5V logic, helps to reduce project development times.
ft81xmania.com/comunidad/

david_prentice

I agree that putting the CD4050 or TXS0108 onto the Protoshield makes it "universal"
i.e. any Red SPI display can run on 5V Arduino as well as 3V Arduino.

Red SPI displays come in many sizes.  e.g. 128x128, 128x160, 176x220, 240x320, 320x480.
You can use the same 14x1 header for all these displays.

Note that you need more than 6 channels if you want to use TFT, Touch and SD card.

David.

TFTLCDCyg

In theory we could install a microSD reader with 5V logic like these for example:



I remember having built a shield to do tests with that type of external readers, I could place it under the shield with CD4050BE, which manages the lines with 3.3V logic from the ILI9341 to see how "the Franky" behaves on the arduino MEGA jejeje

Regarding the touch panel, on AVR boards it goes very well with the URTouch library. So the XPT lines could connect to digital pins directly
ft81xmania.com/comunidad/

david_prentice

The CD4050 has enough channels for TFT and SD.
You can bit-bang the XPT2046 with 4 or 5 independent GPIO pins e.g. URTouch.h library
Obviously at the expense of losing some GPIO pins.

The XPT2046 VCC pin on the Red SPI displays is supplied by the 3.3V regulator.
The IOVDD pin appears to be left as n.c.

According to the XPT2046 datasheet:
Quote
Absolute Maximum Ratings
+VCC and IOVDD to GND
−0.3V to +6V
Analog Inputs to GND
−0.3V to +VCC + 0.3V
Digital Inputs to GND
−0.3V to IOVDD + 0.3V
...
Yes,  you can run an independent XPT2046 with VCC=5V.   And use 5V logic to the Digital Inputs.
But these Red SPI boards route VCC=3.3V to ILI9341, XPT2046, SD card.

Yes,  you can use 1.8V logic on the XPT2046 (if you provide 1.8V to IOVDD pin)
But you can't use logic levels where IOVDD > VCC

I suspect that the XPT2046 is actually more input voltage tolerant that the datasheet says.

I also suspect that TFTLCDCyg uses HW SPI for TFT and Touch on the Teensy.

David.

coby1kenobi

Thank you all for your replies and suggestions!

I've tried to overhaul my messy design but it was to no avail. I've attached a photo of it for reference but here are the connections (display -> arduino):
VCC -> 5v
Grnd -> grnd
CS -> D53 through a level shifter. 1k resistor then another 2 1k resistors.
Reset -> D42 through TXB0104 shifter
DC -> D43 through a level shifter with the same configuration as CS'
MOSI -> D51 through TXB0104
SCK -> D52 through TXB0104
LED -> 5v
MISO -> D50 through TXB0104

Here are the first few lines of the graphicstest I'm trying to use:
Code: [Select]
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_DC 43
#define TFT_CS 53
#define TFT_RST 42

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);


For the life of me, I can't figure out what's wrong.


david_prentice

Your picture makes my head hurt.

If you had followed my advice you would have 8 or 9 different coloured wires from breadboard to Arduino.
We could trace each wire end from Arduino to breadboard.   Without any rats interfering.

I have never considered connecting a Red SPI display to a Mega2560.   You have not even got a proper Mega2560.

I presume that you own 10 1k0 resistors.   Please confirm.
If positive,  I will connect a Red SPI display to a 5V Mega2560 with 1k0 + 1k0 potential dividers.   i.e. I will try it for myself.

David.

coby1kenobi

Sorry about the photo. I'll switch up the wires. 
I only have 7 1k resistors but I do have the TXB0104 shifter. I have attached a photo of it. 


TFTLCDCyg

I have some notes that you should consider, thank you for uploading the photo of the circuit that you have installed in your TFT. Please disconnect it as soon as possible, there are some details that you should know before your TFT suffers irreparable damage!

The resistive voltage divider 5V-3V3, is nothing more than a circuit adapted to achieve that the signal with 5V logic that comes out of the arduino MEGA, is reduced to 3.3V and can be interpreted by the TFT controller without burning it with a voltage that is not correct.

In practical terms, this is the divider that we must build in each TFT control line.



The 5V input signal is the one that comes from each pin of the arduino MEGA, the 3.3V output signal is the one we get from the junction point between R1 and R2. To obtain 3.3V R2 must be twice the value of R1. If R1 = 10K, then R2 is equal to 20K.

Key: the circuit must be built for each control line: CS, RESET, CD, MOSI and SCK

I found some elements to convert the ideas into hardware (if I'm wrong please have an electronics expert correct me!).


After some cuts ... by the way I found the shield with the microSD reader that works in both 5V and 3.3V MCUs, so I will basically focus on the TFT


I took the opportunity to connect the lines of the touch panel to pins 6,5,4,3 and 2, which the URTouch library requires.

These are the 5 circuits that I built in each control line between the MEGA and the TFT, in each one these are the values: R1 = 10K and R2 = 20K (10K + 10K)



Sorry for the roughness of the solder, the soldering iron already has a very damaged tip, for the moment, I have not been able to replace it.

The shield for the TFT has been like this:




The shield with the microSD reader, connected directly to the 5V SPI, does not have voltage dividers




Well ... it was time to connect the MEGA ...

It´s alive!
ft81xmania.com/comunidad/

coby1kenobi

Oh no! I hope it hasn't been damaged.
I made the voltage divider only for the CS and DC pins in junction between 1 1k resistor and another 2 1k resistors. If I'm not mistaken that should reduce the 5v to 3.3v? For the other pins, I used the TXB0104 that I got from https://shopee.ph/product/20469516/826994432

Thank you so much for the instructions on how to make the shield but I'm hoping to keep my project as compact as possible. The screen is to fit tightly inside a casing (this is also why I am using the mega pro instead of the usual one). I also need 10 other pins for 3 sensors + sd card module that will be added to the project. I will post a photo of the casing when it is printed(This will be in 9hrs). But I will attempt to make a shield for the display soon after the project. Your shield looks MEGA

May I know what pin connections you have from the TFT to the mega? Also what software you used to make the schematic? I'd like to make one too for mine to make the connections clearer for all in this forum.

Thanks!


Go Up