Arduino LCD

I have an sainsmart 1.8" LCD that works fine with the adafruit library but I find their examples to cumbersome to edit, and the arduino tft library seems much easier. I am using it with an ethernet shield so I can't use spi on it because of pin conflicts which is fine, but it means I have to manually define my pins for the LCD. When using the example provided with the LCD library I get an error when defining more than 3 pins .. help please.

#define SCLK 4
#define MOSI 5
#define CS 6
#define DC 7
#define RESET 8

TFT myScreen = TFT(CS, DC, MOSI, SCLK, RESET);

--

TFTDisplayText:27: error: no matching function for call to 'TFT::TFT(int, int, int, int, int)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/TFT.h:17: note: candidates are: TFT::TFT(uint8_t, uint8_t, uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/TFT.h:15: note: TFT::TFT(const TFT&)
TFTDisplayText.ino: In function 'void setup()':
TFTDisplayText:37: error: 'TFTscreen' was not declared in this scope
TFTDisplayText.ino: In function 'void loop()':
TFTDisplayText:62: error: 'TFTscreen' was not declared in this scope

Are you sure that the library is properly installed?

The library I'm trying to use is the TFT library that comes with the arduino ide, and the syntax is from the arduino reference.

Please post all of your code in [ code][ /code] brackets.

The code im using with the arduino tft library is:

/*

 Arduino TFT Bitmap Logo example
 
 This example reads an image file from a micro-SD card
 and draws it on the screen, at random locations.
 
 In this sketch, the Arduino logo is read from a micro-SD card.
 There is a .bmp file included with this sketch. 
 - open the sketch folder (Ctrl-K or Cmd-K)
 - copy the "arduino.bmp" file to a micro-SD
 - put the SD into the SD slot of the Arduino TFT module.
 
 This example code is in the public domain.
 
 Created 19 April 2013 by Enrico Gueli
 
 http://arduino.cc/en/Tutorial/TFTBitmapLogo
 
 */
 
// include the necessary libraries
#include <SPI.h>
#include <SD.h>
#include <TFT.h>  // Arduino LCD library

// pin definition for the Uno
#define sclk 3
#define mosi 5
#define cs   6
#define dc   7
#define rst  8  // you can also connect this to the Arduino reset




TFT TFTscreen = TFT(cs, dc, mosi, sclk, rst);

// this variable represents the image to be drawn on screen
PImage logo;


void setup() {
  // initialize the GLCD and show a message
  // asking the user to open the serial line
  TFTscreen.begin();
  TFTscreen.background(255, 255, 255);

  TFTscreen.stroke(0, 0, 255);
  TFTscreen.println();
  TFTscreen.println("Arduino TFT Bitmap Example");
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.println("Open serial monitor");
  TFTscreen.println("to run the sketch");

  // initialize the serial port: it will be used to 
  // print some diagnostic info  
  Serial.begin(9600);
  while (!Serial) {
    // wait for serial line to be ready
  }

  // clear the GLCD screen before starting
  TFTscreen.background(255, 255, 255);
  
  // try to access the SD card. If that fails (e.g.
  // no card present), the setup process will stop.
  Serial.print("Initializing SD card...");
  if (!SD.begin(sd_cs)) {
    Serial.println("failed!");
    return;
  }
  Serial.println("OK!");
  
  // initialize and clear the GLCD screen
  TFTscreen.begin();
  TFTscreen.background(255, 255, 255);

  // now that the SD card can be access, try to load the
  // image file.
  logo = TFTscreen.loadImage("arduino.bmp");
  if (!logo.isValid()) {
    Serial.println("error while loading arduino.bmp");
  }
}

void loop() {
  // don't do anything if the image wasn't loaded correctly.
  if (logo.isValid() == false) {
    return;
  }
  
  Serial.println("drawing image");

  // get a random location where to draw the image.
  // To avoid the image to be draw outside the screen,
  // take into account the image size.
  int x = random(TFTscreen.width() - logo.width());
  int y = random(TFTscreen.height() - logo.height());

  // draw the image to the screen
  TFTscreen.image(logo, x, y);

  // wait a little bit before drawing again
  delay(1500);
}

but there is a problem using more than 3 variables with the TFTscreen part.

Hey!

Solved this:

Use the line:

Adafruit_ST7735  screen = Adafruit_ST7735(CS, DC, MOSI, SCLK, RESET);

Instead of:

TFT TFTscreen = TFT(CS, DC, MOSI, SCLK, RESET);

Working sample code with my pin configuration (Arduino UNO):

//Taken from http://arduino.cc/en/Reference/TFTText
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define SCLK 1
#define MOSI 7
#define CS   8
#define DC   9
#define RESET 12 

Adafruit_ST7735 screen = Adafruit_ST7735(CS, DC, MOSI, SCLK, RESET);

void setup() {
  // initialize the screen
  //screen.begin(); begin() is only available when using TFT instead of Adafruit_ST7735
  //so we have to use the next two lines instead.
      screen.initR(INITR_REDTAB);
      screen.setRotation(1);

  // make the background black
  screen.background(0,0,0);

  // set the text color to white
  screen.stroke(255,255,255);

  // write text to the screen in the top left corner
  screen.text("Testing!", 0, 0);
}

void loop() {
}

@Zaungast, I had the same issue with using the tft function with five paramaters. Your solution with two changes eliminated the error I faced. But now the TFT does not display the correct image that I have called from the SD. It shoes some random placed black bands and colour lines… what could have posiibly gone wrong with my program?

Im using arduino DUE and connecting a TFT 160X128 pixels through software SPI. here is my code.

#include <SPI.h>
#include <SD.h>
#include <TFT.h>  // Arduino LCD library

// pin definition for the Due                 
#define sd_cs  7
#define lcd_cs 4 //before, the value was 10,52,
#define dc     9
#define rst    8
#define sclk  12 //using other pins instead of hardware SPI pins
#define mosi 11 //using other pins instead of hardware SPI pins
//miso is on pin 5

//TFT TFTscreen = TFT(lcd_cs, dc, mosi, sclk, rst);
Adafruit_ST7735  TFTscreen = Adafruit_ST7735(lcd_cs, dc, mosi, sclk, rst);
//TFT TFTscreen = TFT(lcd_cs, dc, rst);

// this variable represents the image to be drawn on screen
PImage logo;


void setup() {
  // initialize the GLCD and show a message
  // asking the user to open the serial line
  //  TFTscreen.begin();
  //begin() is only available when using TFT instead of Adafruit_ST7735
  //so we have to use the next two lines instead.
  //TFTscreen.initB();
  TFTscreen.initR(INITR_GREENTAB);
  TFTscreen.setRotation(3);
  
  TFTscreen.background(255, 0, 255);

  TFTscreen.stroke(0, 0, 255);
  TFTscreen.println();
  TFTscreen.println(F("Arduino TFT Bitmap Example"));
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.println(F("Open serial monitor"));
  TFTscreen.println(F("to run the sketch"));
   delay(1500);

  // initialize the serial port: it will be used to
  // print some diagnostic info
  Serial.begin(9600);
  while (!Serial) {
    // wait for serial port to connect. Needed for native USB port only
  }

  // clear the GLCD screen before starting
  TFTscreen.background(255, 255, 255);

  // try to access the SD card. If that fails (e.g.
  // no card present), the setup process will stop.
  Serial.print(F("Initializing SD card..."));
  if (!SD.begin(sd_cs)) {
    Serial.println(F("failed!"));
    return;
  }
  Serial.println(F("OK!"));

  // initialize and clear the GLCD screen
  //  TFTscreen.begin();
  //begin() is only available when using TFT instead of Adafruit_ST7735
  //so we have to use the next two lines instead.
   //TFTscreen.initB();
   TFTscreen.initR(INITR_GREENTAB);
   TFTscreen.setRotation(3);
  
  TFTscreen.background(255, 255, 255);

  // now that the SD card can be access, try to load the
  // image file.
  logo = TFTscreen.loadImage("4.bmp");//24 bit image stored in sd card
  if (!logo.isValid()) {
    Serial.println(F("error while loading arduino.bmp"));
  }
}

void loop() {
  // don't do anything if the image wasn't loaded correctly.
  if (logo.isValid() == false) {
    return;
  }

  Serial.println(F("drawing image"));

  // get a random location where to draw the image.
  // To avoid the image to be draw outside the screen,
  // take into account the image size.
  int x = (TFTscreen.width() - logo.width())/2;
  int y = (TFTscreen.height() - logo.height())/2;

  // draw the image to the screen
  TFTscreen.image(logo, x, y);

  // wait a little bit before drawing again
  delay(1500);
}