I am using an Arduino Mega 2560 with a Treedix 3.5" TFT shield. I put an SD card (Formatted to FAT32) in it and attempted to use "SD.begin(10)", but it's returning false. I have both the SD.h and SPI.h included. I've scoured the internet and have not found any working solution, thanks!
@amsquid
Welcome!
You can try
if (!SD.begin(10, 11, 12, 13)) {
Serial.println("Card failed, or not present");
}
And let me know how that goes.
Can you post a link to the exact screen you have?
Also please post your code.
It's bringing up this error, "no matching function for call to 'SDLib::SDClass::begin(int, int, int, int)'"
Here's the code:
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <SoftwareReset.hpp>
#include <SPI.h>
#include <SD.h>
MCUFRIEND_kbv tft;
#define A 49
#define B 51
#define C 53
#if defined(ESP32)
#define CS 5
#else
#define CS 10
#endif
int menu = 0;
int option = 0;
int maxOptions = 1;
int background = TFT_BLUE;
int foreground = TFT_WHITE;
int consoleBackground = TFT_BLACK;
int consoleForeground = TFT_WHITE;
int buttonsDown[] = {};
void settingsTop() {
tft.fillScreen(background);
tft.setTextColor(foreground, background);
tft.setCursor(0,0);
tft.setTextSize(3);
tft.println("Startup");
}
void settings() {
tft.setTextSize(2);
if(option == 0) {
tft.setTextColor(background, foreground);
} else {
tft.setTextColor(foreground, background);
}
tft.setCursor(0, 32);
tft.println("Reset Arduino");
if(option == 1) {
tft.setTextColor(background, foreground);
} else {
tft.setTextColor(foreground, background);
}
tft.setCursor(0, 56);
tft.println("Boot to SD Card");
}
void boot() {
tft.setCursor(0, 0);
tft.setTextColor(consoleForeground, consoleBackground);
tft.setTextSize(1);
Serial.println("Attempting to init sd");
tft.print("Initializing card on pin ");
tft.println(CS);
if (!SD.begin(CS)) {
Serial.println("Card failed, or not present");
tft.println("SD reading failed");
tft.println("Resetting in 5 seconds...");
delay(5000);
softwareReset::standard();
} else {
tft.println("Read SD successfully!");
}
}
void refresh() {
settings();
}
/*
===============
ARDUINO FUNCTIONS
===============
*/
void setup() {
// Serial
Serial.begin(9600);
// Pin Modes
pinMode(A, INPUT_PULLUP);
pinMode(B, INPUT_PULLUP);
pinMode(C, INPUT_PULLUP);
pinMode(CS, OUTPUT);
// TFT
Serial.println("Resetting TFT");
tft.reset();
uint16_t identifier = tft.readID();
if (identifier == 0xEFEF) identifier = 0x9486;
tft.begin(identifier);
tft.setRotation(1);
tft.setTextSize(2);
// Startup
settingsTop();
refresh();
}
void loop() {
int ARead = digitalRead(A);
int BRead = digitalRead(B);
int CRead = digitalRead(C);
if(ARead == LOW) {
if(!(buttonsDown[A])) {
buttonsDown[A] = true;
if(menu == 0) {
if(option > 0) {
option--;
refresh();
}
}
}
} else {
buttonsDown[A] = false;
}
if(BRead == LOW) {
if(!(buttonsDown[B])) {
buttonsDown[B] = true;
if(menu == 0) {
switch(option) {
case 0:
tft.setCursor(0, 0);
tft.setTextColor(consoleForeground, consoleBackground);
tft.setTextSize(1);
tft.println("Resetting");
softwareReset::standard();
break;
case 1:
boot();
break;
}
}
}
} else {
buttonsDown[B] = false;
}
if(CRead == LOW) {
if(!(buttonsDown[C])) {
buttonsDown[C] = true;
if(menu == 0) {
if(option < maxOptions) {
option++;
refresh();
}
}
}
} else {
buttonsDown[C] = false;
}
}
That's the old code, I copied and pasted your code and it brought that error.
@amsquid
Can you post a link to the exact screen you have please?
Where did you get that SD library? Was it downloaded from the library manager, or elsewhere?
It is just the default SD library built into Arduino IDE.
If by the screen you mean what shows on the TFT, it just shows the error messages I put into the if statement.
"SD reading failed"
"Resetting in 5 seconds..."
Here is an image of it...
@amsquid
No. I mean the ebay link or whatever store you got it at. I need a screen datasheet, or at least a model number.
If it was the default SD library it would not say:
Can you tell me who wrote the library (op[en the library manager and see what the authors name is)?
Is it this one:
Did you use pins 50, 51 and 52?
Here's the WIKI that was linked with the TFT: 3.5inch Arduino Display-UNO - LCD wiki.
Here's the amazon page: https://www.amazon.com/dp/B0872S57HG
The author line says the following: Built-In by Arduino Version 1.2.4 INSTALLED
I checked the SD_SS pin (CS pin according to LCD Wiki) and unless I'm mistaken, it is on pin 10.
@amsquid
I rewrote this:
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <SPI.h>
#include <SD.h>
MCUFRIEND_kbv tft;
#define A 49
#define B 51
#define C 53
#if defined(ESP32)
#define CS 5
#else
#define CS 10
#endif
int menu = 0;
int option = 0;
int maxOptions = 1;
int background = TFT_BLUE;
int foreground = TFT_WHITE;
int consoleBackground = TFT_BLACK;
int consoleForeground = TFT_WHITE;
int buttonsDown[] = {};
void settingsTop() {
tft.fillScreen(background);
tft.setTextColor(foreground, background);
tft.setCursor(0, 0);
tft.setTextSize(3);
tft.println("Startup");
}
void settings() {
tft.setTextSize(2);
if (option == 0) {
tft.setTextColor(background, foreground);
} else {
tft.setTextColor(foreground, background);
}
tft.setCursor(0, 32);
tft.println("Reset Arduino");
if (option == 1) {
tft.setTextColor(background, foreground);
} else {
tft.setTextColor(foreground, background);
}
tft.setCursor(0, 56);
tft.println("Boot to SD Card");
}
void boot() {
tft.setCursor(0, 0);
tft.setTextColor(consoleForeground, consoleBackground);
tft.setTextSize(1);
Serial.println("Attempting to init sd");
tft.print("Initializing card on pin ");
tft.println(CS);
if (!SD.begin(10, 11, 12, 13)) {
Serial.println("Card failed, or not present");
tft.println("SD reading failed");
tft.println("Resetting in 5 seconds...");
delay(5000);
} else {
tft.println("Read SD successfully!");
}
}
void refresh() {
settings();
}
/*
===============
ARDUINO FUNCTIONS
===============
*/
void setup() {
// Serial
Serial.begin(9600);
// Pin Modes
pinMode(A, INPUT_PULLUP);
pinMode(B, INPUT_PULLUP);
pinMode(C, INPUT_PULLUP);
pinMode(CS, OUTPUT);
// TFT
Serial.println("Resetting TFT");
tft.reset();
uint16_t identifier = tft.readID();
if (identifier == 0xEFEF) identifier = 0x9486;
tft.begin(0x9488);
tft.setRotation(1);
tft.setTextSize(2);
// Startup
settingsTop();
refresh();
delay(2000);
boot();
}
void loop() {
int ARead = digitalRead(A);
int BRead = digitalRead(B);
int CRead = digitalRead(C);
if (ARead == LOW) {
if (!(buttonsDown[A])) {
buttonsDown[A] = true;
if (menu == 0) {
if (option > 0) {
option--;
refresh();
}
}
}
} else {
buttonsDown[A] = false;
}
if (BRead == LOW) {
if (!(buttonsDown[B])) {
buttonsDown[B] = true;
if (menu == 0) {
switch (option) {
case 0:
tft.setCursor(0, 0);
tft.setTextColor(consoleForeground, consoleBackground);
tft.setTextSize(1);
tft.println("Resetting");
break;
case 1:
boot();
break;
}
}
}
} else {
buttonsDown[B] = false;
}
if (CRead == LOW) {
if (!(buttonsDown[C])) {
buttonsDown[C] = true;
if (menu == 0) {
if (option < maxOptions) {
option++;
refresh();
}
}
}
} else {
buttonsDown[C] = false;
}
}
Please test it. It compiles perfectly for me, so if you have the same library, it will work for you.
Doesn't work. Are you using a different version or library?
What version do you have?
Version 1.2.4
Are you sure this is what you have?
If it is , please downgrade it (select an old version and install it) and then update it again.
Still doesn't seem to work. By the looks of it, you're on windows. I'm on mac but I can try to compile on windows, I doubt that would change but I'll give it a shot.
Yes, I am on windows.
Same error, here's the full log (with my info blocked out)
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"
C:\Users\-----\Documents\Arduino\Test\Test.ino: In function 'void boot()':
Test:69:31: error: no matching function for call to 'SDLib::SDClass::begin(int, int, int, int)'
if (!SD.begin(10, 11, 12, 13)) {
^
In file included from C:\Users\-----\Documents\Arduino\Test\Test.ino:4:0:
F:\Arduino\libraries\SD\src/SD.h:71:15: note: candidate: boolean SDLib::SDClass::begin(uint8_t)
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
^~~~~
F:\Arduino\libraries\SD\src/SD.h:71:15: note: candidate expects 1 argument, 4 provided
F:\Arduino\libraries\SD\src/SD.h:72:15: note: candidate: boolean SDLib::SDClass::begin(uint32_t, uint8_t)
boolean begin(uint32_t clock, uint8_t csPin);
^~~~~
F:\Arduino\libraries\SD\src/SD.h:72:15: note: candidate expects 2 arguments, 4 provided
exit status 1
no matching function for call to 'SDLib::SDClass::begin(int, int, int, int)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You have the wrong library. There is no such thing as a src folder in the library I am using.