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

Hello,

I have a TFT LCD display which comes with a shield for arduino uno (like this one https://www.amazon.de/-/en/Hailege-ILI9341-240X320-Display-Arduino/dp/B07YKN1C2Z)
I am using the SPFD5408_Adafruit_TFTLCD.h library which is working fine with it.
But the issue is that the LCD shield is using the analog ports A0-A4 for the LCD_CS,CD,WR,RD and RESET.
In my project, I have 4 sensors that require using the analog ports, and the LCD is using them and as you know in arduino UNO I only have 6 analog ports.
Is there a way to use the digital ports 10,11,12,13 for the LCD display or maybe is there any other library that I can use which permit me to use the digital ports instead of the analog ones.
Thank u.

seems this display using every possible pin on Uno. use Mega with shield or any additional board as sensor handler

1 Like

Can’t view the Amazon page on this phone, but if the display has an SD card interface, you might be able to disconnect that and use those pins for the display. You would need to modify the library files.

1 Like

This display has a resistive touch overlay also connected to the analog pins. Needs to be on those pins if you want to use touch (no touch controller.
It doesn't have an SD card holder.

That will be my last resort if I didn't find a solution. Thank u.

Finally had a look at the link the OP posted, the display clearly has an SD card holder and four pins dedicated to the SD card.

The A4 connection on this type display is a reset line, that can easily be moved to the reset pin on the arduino, or just tied HIGH and rely on a reset when applying power. (I've done that in order to use the I2C bus along with a similar display).

Using a Nano (atmega328 version) would give you two additional analog inputs, with no changes to the code or wiring.

Hi David,
I already disconnected the SD card pins and tried to use them instead of the analog ports.
I used an example from Electronics Eternity youtube channel making the TFT works without library, but they also use the analog ports in their example. I modified their code and the TFT worked fine with digital pins, but as you know using library is far simple, as all functions are already defined.
Modifying the library is a tough option, I will check if I can do it with my little experience.
Thank you.

Hello,
If the touch require the analog ports, then the only option that I have now is what @kolaha suggested, which is using the arduino mega instead.
But how it comes the analog ports are used for the LCD and for the touch at the same time, and I can't use the same digital ports for the same functionality.
Thank u anyway for your reply.

You may be lucky, the library has two constructors, one for the default shield pinout, and one for the breakout board where you define the CS, CD, WR, RD, and RST pins.

  Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst);
  Adafruit_TFTLCD(void);

You do need to be careful that the USE_ADAFRUIT_SHIELD_PINOUT define line is commented out in the SPFD5408_Adafruit_TFTLCD.h file. (this seems to be the default)

// **** IF USING THE LCD BREAKOUT BOARD, COMMENT OUT THIS NEXT LINE. ****
// **** IF USING THE LCD SHIELD, LEAVE THE LINE ENABLED:             ****

// *** SPFD5408 change -- Begin
//#define USE_ADAFRUIT_SHIELD_PINOUT 1
// -- End

Should be ok, the touch screen only needs two analog pins, and you needed four for your sensor.

The analog pins for the touchscreen are shared with the pins for the display. Whenever you read the touchscreen, it is necessary to immediately set the pins back to output mode for use by the display library.

Hi David,
Thank you for your help.
What are the two pins that require to be analog, as on the shield there is no dedicated ports for the touch. I have only the CS, CD, WR, RD, and RST pins, in addition to the digital and SD pins.
It's good idea to connect the RST pin to the reset pin on the arduino.
But still I have to update the library, no?

Did you test the touchscreen with the library you are using? If so, the examples seem to use A1 and A2 for the touchscreen analog pins.

Thank you David,
do you mean that uncommented the
//#define USE_ADAFRUIT_SHIELD_PINOUT 1
will makes me define the ports needed to be used as digital pins for the LCD.
But I still need to know what are the two pins that require analog and used by the touch screen to connect them.

Leave that line commented out, then use the constructor where you explicitly define the cs, cd, wr,rd, and rst pins. If the touchpad is on A1 and A2, leave the digital pins for the display wired to those, and use A0, A3, A4, and A5 for your sensors.

Yes, I already did a lot of tests including the touch and everything is working fine with that library. as per the library that I am using, the A1 is the LCD_WR and A2 is the LCD_CD. Does that make sense.

That sounds correct. For some reason the picture on amazon shows A2 as LCD_RS instead of LCD_CD, but the others match the CS,WR, RD, and RST labeling.

I will try that option and let you know, hope that will not require any modifications to the library :slight_smile: . Thank you again.

Yes I checked that before, LCD_RS is the same as LCD_CD.

Hi David,
I tried that code:

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

// optional
#define LCD_RESET A4

Adafruit_TFTLCD tft();

But when compiling I received error on most the functions used in the library, such as:

void setup() {

  tft.reset();
  tft.begin(0x9341); //--> SDFP5408/ILI9341
  tft.setRotation(0); /

Sorry my mistake was in that line
Adafruit_TFTLCD tft();
it should be like this
Adafruit_TFTLCD tft;

But even, I didn't have any display on the screen, and the LCD shows a white screen.