Defining 2 SD card conflicts

I have a Mega with an Adafruit Datalogging shield and using a 3.5 TFT touch screen. On the TFT display is an SD card that I have a bit map that I load in as a background on the display. All of that is working. I had a second sketch that worked to datalog info but that sketch did not use the TFT. I am now trying to incorporate the datalogging shield which also has an SD card into the sketch that has the TFT. I am getting some errors. I believe the first couple of errors were because both sketches use "SD" to define the cards. So I changed the ones that are for the TFT card to "SD_TFT" I did notice that in the lines that I changed, "Adafruit_ImageReader reader(SD_TFT)" for example, that "SD" was red and now that I've changed it it is not.

So now when I compile I get the following error.

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:10:0:

C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:23:0: warning: "FILE_READ" redefined

 #define FILE_READ O_READ

 ^

In file included from C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/FatLib/FatLib.h:27:0,

                 from C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/SdFat.h:33,

                 from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:7:

C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/FatLib/ArduinoFiles.h:37:0: note: this is the location of the previous definition

 #define FILE_READ O_RDONLY

 ^

In file included from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:10:0:

C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:24:0: warning: "FILE_WRITE" redefined

 #define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_APPEND)

 ^

In file included from C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/FatLib/FatLib.h:27:0,

                 from C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/SdFat.h:33,

                 from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:7:

C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/FatLib/ArduinoFiles.h:39:0: note: this is the location of the previous definition

 #define FILE_WRITE (O_RDWR | O_CREAT | O_AT_END)

 ^

In file included from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:8:0:

C:\Users\lampo\Documents\Arduino\libraries\Adafruit_SPIFlash\src/Adafruit_SPIFlash.h:75:26: warning: integer overflow in expression [-Woverflow]

   SFLASH_BLOCK_SIZE  = 64*1024,

                          ^

C:\Users\lampo\Documents\Arduino\libraries\Adafruit_SPIFlash\src/Adafruit_SPIFlash.h:75:27: warning: overflow in constant expression [-fpermissive]

   SFLASH_BLOCK_SIZE  = 64*1024,

                           ^

In file included from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:10:0:

C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:62:3: error: 'SdVolume' does not name a type

   SdVolume volume;

   ^

C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:70:33: error: 'SD_CHIP_SELECT_PIN' was not declared in this scope

   boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);

                                 ^

Eoflow_Demo:69:1: error: reference to 'File' is ambiguous

 File logfile;

 ^

In file included from C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/FatLib/FatLib.h:27:0,

                 from C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/SdFat.h:33,

                 from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:7:

C:\Users\lampo\Documents\Arduino\libraries\SdFat\src/FatLib/ArduinoFiles.h:122:7: note: candidates are: class File

 class File : public FatFile, public Stream {

       ^

In file included from C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:10:0:

C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:28:7: note:                 class SDLib::File

 class File : public Stream {

       ^

C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino: In function 'void setup()':

Eoflow_Demo:189:7: error: 'logfile' was not declared in this scope

       logfile = SD.open(filename, FILE_WRITE); 

       ^

C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino: In function 'void loop()':

Eoflow_Demo:347:13: error: 'Pump_Test' was not declared in this scope

   Pump_Test();

             ^

C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino: In function 'void drawHomeScreen()':

C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino:393:48: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   stat = reader.drawBMP("/logo2.bmp", tft, 0, 0);

                                                ^

C:\Users\lampo\Documents\Arduino\EoFlow\Eoflow_Demo\Eoflow_Demo.ino: In function 'void ReadBatt()':

Eoflow_Demo:628:1: error: a function-definition is not allowed here before '{' token

 {

 ^

Pump_Test:2:1: error: a function-definition is not allowed here before '{' token

 {

 ^

Pump_Test:95:1: error: expected '}' at end of input

 } // end void Pump_Test

 ^

exit status 1
reference to 'File' is ambiguous

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I've exceeded the number of characters allowed so I can only but the definitions I think apply here and part of the void setup.

#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"
#include "TouchScreen.h"
#include <SdFat.h>                // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h>    // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

// These are 'flexible' lines that can be changed
#define TFT_CS 26
#define TFT_DC 27
#define SD_CS  24
#define TFT_RST -1  // dont use a reset pin, tie to arduino RST if you like
//#define TFT_RST 8 // RST can be set to -1 if you tie it to Arduino's reset

SdFat                SD_TFT;         // SD card filesystem
Adafruit_ImageReader reader(SD_TFT); // Image-reader object, pass in SD filesys
Adafruit_Image         img;        // An image loaded into RAM
int32_t                width  = 480, // BMP image dimensions
                       height = 320;

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;


void setup(void) {


    // The Adafruit_ImageReader constructor call (above, before setup())
  // accepts an uninitialized SdFat or FatFileSystem object. This MUST
  // BE INITIALIZED before using any of the image reader functions!
  Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
  // SD card is pretty straightforward, a single call...
  if(!SD_TFT.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit
    Serial.println(F("SD begin() failed"));
    for(;;); // Fatal error, do not continue
  }
#else
  // SPI or QSPI flash requires two steps, one to access the bare flash
  // memory itself, then the second to access the filesystem within...
  if(!flash.begin()) {
    Serial.println(F("flash begin() failed"));
    for(;;);
  }
  if(!filesys.begin(&flash)) {
    Serial.println(F("filesys begin() failed"));
    for(;;);
  }
#endif
  Serial.println(F("OK!"));

   // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
  //  error("Card failed, or not present");
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }

Thanks so much for any help
John

I would try to put the background bitmap on the logging card and don't use the TFT card slot. Or the other way around.

The error message looks like it is #include'ing two different copies of the same library. But I cant see in your #include's why that is happening.

You should use only one SD library. It looks like you have at least three:

Built-in library: SD
Installed library: libraries\SD
Installed library: libraries\SdFat

I would get rid of the two installed SD libraries and use the built-in SD library. Just move those two folders out of the 'libraries' folder. Then you can modify the sketch, if necessary, to work with the built-in library. This will allow your sketch to work on the largest number of platforms if you ever want to migrate.

I knew I was double dipping somewhere just wasn't sure of where. I am including 2 SD libraries

SdFat.h, this is the one that the TFT uses and
SD.h, I believe this is the standard one that the datalogging shield is using.

I only have 1 bitmap I'm using and I believe I can put that into the flash memory on the TFT.

Thanks for the help
John