Problem Connecting 128x160 TFT Display with PCF8574 Module on Arduino Uno

I'm facing an issue connecting a 128x160 TFT SPI display to my Arduino Uno due to limited available pins. The only free pins I have are:

  • D0 (RX) and D1 (TX)
  • D10
  • D13
  • A5

Since I ran out of available pins, I decided to use the PCF8574 module to add extra GPIO pins via I2C. This way, I can free up SPI pins for other components and still control the TFT display.

I wired it like this:

  • PCF8574 SDA β†’ A4 (SDA on Arduino)
  • PCF8574 SCL β†’ A5 (SCL on Arduino)
  • PCF8574 pins P0-P4 for TFT control (SCK, SDA, DC, RESET, CS)

However, the screen is not displaying anything. Could you suggest any improvements to the wiring or code? I'd appreciate any help!

Thanks in advance!

How are you driving the PCF8574 P0-P4 pins? Did you write code to simulate an SPI interface on the PCF8574? Are there timing requirements on the display that may be a problem with the PCF8474?

1 Like

Thank you for your response!

  1. Driving PCF8574 pins: I’m using I2C commands to toggle the PCF8574 P0-P4 pins to simulate SPI, code I created but not yet tested
    Code :
#include <Wire.h>               
#include <PCF8574.h>            
#include <TFT.h>                

PCF8574 pcf8574(0x20);         

#define CS    4   
#define RESET 3   
#define DC    2   
#define SDA   1   
#define SCK   0   

TFT TFTscreen(CS, DC, RESET);

void setup() {
  Wire.begin();
  pcf8574.begin();
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
  TFTscreen.setTextSize(2);
}

void loop() {
  int redRandom = random(0, 255);
  int greenRandom = random(0, 255);
  int blueRandom = random(0, 255);
  
  TFTscreen.stroke(redRandom, greenRandom, blueRandom);
  TFTscreen.text("Hello, World!", 6, 57);
  delay(200);
}
  1. Timing requirements: I suspect the I2C speed may not meet the timing needs of the TFT display, which could explain why it’s not working.

Do you think simulating SPI via PCF8574 is feasible, or should I explore other options like multiplexers?

Thanks for your help!

I moved your topic to an appropriate forum category @jawad_r7 .

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

It can be done. Whether or not it is practical depends. Here is some code I wrote to run a MAX7219 via a PCF8574. Ignore about 80% of it (related to the MAX7219) and look at the functions with spi in the name.

Can you rearranged whatever you are using the other pins for to free up the SPI pins?

Component Name | Arduino Uno Used Inputs

S1 Water Pump Manual | D2
Relay 1 Water Pump | D3
IN1 Motor Driver (roof) | D4
IN2 Motor Driver (roof) | D5
Humidity and Temperature DATA AM2302 | D6
LEDs (UV) | D7
LEDs (White) | D8
S2 White LED Activation | D9
EnA Motor Driver (roof) | D11
Relay 2 Fan | D12
Soil Humidity Sensor AO | A0
Rain Sensor DO | A1
Rain Sensor AO | A2
Light Sensor SCL | A4
Light Sensor SDA | A5
Remaining Inputs
D10 | D13
A3 |

Use the PCF8574 to drive these two devices, freeing up your SPI pins. Also, you gain another 6 possible I/Os (and you can move other devices there to free up pins for DC, CS & RESET on Arduino pins if you like).

The display I am using is a 1.8” TFT. Initially, I wired it as shown in the photo. My question is: to avoid adding an extension module (which I can’t use because only the A3 analog pin is still available on my Arduino Uno), can I connect the screen to the following pins: D1, D10, D13, and A3?

If it is possible to use these pins, how should I wire them correctly?

Here the code that work before when I tested the display :


*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */

// include TFT and SPI libraries
#include <TFT.h>  
#include <SPI.h>

// pin definition for Arduino UNO
#define cs   10
#define dc   9
#define rst  8


// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

void setup() {

  //initialize the library
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
  //set the text size
  TFTscreen.setTextSize(2);
}

void loop() {

  //generate a random color
  int redRandom = random(0, 255);
  int greenRandom = random (0, 255);
  int blueRandom = random (0, 255);
  
  // set a random font color
  TFTscreen.stroke(redRandom, greenRandom, blueRandom);
  
  // print Hello, World! in the middle of the screen
  TFTscreen.text("Hello, World!", 6, 57);
  
  // wait 200 miliseconds until change to next color
  delay(200);

No.

You've been given a workable solution. Use it, don't use it, it's up to you. I'm done.

What solution? :face_with_monocle: :face_with_monocle:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.