SOLVED - unable to make it work 1.8 SPI TFT 128x160

Thanks for the replies but I've found out that the problem was due to the stickduino. I switched to an ardunino nano v3 and everything is working perfectly but now I have another problem.

The LCD works great and so the SD card reader. But when I try to use them at the same time the LCD becomes extremely slow. :frowning:

Pleae take a look at this sample of code:

#define cs_lcd   10
#define cs_sd    7
#define dc       9
#define rst      8

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>

Adafruit_ST7735 tft = Adafruit_ST7735(cs_lcd, dc, rst);
File myFile;

void setup()
{
  tft.initR(INITR_REDTAB); 
  tft.fillScreen(ST7735_BLACK);
  tft.setTextWrap(false); 
}


void loop()
{
  tft.setTextSize(5);
  tft.setTextColor(ST7735_RED, ST7735_BLACK);
  for ( int i = 0; i < 100; i++ )
  {
    tft.setCursor(40, 50);
    tft.print( i );
    delay( 100 );
  }
  
}

This sample of code works perfectly without any problem. But if I add a simple function to open and write data to a file it will start lagging severely:

#define cs_lcd   10
#define cs_sd    7
#define dc       9
#define rst      8

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>

Adafruit_ST7735 tft = Adafruit_ST7735(cs_lcd, dc, rst);
File myFile;

void setup()
{
  tft.initR(INITR_REDTAB); 
  tft.fillScreen(ST7735_BLACK);
  tft.setTextWrap(false); 
}


void loop()
{
  tft.setTextSize(5);
  tft.setTextColor(ST7735_RED, ST7735_BLACK);
  for ( int i = 0; i < 100; i++ )
  {
    tft.setCursor(40, 50);
    tft.print( i );
    delay( 100 );
  }
  writeCard();
  
}

void writeCard()
{
  if (!SD.begin(cs_sd)) {
    //Error accessing SD CARD.
    return;
  }
  
  myFile = SD.open("tmp.txt", FILE_WRITE);
   if (myFile) {
    //WRITING TO FILE
    myFile.println("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
    // close the file:
    myFile.close();
  }  
}

I though that this could have something to do with the SS, after all I'm enabling the SD pin without disabling the LCD one but still no good. :disappointed_relieved:

void writeCard()
{
  //TRY TO DISABLE THE LCD SS PIN
  digitalWrite( cs_lcd, HIGH );
  
  if (!SD.begin(cs_sd)) {
    //Error accessing SD CARD. Re-enable LCD SS pin, force the SD SS pin to be disabled and exit.
    digitalWrite( cs_lcd, LOW );
    digitalWrite( cs_sd, HIGH );
    return;
  }
  
  myFile = SD.open("tmp.txt", FILE_WRITE);
   if (myFile) {
    //WRITING TO FILE
    myFile.println("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
    // close the file:
    myFile.close();
  }
  
  //Writing finished. Lets re-enable LCD SS pin and disable the SD SS pin.
  digitalWrite( cs_lcd, LOW );  
  digitalWrite( cs_sd, HIGH );
}

I would really love not to have to hack (aka mess with) the Sd.h but right now I feel like I've hit a wall.

Any ideas? :frowning: