I know this is a recurrent question...but still is very hard to find some working sketch.
I already tried tens of samples, with differente libraries (UTFT, Arduino, MCUFriend, HT...something), but all of these give some sort of errors possibly due to the various dependencies required and/or for a wrong pin definition.
In example: into the sketch 'showBMP_not_uno' from MCUFriend I do not understand these roes:
SoftSpiDriver<50,51,52> softSpi; //Bit-Bang on the Shield pins SDFat.h v2
SdFat SD;
#define SD_CS SdSpiConfig(10, DEDICATED_SPI, SD_SCK_MHZ(0), &softSpi)
I mean, where the pin 10 comes from? Is it correct for my HW?
I try to attach a picture of my TFT module; I see 4 lines going from the SD to pins 16,17,18,19.
Should I redefine the pins (where)? Specifically, how to define the CS pin?
Thanks
I'm sorry, I got the wrong pins from the picture; actually you are right, the pins are 10,11,12,13, so this section should be correct:
SoftSpiDriver<12, 11, 13> softSpi; //Bit-Bang on the Shield pins SDFat.h v2
SdFat SD;
#define SD_CS SdSpiConfig(10, DEDICATED_SPI, SD_SCK_MHZ(0), &softSpi)
I downloaded a fresh copy of the sketch and I just modified the bmp file name.
The SPI_DRIVER_SELECT is 2.
Your note is not clear to me.:
`SD_CS` should be named e.g. `SD_BEGIN_PARAMETER` to be understandable.
Question: I got the SdFatConfig.h, SdSpiDriver.h and sdios.h files from GitHub as standalone files, copied inside the sketch's folder. I'm not sure this is the correct mode, but I do not know any other method since there was not a zip folder containing all these libraries. Anyway, the IDE shows them, togheter with SdFat.h in the top files bar and I was able to change the SPI_DRIVER_SELECT to 2.
Compiling the '#if SPI_DRIVER_SELECT != 2' test is correct.
The final result is this on the serial monitor:
Show BMP files on TFT with ID:0x9486
cannot start SD
Ok, I see you are missing some fundamental knowledge about use of libraries with the Arduino IDE.
There are libraries that are "known" by the Library Manager of the Arduino IDE. These should always be installed using the Library manager. SdFat and MCUFriend_kbv fall into that category. Just open Library Manager, type in the library name in the search box, and install.
Other, less common, libraries, may be available on GitHub. These can be downloaded as ZIP files, and then installed with the Library Manager using Add .ZIP Library....
Libraries should only be copied to the libraries folder, if there is no other means. Never copy just single files from a library. Most likely this will then not compile.
BTW: I think there are tutorials about this.
Jean-Marc
I did not understand that piece of code in your post. I had to look at both libraries to find out.
Originally, the method begin() of SdFat took a pin number as parameter for the CS pin.
This method still exists.
But now there is an additional (overloaded) method:
Well, thanks for yuor support; as you see I'm new to Arduino.
I studied the tutorial and wow the libraries handling is much clear; I decided to insert the SDfat zipped folder inside my sketchbook after the mod to the SdFatConfig.h to change the SPI_DRIVER_SELECT=2. and then I added the zipped library; now I see it in the menu.
A secondary note: then sentence
'SD_CSshould be named e.g.SD_BEGIN_PARAMETER` to be understandable'
was in your first replay, not in the code...anyway, let's forget it.
Now, every should be correct, I hope, but actually the program still does not proceed.
I added a debug message into the setup to print the SPI_DRIVER_SELECT, correct, and the SD_CS parameter, with an absurd value (I was expecting 10); this is the output I get:
SPI_Driver_Select=2, SD_CS=266
Show BMP files on TFT with ID:0x9486
cannot start SD
It seems that the problem is in this piece of code:
The meaning of SD_CS was not immediately clear. David should have used a different name. SD_CS is an instance of the class SdSpiConfig, constructed with four parameters.
I would not have expected you can Serial.print(SD_CS), I'd expected a compiler error.
Did you put an SD card into the SD card holder, preformatted with Fat filesystem?
For the example it should have a copy of tiger.BMP, or any other BMP file(s).
I think I have to give up with the SD.
I tried almost everything I found in the example; even the simpler (and usuful I believe) which is the QuickStart.ino inside the SDfat examples folder fails, testing with CS=10 as in:
The fact is that I never pass then initialization phase, The test sketch always returns with
errorCode: 0x2b, errorData: 0x0
regardless of any mod attempt.
The SD is formatted in Fat32, with 3 bmp files; my PC reads and writes correctly the SD; unfortunately I do not have another SD to try, but I do not think the problem is with the card.
QuickStart.ino may not work with SW SPI, but I am not sure.
You may need to configure SdFat for Fat32, but I don't know.
I am confident that MCUFriend_kbv and showBMP_not_Uno.ino should work correctly on Arduino MEGA with your display.
My TFT displays are not yet stored in a sorted way, so I don't know if I have this display.
Something magical happened !
I finally got some pics on the screen, but..
Firstly I made a loop in the SD initialization phase; I discovered that the very first attempt always fails. Typically it takes 2 or 3 retry before the bmp appears.
After I saw the first image I was so happy....but then...
I think to have an hardware problem somewhere since sometimes the show does not start even after tens of attempts. Moving slightly up and down the display board over the Mega seems to fix the problem. So, it works, but is unreliable. Now I ordered an SD breakout to test the SPI communication with Mega without the display, using the SD as a datalogger.
Thanks for your help.