Both TFT and SD work fine with an Arduino UNO using the attached sketch. I've soldered the pads so that ICSP is connected (and have not cut the traces to the I/O pins). However when using the same sketch with the Arduino Zero, only the TFT works (so at least SPI on ICSP must be working). The "SD.begin" function will always fail with the Zero... while it worked fine on the UNO. I do not have any other devices connected to the Arduino. I can't figure out why this would happen. Here is my sketch... Thanks!:
Code: Select all
// Debug effort using Adafruit Capacitive touch screen with SD card reader (prod. 1947) on
// an Arduino Zero. Same code works fine on Uno
#include <SD.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
#define SD_CS 4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
// initialize serial communication
while ( ! Serial ) { delay( 1); } // this is required for M0's because of slower on-board/"native" USB
Serial.begin(9600);
Serial.println("ILI9341 Test!");
Serial.print("Initializing SD card...");
//* !!!!??? THIS ONLY WORKS ON UNO... FAILS ON ZERO. ???!!!!!!!
// see if the card is present and can be initialized:
if (!SD.begin(SD_CS)) {
Serial.println("Card failed, or not present");
while (1); // don't do anything more:
}
Serial.println("card initialized.");
SDdemo2();
//*/ !!!!!!!!!!!!!!!!!!!!!!!!!!
TFTdemo();
}
void loop(void) {
}
void SDdemo2(){
String dataString = "hello";
File dataFile = SD.open("datalog.txt",FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.print("Value written to card is: ");
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void TFTdemo(){
tft.begin();
Serial.println(F("Benchmark Time (microseconds)"));
delay(10);
Serial.print(F("Screen fill "));
Serial.println(testFillScreen());
delay(500);
Serial.print(F("Text "));
Serial.println(testText());
delay(3000);
Serial.println(F("Done!"));
}
unsigned long testFillScreen() {
unsigned long start = micros();
tft.fillScreen(ILI9341_BLACK);
yield();
tft.fillScreen(ILI9341_RED);
yield();
tft.fillScreen(ILI9341_GREEN);
yield();
tft.fillScreen(ILI9341_BLUE);
yield();
tft.fillScreen(ILI9341_BLACK);
yield();
return micros() - start;
}
unsigned long testText() {
tft.fillScreen(ILI9341_BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
tft.println(1234.56);
tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
tft.println(0xDEADBEEF, HEX);
tft.println();
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(5);
tft.println("Groop");
tft.setTextSize(2);
tft.println("I implore thee,");
tft.setTextSize(1);
tft.println("my foonting turlingdromes.");
tft.println("And hooptiously drangle me");
tft.println("with crinkly bindlewurdles,");
tft.println("Or I will rend thee");
tft.println("in the gobberwarts");
tft.println("with my blurglecruncheon,");
tft.println("see if I don't!");
return micros() - start;
}