Wiring question for 2.8 touch tft to mega

Per this webpage:

It talks about hooking up a CCS pin to digital pin 4 on the Uno, to be able to access the sd card in the display. On the mega, this pin is not the same (I presume) because it's mapped to a PWM pin rather than a plain old digital pin.

Can anyone tell me which Mega pin correlates to the Uno Pin 4 they want you to connect OR can you simply redefine the pin to be whatever you want? Either way, I'm stuck not knowing which pin I need to connect on the Mega because it's not in the instructions.

Thank you.

I am going to work on MEGA next, but in the mean time, it might be helpful to know that I got the TFT I bought from amazon (both the 2.8 and the 3.5) to work with a Nano:

2.8" -> https://www.amazon.com/gp/product/B01EUVJYME/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
3.5" -> https://www.amazon.com/gp/product/B075FP83V5/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

I wired it like this (I listed the pins counter-clockwise from the USB connector)

NANO TFT
D13 SD_SCK
3v3 nothing
Ref Nothign (probably should connect to 5v)
A0 LCD_RD
A1 LCD_RW
A2 LCD_RS
A3 LCD_CS
A4 LCD RST
A5 Analog1
A6 Analog2
A7 Analog3
5V 5V
RST (wired to 3v3, but I think it is wrong)
GND GND
Vin nothing

TX1 nothing
RX0 Nothign
RST nothing
GND nothing (probably should be grounded)
D2 LCD_D2
D3 LCD_D3
D4 LCD_D4
D5 LCD_D5
D6 LCD_D6
D7 LCD_D7
D8 LCD_D0
D9 LCD_D1
D10 SD_SS
D11 SD_Di
D12 SD_Do

I have not seen this documentation anywhere else on this forum, so I am starting here!

Gahhhrrrlic:
Per this webpage:

Bitmaps (SPI Mode) | Adafruit 2.8" and 3.2" Color TFT Touchscreen Breakout v2 | Adafruit Learning System

It talks about hooking up a CCS pin to digital pin 4 on the Uno, to be able to access the sd card in the display. On the mega, this pin is not the same (I presume) because it's mapped to a PWM pin rather than a plain old digital pin.

Can anyone tell me which Mega pin correlates to the Uno Pin 4 they want you to connect OR can you simply redefine the pin to be whatever you want? Either way, I'm stuck not knowing which pin I need to connect on the Mega because it's not in the instructions.

Thank you.

the Arduino UNO pins map directly to the Arduino Mega pins.
They have to map directly else all the Arduino Shields would not work.

the Arduino UNO pins map directly to the Arduino Mega pins.
They have to map directly else all the Arduino Shields would not work.

Incorrect assumption, there is no pin for pin compatibility for hardware SPI.

From the comments in the Adafruit SD library examples:

  • SD card attached to SPI bus as follows:

** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed) and pin #10 (SS) must be an output

** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed) and pin #52 (SS) must be an output

** Leonardo: Connect to hardware SPI via the ICSP header

Your 2.8" shield is a regular "Blue 2.8 inch Mcufriend" 240x320
Your 3.5" shield is a regular "Blue 3.5 inch Mcufriend" 320x480

Both will plug into regular Uno, Mega, Zero, Due, ...

Both will work with MCUFRIEND_kbv library.

The Touch will work on all Arduinos.
The microSD will work on a Uno.

The microSD will only work on a Mega2560 if you install (and configure) the SdFat library from the Library Manager.

David.

I am also experiencing the problem with a TFT on MEGA reading the SD Card.

I am using the display I bought from Amazon:

It comes with a CD and the example file called "Example07-ShowBMP"

This would always say "SD Card Init Fail" and "Didn't find BMPimage"

I saw posts saying that wiring needs to be changed because the TFT display pins are not connected to the SPI pins of the Mega. The post gives old and new pin numbers, but it implies that they should be connected in order, which is NOT the case. Connecting the pins in this order gave better results:

OLD pin NEW pin
11 51 (MOSI) (Master Out, Slave In for SPI)
12 50 (MISO) (Master In, Slave Out for SPI)
13 52 (SCK) (Clock for SPI)

I left pin 10 (SD_SS Chip select) alone. I also noted that while the example program creates a variable for the chip select pin (called "PIN_SD_CS") later in the code, it hard codes pin 10 as the chip select pin. If you ever decide to use a different pin for chip select, that is worth noting.

I did my victory dance (link to video omitted) when I uploaded the program and it displayed the sample images from the SD card.

However, my heard sank when I cycled power. It seems to only work right after uploading, but never again after power cycle. :frowning:

I will keep investigating, but maybe someone knows why that might be happening?

Shields are designed to mate as Nature intended.

This means that you have to bit-bang the SPI on pins 11,12,13 for Mega, Due.
Install the SdFat library with the Library Manager. And configure it.

I provide examples that use SdFat on a Mega.
You say that your shield came with a CD. Either provide a link or attach the problem sketch to your message.

Yes, you can hand-wire the shield to the hardware SPI pins but it defeats the convenience of well-mated mechanical/electrical connections. Especially since the software SD works ok.

Historically the official SD.h library could be configured for software on 11,12,13 on a Mega.
The current SD library has lost this feature.

David.

Thank you David for pointing me to the SDFat Library.
I saw some other posts that warned that bit-banging the SPI might be too slow (although I cant imagine that being the case) so I am interested in seeing the difference.
I will go back and try that.

In the mean time, I had some divine inspiration and set the pin mode on pins 11,12,& 13 force them to INPUTS before the SD.begin() call, and now it is working fine. I surmise that re-uploading forces the pins to inputs, but something later turns them to outputs and saves that information after re-booting, thus messing up the SPI communications only after a power cycle.

Thank you for your help, and I also hope "Gahhhrrrlic" found a resolution that meets their needs.

Another update on my progress (Not necessarily looking for help).

I loaded the SDFat library and configured it (as recommended above).
To learn how to use it, I copied the pertinent information from the example file called "SoftwareSpi.ino".
The beginning of this file has "#include <SPI.h>".

I am using the example file that came on a CD with my display called "Example07-ShowBMP" (as mentioned above), so I copied and pasted the pertinent lines from the "SoftwareSpi.ino" file into the "Example07-ShowBMP" and tried to run it.

It took a lot of head banging to realize the line #include <SPI.h> must be commented out, otherwise it will always result in an "initialization failed" error when executing this function:

if (!SD.begin(SD_CHIP_SELECT_PIN)) {
Serial.println("initialization failed!");
tft.setCursor(0, 0);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.println("SD Card Init fail.");
}else
Serial.println("initialization done.");

It seems that the SDFat provides its own SPI, and the SPI.h was pushing it to use the hardware SPI, so It could never dial into the software SPI.

I still had issues after fixing this issue with this example file. It seems the bmpReadheader(File f) function has issues with the SDFat library. If I comment out the call to that function, the bitmaps are displayed, but they are shifted to the right by about 10 pixels.

I compared the serial values that are printed between the previously mentioned NANO connected to this display with hardware SPI and default SD library compared to the exact same display and SD card connected to a MEGA and using the SDFat.h file. I am including that serial output here:

NANO:
TFT LCD test
Found 0x9486 LCD driver
TFT size is 320x480
initialization done.
size 0x38436
offset 54
header size 40
bitdepth 24
compression 40
4830 ms

MEGA:
TFT LCD test
Found 0x9486 LCD driver
TFT size is 320x480
initialization done.
size 0x4D424D42
offset 66
header size 1296190786
bad bmp

I have attached the example program to this post, but I will continue pursuing this on my own.

I hope to add some serial print lines and try different things and look into the SDFat library and see if I can figure out what is going on. I am also convinced the example program I am using is not very well written, as I tried to change the size of the display and found that while they made height and width variables at the top of the program, they did not use those variables inside the function to allow the different sized displays to be easily used. I'm sure the SDFat library is fine, but it is not a plug and play with this particular display's example programs. Once I get it resolved, I intend to post better example software on the Amazon page where I bought the display. I like the display, but I must think this would annoy many customers.

I will post again if I make more progress.

ShowBMP.ino (8.77 KB)

Your attached sketch is a mish-mash of stuff put together without any thought.

Your 2.8" shield is a regular "Blue 2.8 inch Mcufriend" 240x320 --- probably ILI9341
Your 3.5" shield is a regular "Blue 3.5 inch Mcufriend" 320x480 --- probably ILI9486

I provide some examples with MCUFRIEND_kbv library. Some are quite complex.
Adafruit provide examples with the Adafrut_TFTLCD library. Probably simpler and easier to understand.

Most sketches and examples will work with either library e.g. both support ILI9341
I don't think the official Adafruit supports ILI9486.
Avoid hacked libraries that are not available through the Library Manager.

I suggest that you start with proven examples first. Then adapt and modify to suit your needs. Try to keep everything simple e.g. only modify one small step at a time.

Only include necessary headers. e.g. Adafruit_TFTLCD.h or MCUFRIEND_kbv.h
If you are not using the TouchScreen, don't include TouchScreen.h

If you want help, attach or link to the original example sketch e.g. from your CD.

David.

I take exception to your comment of "Your attached sketch is a mish-mash of stuff put together without any thought." There is a difference between not knowing and not thinking. I am sure you assist a lot of people that ask questions that spawn from not knowing what to ask. If that is annoying to you, maybe you would find more joy in another hobby.... I am sure you are not trying to convince people that the Arduino forums are a hostile environment, but this type of comment sure makes it feel that way. I know you are not my "mommy", but there is no need to be rude.

I agree the sketch I posted is not great, but it is from the vender of the display. The vender of my display claimed it was "Compatible with UNO and Arduino Mega2560 development board directly, no any wiring needed." I don't have enough knowledge or experience to find something better than the vendor provides, as I assume the vender to be the expert on the vendor's products. The alterations made to the vendor's example have been taken from other expert's example files. I have not yet found any sketches designed for this display and the Mega that work. So I have to piece through that. Once I get to your heightened level of knowledge and experience I will be able to write these things from scratch without having to pull pieces from other people's examples.

You were kind enough to point me to the SDFat Library, and I was trying to let everyone know that just using that library wont get a newbie (me) where I need to be (the bitmap from the card displays correctly on the display).

If you find me annoying, I will not take any Karma points away from you if you no longer respond to my posts.

Sorry, I was just being honest. There is nothing for a learner to be ashamed of. But I do think a Vendor should not broadcast that sort of code.

There are a whole range of sketches and examples on the internet. Some better than others. Some truly appalling.

I was trying to point you towards Adafruit. They generally have pretty good stuff. Of course it means that they are often the first choice for people to "adapt".

So it is wise to check carefully that "Adafruit" code has actually come from Adafruit and not some random hacker.

David.

Thank you for your reply.

I will try to steer clear of the adapted versions.

So, when all is said and done - How do I get either of my 2 GENUINE Arduino Megas to connect to any of my 3 off 2.8" TFT and show anything other than a white screen. The TFT screens work quite happily with my UNOs, both genuine and clone.

Post a link to the 2.8 inch screen.

If it works on a Uno it should work on a Mega.

Have you checked your library version via the IDE Library Manager?
e.g. Sketch->Include Library->Manage Libraries...

David.

If you want to access the SD card from a Mega with a tft Mcufriend shield some shields have these holes off to one side User Manual For 2.8" TFT Touch Shield for Arduino with Resistive Touch Screen (TF028) - PDF Free Download. After playing around I found that you can connect to the SD card by connecting pins 50-53 to the holes labeled in the JPG attached

Yes, you can connect pins 11-13 on the Shield to pins 50-52 on a MEGA2560.

It is RISKY. This only works if 11-13 are INPUT mode. Otherwise the Port output pins are fighting.

Much safer to use Software SPI as in example.

David.

PIN 53 is the CS Pin on a Mega

Yes, you can connect digital #10 to digital #53 too.
This will ensure another output BATTLE