Two or more display in the same time - sumotoy/TFT_ILI9163C GitHub Wiki
Version 1.0p7 introduces multiple instances so it's possible use 2 or more display by just adding one cpu pin on Teensy 3.x, but other CPU needs DC separate!
connections...
If you have a Teensy 3.x you are luky, you can share the DC pin so any additional display needs only one pin more (CS), but Teensy cannot use any pin for CS so take care to choose the CS compatible ones!
Other CPU needs all separate, you can get rid of Reset pin, connect all reset to a resistor (4k7 to 10K at 3V3), share MOSI and SCLK between display's, then choose 2 pins (DC and CS) for any display. You need to pullup every CS with a resistor (10K to 3v3), this is important, a good practice but in a multidisplay confuguration a must have!
use different display type per instance?
Sure yes, library correct offset and perform a rotation correction as well, can even perform color correction, as result even different display type!
settings and library, how to use
To proceed, library has a setting inside _settings/TFT_ILI9163C_settings.h.
You should comment out:#define TFT_ILI9163C_INSTANCES.
In this way the library will not load single display files but load TFT_ILI9163C_ALL.h that contain multiple settings in the same time so the library instance changed into:
TFT_ILI9163C(display type, cs pin, dc pin, reset pin), where:
- Display Type: REDPCB_NEW(yellow pin, red pcb), REDPCB_OLD(black pin, red pcb, BLACKPCB_OLD
- CS pin: should be unique to each display
- DC pin: should be shared with all display in Teensy 3,3.1 and 3.2, The other CPU must have separate pin!
- Reset pin: Normally not needed, you can avoid it but pullup reset pin on display at 3v3 with 10K resistor
An example with 2 display (different types):
#include <SPI.h>
#include <TFT_ILI9163C.h>
#if defined(TFT_ILI9163C_INSTANCES)
#error "you should enable setting TFT_ILI9163C_INSTANCES"
#endif
#define __CS1 10
#define __CS2 15
#if defined(__MK20DX128__) || defined(__MK20DX256__)
#define __DC1 9 //should be common for 2 display
#define __DC2 9 //should be common for 2 display
#else
#define __DC1 9
#define __DC2 6
#endif
TFT_ILI9163C tft1 = TFT_ILI9163C(REDPCB_NEW, __CS1, __DC1);
TFT_ILI9163C tft2 = TFT_ILI9163C(REDPCB_OLD, __CS2, __DC1);
void setup() {
tft1.begin();
tft2.begin();
}
void loop() {
}
Internally the library has instance enumerator that will perform SPI initialization just for the first display automatically so there's no risk for multiple SPI initializations. Library uses SPI Transactions so it's safe use other libraries (but be sure all use SPI Transactions).
You can do the same thing in much modern way:
#include <SPI.h>
#include <TFT_ILI9163C.h>
#if !defined(TFT_ILI9163C_INSTANCES)
#error "you should enable in settings TFT_ILI9163C_INSTANCES!"
#endif
#define __CS1 10
#define __CS2 15
#if defined(__MK20DX128__) || defined(__MK20DX256__)
#define __DC1 9 //share between all display
#define __DC2 9 //share between all display
#else
#define __DC1 9
#define __DC2 6
#endif
TFT_ILI9163C tft[2] = { TFT_ILI9163C(REDPCB_NEW, __CS1, __DC1) ,TFT_ILI9163C(REDPCB_OLD, __CS2, __DC2) };
//using an array contain instances it's good when you want save code!
void setup()
{
for (uint8_t i = 0; i < 2; i++) {
tft[i].begin();
tft[i].setRotation(2);
}
}
void loop(){
for (uint8_t i = 0; i < 10; i++) {
drawVerticalVU(0,10*i + 2*i, 10, 10, random(255), 0);
drawVerticalVU(1,10*i + 2*i, 10, 10, random(255), 0);
}
delay(20);
}
//here's a function that creates vertical VU's
void drawVerticalVU(uint8_t disp,uint8_t x, uint8_t y, uint8_t w, uint8_t val, uint16_t color) {
uint8_t h = map(val, 0, 255, tft[disp].height() - y, 0);
if (color < 1) color = tft[disp].gradient(map(val, 0, 255, 0, tft[disp].height()));
tft[disp].fillRect(x, 0, w, h, DARK_GREY);
if (val > 4) tft[disp].fillRect(x, h + 1, w, tft[disp].height() - (h + y + 2), color);
}