Using digital pins instead of analog ones in 2.4" tft lcd shield for arduino

Try using the long constructor

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

Looks like LCD_RESET should be set to 0 for no reset pin.

Same issue, but now the screen is black.
I was checking the SPFD5408_Adafruit_TFTLCD.cpp and it has those line of codes:

  pinMode(A3, OUTPUT);   // Enable outputs
  pinMode(A2, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode( 5, OUTPUT);

Also in the pin_magic.h library, it has those lines:

#define RD_PORT PORTC				/*pin A0 */
  #define WR_PORT PORTC				/*pin A1 */
  #define CD_PORT PORTC				/*pin A2 */
  #define CS_PORT PORTC				/*pin A3 */
  #define RD_MASK B00000001
  #define WR_MASK B00000010
  #define CD_MASK B00000100
  #define CS_MASK B00001000

looks like it's hard for me to figure it out.

Those lines are only compiled if USE_ADAFRUIT_SHIELD_PINOUT is defined.

 106 // Initialization common to both shield & breakout configs
 107 void Adafruit_TFTLCD::init(void) {
 108 
 109 #ifdef USE_ADAFRUIT_SHIELD_PINOUT
 110   CS_IDLE; // Set all control bits to idle state
 111   WR_IDLE;
 112   RD_IDLE;
 113   CD_DATA;
 114   digitalWrite(5, HIGH); // Reset line
 115   pinMode(A3, OUTPUT);   // Enable outputs
 116   pinMode(A2, OUTPUT);
 117   pinMode(A1, OUTPUT);
 118   pinMode(A0, OUTPUT);
 119   pinMode( 5, OUTPUT);
 120 #endif
 121 

Thank you David,
Now my code is that:

#define LCD_CS 12
#define LCD_CD A2 
#define LCD_WR A1
#define LCD_RD 13

// optional
#define LCD_RESET A4


Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

but still I have a black screen. Any suggestions.

Can't really think of anything else.
I don't have the same display, and don't have time tonight to wire up the similar display that I do have.

You need to look through the entire library source and find all the uses of these pins. Perhaps somewhere the pin numbers are used directly or the pins are used as a block and must be in a row.
I don’t see any other reasons why the original code works and yours doesn’t.

Thank you anyway for your help, I will take a look into the library and see if I can find something.

Can you post the complete sketch you are using for testing?

My display is working with your code from reply #24, with the exception that I have LCD_RESET defined as 0 because my display has the reset line permanently wired to the UNO reset pin.

Hi David,
You used the same library in your test?
I am using these libraries:

#include <SPFD5408_Adafruit_GFX.h> //--> Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> //--> Hardware-specific library
#include <SPFD5408_TouchScreen.h>

I can try connecting the LCD_RESET button to the reset of the Arduino and test.
I think even if we don't connect the reset line at all, it should work if you don't use reset command in the code, right?

Here it is:

#include <memorysaver.h>

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega and screen initial

// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GRAY    0xF7BE
#define LIGHTCYAN    0xB7FF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Adafruit_GFX_Button bText, bChart, bGauge;


// -- Setup

void setup(void) {
  Serial.begin(9600);
  tft.reset();
  tft.begin(0x9341); // SDFP5408
  tft.setRotation(3);
  tft.fillScreen(LIGHTCYAN);
  drawButtons(); //function draw the button needed in my project
  drawChart(); //Draw the sensors results as a chart
}

void loop() {
  drawRectChart(random(0,1000), RED,1); //Draw a single sensor results
  drawRectChart(random(0,1000), BLUE,2);
  drawRectChart(random(0,1000), GREEN,3);
  drawRectChart(random(0,1000), YELLOW,4);
  drawRectChart(random(0,1000), MAGENTA,5);
  delay(3000);
  tft.fillRect( 22, 0, 290, 170, LIGHTCYAN);
}

For sure I test it by changing the code sent in post #24 and it didn't work.

This code is working on my display, using the libraries you posted with no modifications to the libraries. I had to add three functions to your code from post #31 to get it to compile, and the LCD_CS and LCD_RD pins have been changed to 12 and 13. The only problem I have is that my display flips the text to a mirror image because it is not exactly the same controller. I did some testing with the touchscreen calibration sketch, the code does respond to the touchscreen with the pins wired this way.

Which library does memorysaver.h come from? I'm using the file from the ArduCAM library.

#include <memorysaver.h>

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega and screen initial

// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS 12 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD 13 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GRAY    0xF7BE
#define LIGHTCYAN    0xB7FF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Adafruit_GFX_Button bText, bChart, bGauge;


// -- Setup

void setup(void) {
  Serial.begin(9600);
  tft.reset();
  tft.begin(0x9341); // SDFP5408
  tft.setRotation(3);
  tft.fillScreen(LIGHTCYAN);
  drawButtons(); //function draw the button needed in my project
  drawChart(); //Draw the sensors results as a chart
}

void loop() {
  drawRectChart(random(0, 1000), RED, 1); //Draw a single sensor results
  drawRectChart(random(0, 1000), BLUE, 2);
  drawRectChart(random(0, 1000), GREEN, 3);
  drawRectChart(random(0, 1000), YELLOW, 4);
  drawRectChart(random(0, 1000), MAGENTA, 5);
  delay(3000);
  tft.fillRect( 22, 0, 290, 170, LIGHTCYAN);
}

void drawButtons(){
  tft.setCursor (55, 50);
  tft.setTextSize (3);
  tft.setTextColor(BLUE);
  tft.print(F("drawButtons"));
}

void drawChart(){
  tft.setCursor (55, 100);
  tft.setTextSize (2);
  tft.setTextColor(RED);
  tft.print(F("drawChart"));
}

void drawRectChart(uint16_t r, uint16_t c, uint16_t x){
  tft.setCursor(55, 120 + 20 * x);
  tft.setTextSize(1);
  tft.setTextColor(c);
  tft.println(r);
}

Hi David,
Thanks for your help, I will retry the wiring again same as you did with my LCD and check.
Regarding memorysaver.h, honestly I don't know from where it comes :slight_smile: . I was not able to upload my code to Arduino UNO and the compiler return a memory related error. While learning on how to use the TFT library, I saw some examples that have that memory library included so I used it :grinning: and my code was uploaded successfully. I read about it, and they said that the Arduino memory size is not enough to accept my code, and using this library will upload the code to the flash memory in the Arduino which is bigger than the RAM memory (something like that). I can generate that error again and send you the error that forces me to use that library, maybe you have better explanation.