I'm trying to get the TFT display and the SD card on it to work.
When I don't do the SD.Open function, the display works as expected. But as soon as I call the SD.Open function, the display appears to hang. The code is as follows:
the display & the serial monitor do show
"Initializing SD card..."
but ONLY the serial monitor window shows "OK!!"
and the text in the loop function never gets displayed. So what am I missing?
Code: Select all
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>
// For the breakout, you can use any (4 or) 5 pins
//*******************************************************************
// this is setup to use the DC BOARDUINO
//******************************************************************
#define sclk 13
#define mosi 11
#define cs 10
#define dc 9
#define rst 8 // you can also connect this to the Arduino reset
#define SD_CS 4 // Chip select line for SD card
// Option 1: use any pins but a little slower
//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
// Option 2: must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
#define SPI_SCK 13
#define SPI_DI 12
#define SPI_DO 11
#define TFT_CS 10
#define TFT_DC 9 //8
#define TFT_RST 8 //0
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, SPI_DO, SPI_SCK, TFT_RST);
const char *pInitTestString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ";
void setup()
{
Serial.begin(9600);
// If your TFT's plastic wrap has a Black Tab, use the following:
//tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
// If your TFT's plastic wrap has a Red Tab, use the following:
//tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab
// If your TFT's plastic wrap has a Green Tab, use the following:
tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab
tft.fillScreen(ST7735_BLACK);
testdrawtext(pInitTestString, ST7735_WHITE);
tft.fillScreen(ST7735_BLACK);
testdrawtext("Initializing SD card...", ST7735_WHITE);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS))
{
Serial.println("failed!");
tft.println("failed!");
return;
}
Serial.println("OK!");
tft.fillScreen(ST7735_BLACK);
testdrawtext("OK!!",ST7735_YELLOW);
delay(500);
}
void loop()
{
tft.fillScreen(ST7735_BLACK);
testdrawtext("In The Loop...", ST7735_YELLOW);
delay(500);
}
void testdrawtext(const char *text, uint16_t color) {
tft.setCursor(0, 0);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}