1.8" TFT

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
OldJohn
 
Posts: 5
Joined: Thu Feb 27, 2014 3:24 pm

1.8" TFT

Post by OldJohn »

OK, I'm obviously missing something.
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);
}

OldJohn
 
Posts: 5
Joined: Thu Feb 27, 2014 3:24 pm

Re: 1.8" TFT

Post by OldJohn »

oh, this is a the breakout form, not the shield, and I'm using the boarduino

OldJohn
 
Posts: 5
Joined: Thu Feb 27, 2014 3:24 pm

Re: 1.8" TFT

Post by OldJohn »

ok, finally got it working.
one of the example code (soft_spitftbitmap) has a method that does not compile with the SD library from Arduino:
SD.begin(SD_CS, SPI_DO, SPI_DI, SPI_SCK)
So had to get the SD library from Adafruit... next question... will this work with other SD card drivers (I have Seeed)...

also, the same example code uses this function to instantiate the tft object.
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, SPI_DO, SPI_SCK, TFT_RST);
It compiles, but as my initial post mentions, the logic appears to hang after the SD.Open function ...
After playing around with this further I have everything working with regard to the TFT 1.8 display while using the SD Microcard too.

I hope the following helps others

Follow the wire setup for SPI, at the two hires for pin 4 (SD Card) & 12 (MOSI) on the arduino board. The code:

Code: Select all

/***************************************************
 This is an example sketch for the Adafruit 1.8" SPI display.
  This library works with the Adafruit 1.8" TFT Breakout w/SD card
  ----> http://www.adafruit.com/products/358
  as well as Adafruit raw 1.8" TFT display
  ----> http://www.adafruit.com/products/618

  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)

***************************************************/


#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
//******************************************************************
//this is for option 1 setup.. not the SPI interface (option 2)
//must use the SPI when working with the SD card
//******************************************************************
//#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

//this does not work...appears to hang after the SD is opened.
//also function does not exists in the Arduino SD library... Must get the newer one from Adafruit.
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, SPI_DO, SPI_SCK, TFT_RST);

///this works fine....
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

//just using this to test text output.
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. ";

const int TempSensor = 0; //analog pin
const char pFileName[] = "Tmprture.txt";

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);
 
  if (SD.exists("Tmprture.txt"))
  {
    SD.remove("Tmprture.txt"); 
  }
  
  delay(500);
}

void loop()
{
  PullDataAndUpdate();
  delay(1000); 
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”