Adafruit ili9341 Library

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Adafruit ili9341 Library

Post by Chris_Cooper »

Hi All,

I’ve been using multiple Adafruit 2.4” displays on SPI. I have managed to configure six of them on the same SPI bus which all work, but as soon as I add a 7th, the code won’t compile.

The displays are initialised as follows and as soon as I uncomment tft7 it stops compiling.

Is the library limited to 6 actual devices?

// Configure ILI9341 display.

Adafruit_ILI9341 tft1 = Adafruit_ILI9341(TFT1_CS, TFT1_DC);
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(TFT2_CS, TFT2_DC);
Adafruit_ILI9341 tft3 = Adafruit_ILI9341(TFT3_CS, TFT3_DC);
Adafruit_ILI9341 tft4 = Adafruit_ILI9341(TFT4_CS, TFT4_DC);
Adafruit_ILI9341 tft5 = Adafruit_ILI9341(TFT5_CS, TFT5_DC);
Adafruit_ILI9341 tft6 = Adafruit_ILI9341(TFT6_CS, TFT6_DC);
//Adafruit_ILI9341 tft7 = Adafruit_ILI9341(TFT7_CS, TFT7_DC);
//Adafruit_ILI9341 tft8 = Adafruit_ILI9341(TFT8_CS, TFT8_DC);

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit ili9341 Library

Post by mikeysklar »

Good job getting six TFTs going. Even that seems impressive.

What is the compile error you receive when the 7th display is initialized? It might be helpful to enable verbose debugging.

File->Preferences->Show verbose output during....

User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Re: Adafruit ili9341 Library

Post by Chris_Cooper »

Hi,

Sorry for the lack of reply, I may have been premature on the 6TFTs as it is very unstable.

Just solving that then I will come back to you!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit ili9341 Library

Post by mikeysklar »

Okay, let us know if we can help with the six TFTs getting stable.

User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Re: Adafruit ili9341 Library

Post by Chris_Cooper »

Please see next post.
Last edited by Chris_Cooper on Fri Oct 01, 2021 7:06 pm, edited 1 time in total.

User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Re: Adafruit ili9341 Library

Post by Chris_Cooper »

Hi,

So, after much reading, running 8 TFTs is not going to work seemingly. So my project is in jeopardy, as it’s based on 8 displays. But I suddenly thought that perhaps I could use both the VSPI and HSPI bus's on my ESP32 to run 4 TFTs each?!

Therefore, I was wondering if have any hints on how to use the Adafruit ILI9341 driver with the ESP32 in this configuration?

I’m trying to get my head around SPI classes and the ILI9341 Adafruit Driver, but I can’t get the HSPI bus to initialise although the VSPI bus is fine.

When using this line of code, on the default SPI bus, the display works fine (testing circuit):

Code: Select all

Adafruit_ILI9341 tft1 = Adafruit_ILI9341(VSPI_CS, VSPI_DC, VSPI_MOSI, VSPI_CLK, VSPI_RST, VSPI_MISO);
However, to use the ILI9341 on the HSPI bus, I think I call it as follows:

Code: Select all

SPIClass  SPI2 = SPIClass(HSPI);
Then I call the display driver, but with less parameters:

Code: Select all

Adafruit_ILI9341 tft2 = Adafruit_ILI9341(&SPI2, HSPI_DC, HSPI_CS, HSPI_RST);
But this doesn't allow me to configure the other pins (MOSI, CLK etc) and therefore how / where are these set?

Regards,

Christopher

User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Re: Adafruit ili9341 Library

Post by Chris_Cooper »

Hi,

This is the complete test sketch.

Code: Select all

#include <SPI.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>

#define VSPI_MISO   19 // MISO
#define VSPI_MOSI   23 // MOSI
#define VSPI_CLK    18 // SCK
#define VSPI_CS     5  // CS
#define VSPI_DC     4  // DC
#define VSPI_RST    22 // RST

#define HSPI_MISO   12
#define HSPI_MOSI   13
#define HSPI_CLK    14
#define HSPI_CS     15
#define HSPI_DC     26
#define HSPI_RST    27 // RST

#define BLUE            0x001F
#define TEAL            0x0438
#define GREEN           0x07E0
#define CYAN            0x07FF
#define RED             0xF800
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define ORANGE          0xFD20
#define PINK            0xF81F
#define PURPLE          0x801F
#define GREY            0xC618
#define WHITE           0xFFFF
#define BLACK           0x0000

// VSPI (default under Arduino)
SPIClass  SPI1(VSPI);
Adafruit_ILI9341 tft1=Adafruit_ILI9341(&SPI1, VSPI_DC, VSPI_CS, VSPI_RST);

// HSPI 
SPIClass  SPI2(HSPI);
Adafruit_ILI9341 tft2=Adafruit_ILI9341(&SPI2, HSPI_DC, HSPI_CS, HSPI_RST);

void setup() {

	pinMode(VSPI_CS, OUTPUT); //VSPI SS
	pinMode(HSPI_CS, OUTPUT); //HSPI SS

	SPI1.begin(VSPI_CLK, VSPI_MISO, VSPI_MOSI, VSPI_CS);
	SPI2.begin(HSPI_CLK, HSPI_MISO, HSPI_MOSI, HSPI_CS);

	tft1.begin();

	tft1.setRotation(3);
	tft1.setCursor(0, 0);
	tft1.fillScreen(BLUE);

	delay(1000);

	tft2.begin();

	tft2.setRotation(3);
	tft2.setCursor(0, 0);
	tft2.fillScreen(GREEN);

}

void loop() {

}

Thanks

User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Re: Adafruit ili9341 Library

Post by Chris_Cooper »

Hi,

I have now managed to get my 8 TFT's working by diving them across both the VSPI and HSPI ESP32 BUS's.

Using your Adafruit ILI9341 driver, I set the SS (Chip Select) pin when calling the driver to a dummy pin as follows:

Code: Select all

// VSPI Class
Adafruit_ILI9341 tft1 = Adafruit_ILI9341(VSPI_CS0, VSPI_DC, VSPI_MOSI, VSPI_CLK, VSPI_RST, VSPI_MISO); // CS0 is a dummy pin

// HSPI Class
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(HSPI_CS9, HSPI_DC, HSPI_MOSI, HSPI_CLK, HSPI_RST, HSPI_MISO); // CS9 is a dummy pin
I then use digital writes to enable or disable each of the actual SS (Chip Select) pins when required, which works a treat.

My only concern now is that the speed and performance is fairly slow.

Full test sketch here for anyone wanting to run many TFTs of the same type.

Code: Select all

#include <SPI.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include "startScreen.h"

#define VSPI_MISO   19 // MISO - Not needed as it is a display
#define VSPI_MOSI   23 // MOSI
#define VSPI_CLK    18 // SCK
#define VSPI_DC     4  // DC
#define VSPI_RST    22 // RST

#define VSPI_CS0	36 // This is set to an erroneous pin as to not confuse manual chip selects using digital writes.
#define VSPI_CS1    5  // Screen one chip select
#define VSPI_CS2    21 // Screen two chip select
#define VSPI_CS3    16 // Screen three chip select
#define VSPI_CS4    17 // Screen four chip select

#define HSPI_MISO   12 // MISO - Not needed as it is a display
#define HSPI_MOSI   13 // MOSI
#define HSPI_CLK    14 // SCK
#define HSPI_DC     26 // DC
#define HSPI_RST    27 // RST

#define HSPI_CS9    39 // This is set to an erroneous pin as to not confuse manual chip selects using digital writes.
#define HSPI_CS5    15 // Screen five chip select
#define HSPI_CS6    25 // Screen six chip select
#define HSPI_CS7    33 // Screen seven chip select
#define HSPI_CS8    32 // Screen eight chip select

#define BLUE		0x001F
#define TEAL		0x0438
#define GREEN		0x07E0
#define CYAN		0x07FF
#define RED			0xF800
#define MAGENTA		0xF81F
#define YELLOW		0xFFE0
#define ORANGE		0xFD20
#define PINK		0xF81F
#define PURPLE		0x801F
#define GREY		0xC618
#define WHITE		0xFFFF
#define BLACK		0x0000

// VSPI Class
Adafruit_ILI9341 tft1 = Adafruit_ILI9341(VSPI_CS0, VSPI_DC, VSPI_MOSI, VSPI_CLK, VSPI_RST, VSPI_MISO); // CS0 is a dummy pin

// HSPI Class
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(HSPI_CS9, HSPI_DC, HSPI_MOSI, HSPI_CLK, HSPI_RST, HSPI_MISO); // CS9 is a dummy pin

void setup() {
	
	// Enable output pins for chip selects.

	pinMode(VSPI_CS1, OUTPUT); //VSPI SS
	pinMode(VSPI_CS2, OUTPUT); //VSPI SS
	pinMode(VSPI_CS3, OUTPUT); //VSPI SS
	pinMode(VSPI_CS4, OUTPUT); //VSPI SS
	pinMode(HSPI_CS5, OUTPUT); //HSPI SS
	pinMode(HSPI_CS6, OUTPUT); //HSPI SS
	pinMode(HSPI_CS7, OUTPUT); //HSPI SS
	pinMode(HSPI_CS8, OUTPUT); //HSPI SS

	// Set all tft1 chip select outputs high to ensure stable BUS

	disableVSPIScreens();

	// Set all tft1 chip select outputs low to configure all displays the same using tft.begin.

	digitalWrite(VSPI_CS1, LOW);
	digitalWrite(VSPI_CS2, LOW);
	digitalWrite(VSPI_CS3, LOW);
	digitalWrite(VSPI_CS4, LOW);

	// Send screen configuration.

	tft1.begin();
	tft1.setRotation(3);
	tft1.setCursor(0, 0);

	// Reset all chip selects high once again.

	disableVSPIScreens();

	// Set all tft2 chip select outputs high to ensure stable BUS

	disableHSPIScreens();

	// Set all tft2 chip select outputs low to configure all displays the same using tft.begin.

	digitalWrite(HSPI_CS5, LOW);
	digitalWrite(HSPI_CS6, LOW);
	digitalWrite(HSPI_CS7, LOW);
	digitalWrite(HSPI_CS8, LOW);

	// Send screen configuration.

	tft2.begin();
	tft2.setRotation(3);
	tft2.setCursor(0, 0);

	// Reset all chip selects high once again.

	disableHSPIScreens();

	// Bank one screen tests.

	delay(250);
	enableScreen1();
	tft1.fillScreen(BLUE);
	disableVSPIScreens();

	delay(250);
	enableScreen2();
	tft1.fillScreen(BLUE);
	disableVSPIScreens();

	delay(250);
	enableScreen3();
	tft1.fillScreen(BLUE);
	disableVSPIScreens();

	delay(250);
	enableScreen4();
	tft1.fillScreen(BLUE);
	disableVSPIScreens();

	// Bank two screen tests.

	delay(250);
	enableScreen5();
	tft2.fillScreen(GREEN);
	disableHSPIScreens();

	delay(250);
	enableScreen6();
	tft2.fillScreen(GREEN);
	disableHSPIScreens();

	delay(250);
	enableScreen7();
	tft2.fillScreen(GREEN);
	disableHSPIScreens();

	delay(250);
	enableScreen8();
	tft2.fillScreen(GREEN);
	disableHSPIScreens();

	delay(250);

	enableScreen1();
	tft1.fillScreen(RED);
	tft1.setFont();
	tft1.setTextSize(2);
	tft1.setTextColor(BLACK);
	tft1.setCursor(20, 150);
	tft1.println("Screen One - Bank One");

	disableVSPIScreens();

	enableScreen5();
	tft2.fillScreen(RED);
	tft2.setFont();
	tft2.setTextSize(2);
	tft2.setTextColor(BLACK);
	tft2.setCursor(20, 150);
	tft2.println("Screen Five - Bank Two");

	disableHSPIScreens();

	enableScreen2();
	drawBitmap(tft1, 48, 96, startScreen, 128, 128);
	disableVSPIScreens();

} // Close setup.

void loop() {

	// Nothing here just yet!

} // Close loop.

/*-----------------------------------------------------------------*/

// Disable outputs for all displays on VSPI bus.

void disableVSPIScreens() {

	digitalWrite(VSPI_CS1, HIGH);
	digitalWrite(VSPI_CS2, HIGH);
	digitalWrite(VSPI_CS3, HIGH);
	digitalWrite(VSPI_CS4, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Disable outputs for all displays on HSPI bus.

void disableHSPIScreens() {

	digitalWrite(HSPI_CS5, HIGH);
	digitalWrite(HSPI_CS6, HIGH);
	digitalWrite(HSPI_CS7, HIGH);
	digitalWrite(HSPI_CS8, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen one on bank one to recieve SPI commands.

void enableScreen1() {

	digitalWrite(VSPI_CS1, LOW);
	digitalWrite(VSPI_CS2, HIGH);
	digitalWrite(VSPI_CS3, HIGH);
	digitalWrite(VSPI_CS4, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen two on bank one to recieve SPI commands.

void enableScreen2() {

	digitalWrite(VSPI_CS1, HIGH);
	digitalWrite(VSPI_CS2, LOW);
	digitalWrite(VSPI_CS3, HIGH);
	digitalWrite(VSPI_CS4, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen three on bank one to recieve SPI commands.

void enableScreen3() {

	digitalWrite(VSPI_CS1, HIGH);
	digitalWrite(VSPI_CS2, HIGH);
	digitalWrite(VSPI_CS3, LOW);
	digitalWrite(VSPI_CS4, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen four on bank one to recieve SPI commands.

void enableScreen4() {

	digitalWrite(VSPI_CS1, HIGH);
	digitalWrite(VSPI_CS2, HIGH);
	digitalWrite(VSPI_CS3, HIGH);
	digitalWrite(VSPI_CS4, LOW);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen five on bank two to recieve SPI commands.

void enableScreen5() {

	digitalWrite(HSPI_CS5, LOW);
	digitalWrite(HSPI_CS6, HIGH);
	digitalWrite(HSPI_CS7, HIGH);
	digitalWrite(HSPI_CS8, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen six on bank two to recieve SPI commands.

void enableScreen6() {

	digitalWrite(HSPI_CS5, HIGH);
	digitalWrite(HSPI_CS6, LOW);
	digitalWrite(HSPI_CS7, HIGH);
	digitalWrite(HSPI_CS8, HIGH);

} // Close function.

/*-----------------------------------------------------------------*/

// Enable screen seven on bank two to recieve SPI commands.

void enableScreen7() {

	digitalWrite(HSPI_CS5, HIGH);
	digitalWrite(HSPI_CS6, HIGH);
	digitalWrite(HSPI_CS7, LOW);
	digitalWrite(HSPI_CS8, HIGH);

}  // Close function.

/*-----------------------------------------------------------------*/

// Enable screen eight on bank two to recieve SPI commands.

void enableScreen8() {

	digitalWrite(HSPI_CS5, HIGH);
	digitalWrite(HSPI_CS6, HIGH);
	digitalWrite(HSPI_CS7, HIGH);
	digitalWrite(HSPI_CS8, LOW);
}


User avatar
Chris_Cooper
 
Posts: 29
Joined: Sun Jun 07, 2020 11:05 am

Re: Adafruit ili9341 Library

Post by Chris_Cooper »

For anyone wanting to do this, the performance issue is now solved as I have moved the SPI bus's back to being hardware defined as follows:

Code: Select all

SPIClass  SPI2(HSPI);

// VSPI Class (default).
Adafruit_ILI9341 tft1 = Adafruit_ILI9341(VSPI_CS0, VSPI_DC, VSPI_RST); // CS0 is a dummy pin

//Software defined SPI.
//Adafruit_ILI9341 tft1 = Adafruit_ILI9341(VSPI_CS0, VSPI_DC, VSPI_MOSI, VSPI_CLK, VSPI_RST, VSPI_MISO); // CS0 is a dummy pin 

// HSPI Class.
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(&SPI2, HSPI_DC, HSPI_CS9, HSPI_RST); // CS9 is a dummy pin

//Software defined SPI.
//Adafruit_ILI9341 tft2 = Adafruit_ILI9341(HSPI_CS9, HSPI_DC, HSPI_MOSI, HSPI_CLK, HSPI_RST, HSPI_MISO); // CS9 is a dummy pin
Then you have to slow down the TFT displays as follows:

Code: Select all

	tft1.begin(27000000);

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit ili9341 Library

Post by mikeysklar »

Many thanks and congrats on getting all 8 TFTs going. That is awesome. Appreciate the code, CS trick and SPI slowdown freq.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”