I am trying to connect up to 5 TFT displays to one Arduino Uno R3 and use a multiplexer to control the output to each display. At the moment I am stuck being able to only write to a single one. Every time I try to add a second one I fail.
The displays I am using are here along with the pin allocations. https://www.waveshare.com/wiki/1.69inch_LCD_Module#Arduino
The process I am following is detailed here along with the schematic I am following. https://forum.arduino.cc/t/multiple-tft-displays-with-due-using-multiplexed-spi-cs/917473.
In the schematic you can see they are sharing the one reset pin. Additionally that pin is connected to the Arduino's native Reset pin.
I have copied the same design so that all my pins are shared apart from the CS pin. The CS pin from the Arduino goes to the signal pin of the multiplexer.
I can get that setup to work with a single display. However, as soon as I put the second displays reset pin into the same channel on the breadboard as the first displays pin, both screens no longer work. They are backlit, but there is no text appearing. Pull the second RST pin out again, reset the Arduino, and the first screen outputs text again.
I have taken the code from the example above and modified it a little to suit my displays. Below is the code I am using with comments that I hope explains it adequately.
After the initialization, I am adding a delay of 1000 ms in case the displays needed time to reset. Unfortunately, this didn't help either. I feel that adding the delay inside of the initialization loop won't help because as I understand it, the reset happens when the display gets power.
I am not an electronics person but I am a programmer by trade. So it's the code I understand and can modify. Where I am lacking is in being able to wire this up so that I can have the 5 displays hooked up.
I "think" that if I can solve the RST issue, that I should be able to write to the screens no problem, but right now that's a guess.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library
#include <SPI.h>
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF
// rst is declared as pin 8 but there is no pin in that socket
Adafruit_ST7789 tft = Adafruit_ST7789(10, 7, 8); // 10 = CS, dc, rst
void setup(void)
{
// these outputs control the multiplexer chip
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
for (int n = 1; n < 3; n++)
{
SetDisplay(n); // selects the display
tft.init(240, 280);
tft.setTextColor(WHITE);
tft.setRotation(2); // rotate to portrait
tft.fillScreen(BLACK);
tft.setCursor(15, 18);
tft.print("DISPLAY ");
tft.print(n);
}
delay(1000);
}
int value = 0; // this is what is rendered on screen
void loop()
{
// Scroll through the two displays
for (int M = 1; M < 3; M++)
{
SetDisplay(M);
tft.fillRect(0, 25, 159, 128, BLACK); // fill the variable text area which clears the previous text
tft.setCursor(15, 50);
tft.print(String(value));
value++;
}
delay(1000);
}
// This function selects the display by setting two binary outputs to the multiplexer chip
void SetDisplay(int DNo)
{
if (DNo == 1)
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
tft.setTextColor(RED);
}
else if (DNo == 2)
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
tft.setTextColor(GREEN);
}
}