tft.init (Adafruit QDTech Library) disturbs digital output pin LOW (Relay)?

I have a tft display (1.8") and a relay connected to an arduino nano. the relay is connected to pin 12, where it is activated when the pin is LOW.

The following code works, setting pin 12 to 0V in the loop, and activating the relay:

// TFT DISPLAY //

#include <SPI.h>
#include "Adafruit_GFX.h" // Core graphics library
#include "Adafruit_QDTech.h" // Hardware-specific library

#define sclk 13 // Don't change
#define mosi 11 // Don't change
#define cs 9
#define dc 8
#define rst 7 // you can also connect this to the Arduino reset

Adafruit_QDTech tft = Adafruit_QDTech(cs, dc, rst); // Display-Bibliothek Setup

// RELAY
int relay = 12;

void setup() {

// RELAY: initialize the digital pin as an output.
pinMode(relay, OUTPUT);

//Display Setup
// tft.init();

}

void loop() {
digitalWrite(relay, LOW);
}

However, if I activate the display (uncomment tft.init();), pin 12 shows 3,7V in LOW and 4.4 in HIGH.

Is this a software problem?

Thanks in advance!

Hi.

This is no software problem, it is a hardware feature.
I have to assume you are using an Uno.
Your display is connected through the SPI interface.
An Uno and its siblings have a hardware SPI solutions on board, and these are mapped to these pins:

10: SPI SS (Slave Select)
11: SPI MOSI (Master Out, Slave In)
12: SPI MISO (Master In, Slave Out)
13: SPI SCK (Clock)

If you include SPI.h, these pins will be set to use SPI, so you can't use it for other purposes (i don't know if it is possible to release the use of SPI).

So, best is to find another pin to control your relay.
You can also use the Analog input pins to control such relays, they are normal pins which can also be used to sample analogue values.
So if you have all other pins in use already, you can still use those.

Thank you so much for your explanation :slight_smile:

Using pin 10 works as expected!