2 TFT touchscreen

Hello friends

I am making a project where i need two touchscreen tft (SPI) working together but each having its own separate content. How can i connect two of this to the same arduino model.

thank you :wink:

Two different CS (chip select) pins in the class constructors.

Try it and see for yourself.
I suggest that you use the hardware SPI with a respected TFT library.

So far, you have not said what display and which Arduino you are using.
The XPT2046 style of SPI Touch Controller will also need separate CS and IRQ pins.

David.

thank you David
I'm using "Arduino Uno R3" and a TFT touchscreen "TFT w/ILI9340C by Adafruit"

You will use this constructor for the Hardware SPI:

  Adafruit_ILI9340(uint8_t CS, uint8_t RS, uint8_t RST);

I would expect you to have something like:

 Adafruit_ILI9340 tft1(10, 9, 8);    //different CS, same RS, RST pins
 Adafruit_ILI9340 tft2( 7, 9, 8);     //
 ...

       tft1.begin();    //start first TFT
       tft2.begin();    //start second TFT
       ...

Untested. I do not have this display. Nor have I read its manual.

I would guess that the 9341 version of the library would work exactly the same. In fact, you may actually have ILI9341 chips.

Many of the SPI displays have the EXTC pin disabled. So you can not read the ID.
If you have got EXTC, the ID is in register 0xD3. Read 4 bytes.

David.

Works great!

#include <SPI.h>
//#include <ILI9341_t3.h>

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_DC 9
#define TFT_CS 10

//#define TFT_DC2 20
#define TFT_CS2 21

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(TFT_CS2, TFT_DC);
//ILI9341_t3 tft2 = ILI9341_t3(TFT_CS2, TFT_DC);

char TX[20];
int Temperature1=25;
int Dx= 20;
int maxpx = 70;       // Temperature-bar heigh
int maxscale = 100;   // Scale: 0C to 50C (max)
int maxscale2 = 500;   // Scale: 0C to 50C (max)
int lecT1px;

void setup() {
  tft.begin();  tft.setRotation(3);  
  tft.fillScreen(ILI9341_BLUE);

  tft2.begin();  tft2.setRotation(1);  
  tft2.fillScreen(ILI9341_RED);

  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(2);  
  tft.setCursor(20, 20);  tft.print("First TFT ILI9341");  


  tft2.setTextColor(ILI9341_GREEN);
  tft2.setTextSize(2);  
  tft2.setCursor(20, 20);  tft2.print("Second TFT ILI9341");  
}  
  
void loop() {
   Temperature1 = random(maxscale);
   tft.setTextSize(2);     
   sprintf(TX,"T = %03d  C", Temperature1);   
   tft.setTextColor(ILI9341_WHITE, ILI9341_BLUE);
   tft.setCursor(50, 50);  tft.print(TX);          

   int Temperature2 = random(maxscale2);   
   tft2.setTextSize(2);     
   sprintf(TX,"T = %03d  C", Temperature2);   
   tft2.setTextColor(ILI9341_WHITE, ILI9341_RED);
   tft2.setCursor(50, 120);  tft2.print(TX);             
     
     lecT1px = Temperature1*maxpx/maxscale;  //temperature to pixels-value
    int lecT1px2 = Temperature2*maxpx/maxscale2;  //temperature to pixels-value

   tft.fillRect(95,100,Dx,maxpx-lecT1px,ILI9341_BLUE); // up to dawn
   tft.fillRect(95,100+maxpx-lecT1px,Dx,lecT1px,ILI9341_GREEN); // dawn to up
   tft.drawRect(95-1,100-1,Dx+2,maxpx+2,ILI9341_WHITE); // cover
   
   tft2.fillRect(195,100,Dx,maxpx-lecT1px2,ILI9341_BLACK); // up to dawn
   tft2.fillRect(195,100+maxpx-lecT1px2,Dx,lecT1px2,ILI9341_GREEN); // dawn to up
   tft2.drawRect(195-1,100-1,Dx+2,maxpx+2,ILI9341_WHITE); // cover   
   
   tft.setTextSize(1);  
   sprintf(TX,"%d  C", maxscale);  tft.setTextColor(ILI9341_WHITE);
   tft.setCursor(120, 95);  tft.print(TX);     
   sprintf(TX,"%d  C", 0);  
   tft.setCursor(120, 95+maxpx);  tft.print(TX);        
   
   
   tft2.setTextSize(1);  
   sprintf(TX,"%d  C", maxscale2);  tft2.setTextColor(ILI9341_WHITE);
   tft2.setCursor(220, 95);  tft2.print(TX);     
   sprintf(TX,"%d  C", 0);  
   tft2.setCursor(220, 95+maxpx);  tft2.print(TX);           

   delay(50);
}

Two TFT´s ILI9341, different information and different sizes: 2.4", 2.8".
Board: teensy 3.2
Lib: Adafruit_ILI9341, Adafruit_GFX

Awesome :slight_smile:

thank you so much

Where did you get the 2.8" SPI Touch display?

Does it have EXTC ?

David.

#include <SPI.h>
//#include <ILI9340_t3.h>

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"

// broches utilisées sur la carte Arduio uno
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8
//#define TFT_DC2 20
#define _cs2 7

Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
//ILI9340_t3 tft = ILI9340_t3(TFT_CS, TFT_DC);
Adafruit_ILI9340 tft2 = Adafruit_ILI9340(_cs2, _dc, _mosi, _sclk, _rst, _miso);
//ILI9340_t3 tft2 = ILI9340_t3(TFT_CS2, TFT_DC);

char TX[20];
int Temperature1=25;
int Dx= 20;
int maxpx = 70; // Temperature-bar heigh
int maxscale = 100; // Scale: 0C to 50C (max)
int maxscale2 = 500; // Scale: 0C to 50C (max)
int lecT1px;

void setup() {

tft2.begin(); tft2.setRotation(1);
tft2.fillScreen(ILI9340_RED);

tft.begin(); tft.setRotation(3);
tft.fillScreen(ILI9340_BLUE);

tft.setTextColor(ILI9340_YELLOW);
tft.setTextSize(2);
tft.setCursor(20, 20); tft.print("First TFT ILI9340");

tft2.setTextColor(ILI9340_GREEN);
tft2.setTextSize(2);
tft2.setCursor(20, 20); tft2.print("Second TFT ILI9340");

}

void loop() {

Temperature1 = random(maxscale);
tft.setTextSize(2);
sprintf(TX,"T = %03d C", Temperature1);
tft.setTextColor(ILI9340_WHITE, ILI9340_BLUE);
tft.setCursor(50, 220); tft.print(TX);

int Temperature2 = random(maxscale2);
tft2.setTextSize(2);
sprintf(TX,"T = %03d C", Temperature2);
tft2.setTextColor(ILI9340_WHITE, ILI9340_RED);
tft2.setCursor(50, 120); tft2.print(TX);

lecT1px = Temperature1maxpx/maxscale; //temperature to pixels-value
int lecT1px2 = Temperature2
maxpx/maxscale2; //temperature to pixels-value

tft.fillRect(95,100,Dx,maxpx-lecT1px,ILI9340_BLUE); // up to dawn
tft.fillRect(95,100+maxpx-lecT1px,Dx,lecT1px,ILI9340_GREEN); // dawn to up
tft.drawRect(95-1,100-1,Dx+2,maxpx+2,ILI9340_WHITE); // cover

tft2.fillRect(195,100,Dx,maxpx-lecT1px2,ILI9340_BLACK); // up to dawn
tft2.fillRect(195,100+maxpx-lecT1px2,Dx,lecT1px2,ILI9340_GREEN); // dawn to up
tft2.drawRect(195-1,100-1,Dx+2,maxpx+2,ILI9340_WHITE); // cover

tft.setTextSize(1);
sprintf(TX,"%d C", maxscale); tft.setTextColor(ILI9340_WHITE);
tft.setCursor(220, 95); tft.print(TX);
sprintf(TX,"%d C", 0);
tft.setCursor(220, 95+maxpx); tft.print(TX);

tft2.setTextSize(1);
sprintf(TX,"%d C", maxscale2); tft2.setTextColor(ILI9340_WHITE);
tft2.setCursor(120, 95); tft2.print(TX);
sprintf(TX,"%d C", 0);
tft2.setCursor(120, 95+maxpx); tft2.print(TX);

delay(50);
}

I have tried with this code but the problem that " I see the blue screen on the first TFT then the red screen on the second but not at the same time ... "

@david it s from adafruit

I explained that you should use the hardware SPI constructor.
You have chosen to use the bit-bash SPI constructor.

I have not looked at the bit-bash code. Most bit-bash implementations are not very good at having multiple devices.

Since TFTLCDCyg has given you a working example, I would follow his example. i.e. use the hardware constructor()

I have said all along that I have not tested anything.

David.

Double checking in each wire. Please: check it one by one.

With your code, and some changes:

#include <SPI.h>

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"

// broches utilisées sur la carte Arduio uno 
//      #define _sclk 13
//      #define _miso 12
//      #define _mosi 11
      #define _cs 10
      #define _dc 9
      #define _rst 8
      #define _cs2 21   //in my setup

//      Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
      Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);      

//      Adafruit_ILI9340 tft2 = Adafruit_ILI9340(_cs2, _dc, _mosi, _sclk, _rst, _miso);
      Adafruit_ILI9340 tft2 = Adafruit_ILI9340(_cs2, _dc, _rst);

david_prentice:
Where did you get the 2.8" SPI Touch display?

Does it have EXTC ?

David.

TFT 2.8" from Alliexpress. No idea respect to EXTC.

If it responds to extended commands, the EXTC pin is set. e.g. can you read the ID register reg(0xD3) ?

David.

it's working :slight_smile:

this is great

#include <SPI.h>
//#include <ILI9340_t3.h>

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"

// broches utilisées sur la carte Arduio uno
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8
//#define TFT_DC2 20

#define _cs2 7
#define _dc2 5
#define _mosi2 6
#define _sclk2 4
#define _miso2 3
#define _rst2 1

Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
//ILI9340_t3 tft = ILI9340_t3(TFT_CS, TFT_DC);
Adafruit_ILI9340 tft2 = Adafruit_ILI9340(_cs2, _dc2, _mosi2, _sclk2, _rst2, _miso2);
//ILI9340_t3 tft2 = ILI9340_t3(TFT_CS2, TFT_DC);

void setup() {
// put your setup code here, to run once:

tft.begin();
tft.setRotation(3);
tft.fillScreen(ILI9340_YELLOW);
tft.setTextColor(ILI9340_BLACK);
tft.setTextSize(8);
tft.setCursor(20, 20);
tft.print("PROJET");

tft2.begin();
tft2.setRotation(3);
tft2.fillScreen(ILI9340_YELLOW);
tft2.setTextColor(ILI9340_BLACK);
tft2.setTextSize(8);
tft2.setCursor(20, 20);
tft2.print("ELEC");
}

void loop() {

// put your main code here, to run repeatedly:
tft.setCursor(50, 220);
tft2.setCursor(50, 220);

}

Wow!, amazing UNO!. Congratulations :art:

**david_prentice **

I´m sorry, I´m very noob in the "ocean of registers-TFT".

tft.readID() it´s in the Adafruit_TFTLCD lib, but in the Adafruit_ILI9341 or the ILI9341_t3 lib don´t have such function.