ELEGOO 2.8 TFT with SD card and ARDUINO MEGA - accessing SD CARD

As the subject declares I am trying to access the SD card of the ELEGOO 2.8 TFT shield installed as a shield on a Arduino Mega. I found very confusing information while searching around probably confusing because I am just a fledgling with Arduino and its jargon.
I have figured out that Mega uses pins 51 t o 53 for comunicating with the SD card while the shield is for ARDUINO UNO that uses 10 to 13# insteaad.

I downloaded SDfat library and MCCUFRIEND_kbv. TRied to follow the instructions I found around but when I try to run the sketch named "showBMP_not_UNO" it keeps getting me the following error message

'SdFatSoftSpi' does not name a type; did you mean 'SdFatConfig_h'?

Can anyone provide a step-by-step guidance for a workaround?

Thanks in advance.
TRying to learn

SCud

Did you install the SdFat.h library via the Library Manager ?

The instructions in the example were written a few years ago. If you have a problem, please quote the SdFat.h version number (from the Library Manager)

David.

Thanks David
it is version 2.
In the readme file There is an explicit warning highlighting that it is version 2 while version 1 is available at a specific link

Thanks for the feedback. My instructions were correct for SdFat.h v1.x
SdFat.h v2.x works differently

Please edit your showBMP_not_Uno example

#include <SPI.h>             // f.k. for Arduino-1.5.2
#define USE_SDFAT
#include <SdFat.h>           // Use the SdFat library
////SdFat.h v1.x - edit SdFatConfg.h : #define ENABLE_SOFTWARE_SPI_CLASS 1
//SdFatSoftSpi<12, 11, 13> SD; //Bit-Bang on the Shield pins SDFat.h v1
//#define SD_CS 10
////SdFat.h v2.x - edit SdFatConfg.h : #define SPI_DRIVER_SELECT 2
SoftSpiDriver<12, 11, 13> softSpi; //Bit-Bang on the Shield pins SDFat.h v1
#define SD_CS SdSpiConfig(10, DEDICATED_SPI, SD_SCK_MHZ(0), &softSpi)
SdFat SD;

#include <Adafruit_GFX.h>    // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

//#define SD_CS     10   //remember to comment this original define

In other words. The v1.x sequence was two statements. i.e. constructor and SD_CS define
The v2.x sequence works differently and needs three statements. i.e. two different constructors + complex SD_CS define

Please report back. Only tested with 8GB SD.

Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.13\hardware\arduino\avr\libraries\SPI 
Using library SdFat at version 2.0.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\SdFat 
Using library Adafruit_GFX_Library at version 1.10.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Mcufriend_kbv at version 2.9.9-Release in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv 
Using library Adafruit_BusIO at version 1.6.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.13\hardware\arduino\avr\libraries\Wire 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_497204/showBMP_not_Uno.ino.elf"
Sketch uses 31366 bytes (12%) of program storage space. Maximum is 253952 bytes.
Global variables use 1152 bytes (14%) of dynamic memory, leaving 7040 bytes for local variables. Maximum is 8192 bytes.

David.

I'll be damned! You nailed it! Works like a charm now and reads the SD card flawlwssly. Thank you.
In your opinion should I watch out for some specific issues when trying to write data on the SD card?

Thanks again

What size SD cards are you using?

I would expect 1MB - 32GB to work.

If you can report back, I will change the example code in the Beta.
Then issue a new Release. I can't expect people to use an "old" SdFat.h

I own a MEGA2560 but I very seldom use it.

David.

I think the SD card is 32Gb but I need to double check. Anyway I'll be glad to buy a card that just works eventually.

Let me make some changes in my original sketch. Basically it is a garden-variety of a barograph project using this Elegoo 2.6 tft display and a BME280 pressure/humidity/temperature sensor with a buzzer alarming for fast drop in pressure levels. Sketch is too large for a Arduino Uno so I am forced to use Mega2560/R3.

The sketch needs to write the pressure readings on the SD card.
I'll certainly report the outcomes of my trying

Thanks once more
Scud

Hello David

I am glad to report to you that I finally can read / write records in files stored on the SD card.
Your fix proved resolutive and final

Thanks

I have updated the Beta on GitHub. You can find the example sketch at MCUFRIEND_kbv/showBMP_not_Uno.ino at master · prenticedavid/MCUFRIEND_kbv · GitHub

It expects you to read the notes about installing SdFat.h v2

David.

Hi David, ive been having the same problems as Scud63 above and ended up using your code and it worked perfectly
(thank you by the way). But ive now started tinkering with it and came across another problem i have copied the void loop contents into the void setup section at the end... my reasoning being i wanted the picture open only once, but its coming up with an error "showBMP was not declared in this scope" i was presuming one of the included .h files declares this specifically for the void loop but i cant find it anywhere.
Is there any other way to work out where the problem bit is or just looking through files and try to make them global variables?

Attach your INO file. Then I can see what you have done.

thats it there.
thanks.

showBMP01.ino (10.4 KB)

Your indentation is mismatched.

It is always a good idea to format your code e.g. with ctrl-T

This will immediately show where the problem is.

Regarding your requirement.

  1. you need showBMP(), read16() and read32() functions.
  2. you can just change the last few lines of setup() e.g. from
    ...
    if (!good) {
        Serial.print(F("cannot start SD"));
        while (1);
    }
    root = SD.open(namebuf);
    pathlen = strlen(namebuf);
}

to

    ...
    if (!good) {
        Serial.print(F("cannot start SD"));
        while (1);
    }
    showBMP("/woof.bmp", 0, 0);  //Oops,  I forgot the x, y arguments
}
  1. and make an empty loop()

Seriously. It is worth investing in pencil and paper. Draw a flow diagram for any Arduino sketch. It is:

void setup()
{
    //do something only once
}

void loop()
{
    //do this on every pass of loop()
}

David.

Edit. Corrected code, I had forgot the x, y arguments

Regarding your requirement.

  1. you need showBMP(), read16() and read32() functions.

sorry again, this is probably a daft question but how do i do that? ive looked through the sketch and through as many of the .h and .cpp files as are attached to find a base function to declare these as but cant find anything.
ive done points 2. and 3.
Daryn

Have you bought a pencil yet?

My apologies if you are only 16. I am happy to help a school student.

If you are an adult, please study the code and see how to do it with pencil and paper by yourself.

David.

This topic was automatically closed after 120 days. New replies are no longer allowed.