1.8 TFT display interfering with other pins (specifically digitalWrite)?

Hi all,
I’m not sure if the TFT display is actually the cause of my issue, but I have an Arduino Nano connected to a relay + optocoupler module (https://www.amazon.com/dp/B07WQH63FB/ref=cm_sw_r_tw_dp_x_u.JwFb1HVZVJH), along with a 1.8 TFT display. I have an external 5V source coming from a L7805 5V regulator that is fed by an 8.4 V wall barrel jack power supply, and both grounds are connected. The pinouts are as follows:

Screen:
LED → 3.3V (Arduino’s source)
SCK → 13
SDA → 11
DC → 9
RESET → 8
CS → 10
GND → GND
VCC → External 5V

Relay:
DC+ → External 5V
DC- → GND
IN → 12

I don’t believe anything is wrong with my wiring however, I think there is some issue with my code.

#include <TFT.h>
#include <SPI.h>

#define CS 10
#define DC 9
#define RST 8
#define RELAY_PIN 12

TFT lcd = TFT(CS, DC, RST);

void setup() {
  //lcd.begin();
  pinMode(12, OUTPUT);
}

void loop() {
  //lcd.background(0,255,0);
  //lcd.writecommand(0x10);
  //lcd.sleep();
  
  digitalWrite(12,HIGH);
  delay(3000);
  digitalWrite(12,LOW);
  delay(3000);
  
}

The relay works perfectly when all the lcd commands are commented out. However, as soon as I uncomment the lcd.begin() or any following commands, the relay fails to switch on or off. I can see the LED on the relay barely turning on and off, but the relay does not actually switch on or off (no click sound).

I even tried using the .sleep and .wake commands here to try and disconnect the lcd and then turn on/off the relay: https://forum.arduino.cc/index.php?topic=342461.0 ,but nothing changed.

Any help would be much appreciated! Been trying to figure this out but to no avail.

Edit: Ahh the LED turns on when I try a different relay module (https://www.amazon.com/Tolako-Arduino-Indicator-Channel-Official/dp/B00VRUAHLE/ref=sr_1_8?dchild=1&keywords=relay+module+arduino&qid=1599750611&sr=8-8), not with the current one. I’ve also tried different pins but the issue still seems to be the same.

Thanks for the links to your Relay module(s)

I give up.

This Forum subject is Displays. They come in all shapes and sizes. They have different electrical interfaces. Different voltage tolerances. Different pinouts.

It takes about one minute of your life to post a link to the actual display that you have bought. e.g. Ebay sale page.

Of course you can type every page of the relevant datasheets if you don't want to reveal which shop you purchased from.

But one minute is quicker and easier.
You get an immediate and accurate reply. (instead of me repeating the same request for link to hardware display)

David.

Hello, my apologies, I figured 1.8" TFT was specific enough since all the ones I have seen look similar. I bought it a while ago so the Aliexpress listing is no longer there, but it looks exactly the same as this module: https://www.amazon.com/Display-Module-ST7735-128x160-STM32/dp/B07BFV69DZ/ref=sr_1_8?crid=20SKOT2322SG7&dchild=1&keywords=1.8+tft+display&qid=1599754720&sprefix=1.8+tft+%2Caps%2C157&sr=8-8.

Thank you, sorry I didn't include it the first time.

Thanks for the link.

That particular display requires 3.3V logic. i.e. level shifters with a 5V Uno, Mega2560, ...

TFT lcd = TFT(CS, DC, RST);

This means that you are using the Hardware SPI constructor. So avoid digital #12.

Relays and any external electronics require careful wiring and adequate decoupling. e.g. good GND connections, 100nF ceramic capacitors close to any switching chips.

David.

Thank you for the help!
I think it turned out to be more of a power issue than the display. I had an existing 104 ceramic capacitor on the power supply which i figured was enough, but adding another one near the relay power and ground + changing to a different pin solved the issue.
Thanks again, spent hours trying to figure out why!