Hi,
When I use only SPI.begin the output works fine and when I use only TFT.begin the LCD works fine.
But when I use both, There's a conflict I can't resolve.
Have you ever had this problem?
Thanks!
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_GC9A01A.h"
#define TFT_DC 41
#define TFT_CS 39
#define TFT_BL 22
#define TFT_RST 40
#define TFT_MOSI 11
#define TFT_SCLK 13
// screen
Adafruit_GC9A01A tft(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
// 74HC595
const byte LATCH = 38;
byte cmpt = 0;
void setup() {
Serial.begin(9600);
SPI.begin();
tft.begin();
}
void loop() {
cmpt++;
// affiche les leds
GatePlay();
printCompteur();
delay(100);
}
//affiche 74HC595
void GatePlay() {
digitalWrite(LATCH, LOW);
SPI.transfer(cmpt);
digitalWrite(LATCH, HIGH);
}
//affiche ecran
void printCompteur() {
tft.fillScreen(GC9A01A_BLACK);
tft.setTextColor(GC9A01A_WHITE);
tft.setCursor(60, 120);
tft.setTextSize(2);
tft.print("compteur : ");
tft.println(cmpt);
}
What might that conflict be?
I don't know what that conflict be, but the screen remains blank and the output animation does not work...
It may help to use SPI.begin/endTransaction(), at least around the LED output.
I'd try this:
void GatePlay() {
SPI.begin();
digitalWrite(LATCH, LOW);
SPI.transfer(cmpt);
digitalWrite(LATCH, HIGH);
SPI.end();
It's working with the output but the screen keep blank.
noisybear:
the screen keep blank.
Then enclose the screen output printCompteur() in the same way.
Thanks for your help!
I had try code bellow but the screen don't work.
`void GatePlay() {
SPI.begin();
digitalWrite(LATCH, LOW);
SPI.transfer(cmpt);
digitalWrite(LATCH, HIGH);
printCompteur();
SPI.end();
}`
Which arduino board are you using?
Are you certain the TFT works without the SPI? I don’t see the call to tft.display() that is common for an Adafruit library.
I use Teensy 4.1 and yes it’s working perfectly without SPI. I Had try with GFX library and it’s the same.
Have you tried the hardware SPI constructor for the display, looks like you are using the constructor for software SPI.
/*!
@brief Instantiate Adafruit GC9A01A driver with software SPI
@param cs Chip select pin #
@param dc Data/Command pin #
@param mosi SPI MOSI pin #
@param sclk SPI Clock pin #
@param rst Reset pin # (optional, pass -1 if unused)
@param miso SPI MISO pin # (optional, pass -1 if unused)
*/
Adafruit_GC9A01A::Adafruit_GC9A01A(int8_t cs, int8_t dc, int8_t mosi,
int8_t sclk, int8_t rst, int8_t miso)
: Adafruit_SPITFT(GC9A01A_TFTWIDTH, GC9A01A_TFTHEIGHT, cs, dc, mosi, sclk,
rst, miso) {}
/*!
@brief Instantiate Adafruit GC9A01A driver with hardware SPI using the
default SPI peripheral.
@param cs Chip select pin # (OK to pass -1 if CS tied to GND).
@param dc Data/Command pin # (required).
@param rst Reset pin # (optional, pass -1 if unused).
*/
Adafruit_GC9A01A::Adafruit_GC9A01A(int8_t cs, int8_t dc, int8_t rst)
: Adafruit_SPITFT(GC9A01A_TFTWIDTH, GC9A01A_TFTHEIGHT, cs, dc, rst) {}
Hello there,
You are using an GC9A01A, as tft but which board ard you using? Arduino UNO, ESP32, ESP8266 or another one?
Greetings dingsken.
Did you read all replies See post #9 .
Oh, I didn´t saw this Thanks.
I had try that, but I need remove the line (because Compilation error: exit status 1)
Adafruit_GC9A01A tft(cs, dc, mosi, sclk, rst, miso);
and of coarse tft.begin() dont work.
I suggested to use beginTransaction() and endTransaction().
Just to verify, you tried this in the code:
// screen
//Adafruit_GC9A01A tft(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_GC9A01A tft(TFT_CS, TFT_DC, TFT_RST);
If that is not working, then try using different pins for the Software SPI on the display. Running hardware and software SPI on the same pins is likely not going to work.
I gave up my attempts with Adafruit_GC9A01A and GFX, I switched with TFT_eSPI and everything works perfectly.
It's a little more complex but more powerful, so...
Thank you for your efforts to help me!