Problem with MCUFRIEND 3.5 in. TFT

Hello everybody,
i bought a MCUFRIEND 3.5" TFT LCD for Arduino UNO, but i want to use it by Arduino Mega2560 (because i didn’t find Arduino Mega shield where i’m living)
i downloaded MUUFRIEND_kbv library and opened showBMP_not_Uno example

as it described in it’s comments :

// MCUFRIEND UNO shields have microSD on pins 10, 11, 12, 13
// The official <SD.h> library only works on the hardware SPI pins
// e.g. 11, 12, 13 on a Uno
// e.g. 50, 51, 52 on a Mega2560
// e.g. 74, 75, 76 on a Due
//
// if you are not using a UNO,  you must use Software SPI:
//
// install v1.0.1 of the <SdFat.h> library with the Arduino Library Manager.
// edit the src/SdFatConfig.h file to #define ENABLE_SOFTWARE_SPI_CLASS 1
//
// copy all your BMP files to the root directory on the microSD with your PC
// (or another directory)

so i did this editions to be suitable sketch for arduino mega 2560 :

1- edit SPI pins like this :

SdFatSoftSpi<50, 51,52> SD; //Bit-Bang on the Shield pins

#define SD_CS 53

2- remove SdFat.h and install it’s v1.0.1 and i opened SdFatConfig.h in it’s directory and found the line which wrote #define ENABLE_SOFTWARE_SPI_CLASS 1 and i changed to #define ENABLE_SOFTWARE_SPI_CLASS 0 as the comment said

3-my file name is c.bmp , i copied it (it,s 480*320 pixels) in root directory of microSD Card

my whole edited lines are these lines :

SdFatSoftSpi<50, 51,52> SD; //Bit-Bang on the Shield pins

.....

#define SD_CS     53

#define NAMEMATCH "c"         // "" matches any name
//#define NAMEMATCH "tiger"    // *tiger*.bmp
#define PALETTEDEPTH   8     // support 256-colour Palette

char namebuf[32] = "/";   //BMP files in root directory
//char namebuf[32] = "/bitmaps/";  //BMP directory e.g. files in /bitmaps/*.bmp

and i didn’t edit another lines at all
should i ?

now:
i uploaded it on my Arduino mega 2560 successfully and

i have nothing but blue screen and when i open serial monitor i’ll see this at the end :

Show BMP files on TFT with ID:0x9486
cannot start SD

i’ll appreciate for some help

Go on. Post a link to the actual shield that you bought. e.g. Ebay sale page.

Then plug the shield into your MEGA2560 as Nature intended. i.e. every male pin on the shield should mate with the corresponding female socket.

2- remove SdFat.h and install it's v1.0.1 and i opened SdFatConfig.h in it's directory and found the line which wrote #define ENABLE_SOFTWARE_SPI_CLASS 1 and i changed to #define ENABLE_SOFTWARE_SPI_CLASS 0 as the comment said

Please follow the instructions i.e.

#define ENABLE_SOFTWARE_SPI_CLASS 1

Run the showBMP_not_Uno example i.e. no edits. straight out of the box.

Run all the other examples. They should all work on the MEGA2560 (except for showBMP_kbv_Uno )

David.

@hmdsmit,

Please do not PM me. Especially after I had already replied to your message.

sorry about PM
actually i sent it when i didn't read your reply yet

i bought exactly this shield :

https://www.ebay.com/itm/3-5-inch-TFT-Touch-Screen-LCD-Display-480x320-UNO-R3-Board-For-Arduino-Mega-2560/153567000573?_trkparms=aid%3D1110006%26algo%3DHOMESPLICE.SIM%26ao%3D1%26asc%3D20200520130048%26meid%3Dbfbe53552b3647d3b4541193b80b7412%26pid%3D100005%26rk%3D5%26rkt%3D12%26mehot%3Dpf%26sd%3D391927323339%26itm%3D153567000573%26pmt%3D1%26noa%3D0%26pg%3D2047675%26algv%3DSimplAMLv5PairwiseWebWithBBEV2bDemotion%26brand%3DUnbranded&_trksid=p2047675.c100005.m1851

i tried all examples, all of them worked but unfortunately showBMP_not_Uno and showBMP_kbv_Uno didn't work

then i changed my arduino and tried by another Arduino mega 2560 , then as you told me, connect all male connector to all corresponding female connectors on arduino and i uploaded showBMP_not_Uno sketch without any change on arduino and finally it,s working

Thanks Dear David

I am intrigued. What was your conclusion?

  1. one of the MEGA2560 was faulty.
  2. a shield should plug into the Arduino.

God invented Shields. Shields are designed to plug into the Arduino board header sockets.

David.

actually it seems my first Arduino Mega2560 board was faulty because when i used another Arduino mega2560 board, my problem solved

SD_CS is on pin48 as a default for Mega 2560.

bamboobernie:
SD_CS is on pin48 as a default for Mega 2560.

hmdsmit is using a regular Mcufriend Uno shield i.e. with SD_CS on digital#10 and the SD_DI, SD_DO, SD_SCK on 11, 12, 13

Which is why you have to use Software SPI on a MEGA2560 board. (as described in the example)

Shields designed for a MEGA2560 have an 18x2 header and mostly have SD_CS on digital#53.
The Surenoo shield has SD_CS on digital#48 (because the TOUCH_CS is on #53)

David.

Hi David,
thanks for your help
now i have 10 pictures and when i pressed a key named key1 (Connected on a digital pin) screen must show me pic1 and the same for
key2 .... pic 2
key3 .... pic3
key4 .... pic4
.
.
.
key10 .... pic10
how can i do it?
can you tell me an example for two keys two pics ( then i'll edit it later for using 10 pics) ?
thanks

Go on. Invest in pencil and paper. Write down your ideas. Draw arrows between them.

Then draw a complete Flow Chart.

Translate the Flowchart into program statements.
Run the sketch.

for (int pin = 22; pin < 32; pin++) pinMode(pin, INPUT_PULLUP);


for (int key = 0; key < 10; key++) {
     if (digitalRead(key) == LOW) show(picture[key]);
}

i didn't understand it completely
let me answer the question by another example
imagine i connected two buttons to pins No. 22 & 24 (Button 1 & 2)
if i press button No.1 screen Must Show file c.bmp
&
if i press button No.2 screen Must Show file d.bmp

which lines in Example Sketch named showBMP_not_Uno must be change and how ?

Thanks

no-one can't help me on this ?

Replace the loop() function in showBMP_not_Uno.ino with

char *picture[10] = {
    "/bitmaps/betty_1.bmp",
    "/bitmaps/betty_4.bmp",
    "/bitmaps/marilyn_240x240x8.bmp",
    "/miniwoof.bmp",
    "/tiger.bmp",
    "/bitmaps/tiger_178x160x4.bmp",
    "/tiger_240x317x4.bmp",
    "/tiger_320x200x24.bmp",
    "/tiger16T.bmp",
    "woof.bmp",
};

void loop()
{

    for (int pin = 22; pin < 32; pin++) pinMode(pin, INPUT_PULLUP);

    for (int key = 0; key < 10; key++) {
        if (digitalRead(key + 22) == LOW) showBMP(picture[key], 0, 0);
    }
}

David.

hi David
first of all thanks for answer the questions,

actually i forced to change my instuctions and now i,m not able to show images by keys,
now i have to act like this:

i have some variables :
a, b, c, d, ...

when a == 1 :
show "tiger.bmp"

when b == 1:
show "test.bmp"

.
.
.

how can i do that ?

actually i figured out that in wxample in showBMP_not_UNO.ino the line :

#define NAMEMATCH ""

provide the names of file and then the line :

File f = root.openNextFile()

open them one by one after each other

how can i change the code to open the exact file that i want to open it when it's variable changes to 1 (from 0)

Thanks

Go to the shop.
Buy pencil and paper.
Buy some tea bags.

Sit down with a nice cup of tea.
Write your program on paper.

Drink another nice cup of tea.
Check your program. e.g. by drawing arrows on the paper to trace the flow.

Type the paper program into your PC. Run the Arduino sketch.

Celebrate with a nice cup of tea and a biscuit.

David.