Raspberry Pi Pico 2 W display on two 1.9" 170*320 ST7789 SPI LCD, using Arduino_GFX_Library, using separated SPI.
Raspberry Pi Pico 2 W display on two 1.9" 170*320 ST7789 SPI LCD, using Arduino_GFX_Library, using separated SPI.
In previous exercise, I used a Raspberry Pi Pico 2 W to drive two LCDs: a 2.4-inch and a 2.0-inch 240×320 ST7789 SPI IPS. Both displays shared a common SPI bus without any problems. However, when I replaced them with two 1.9-inch 170×320 ST7789 SPI LCDs, the setup did not work. Using the same code and connections, only the second LCD would turn on. To solve this, I separated the SPI connections for the two displays: the first one (on the left) is connected via Arduino_RPiPicoSPI, and the second one (on the right) is connected via Arduino_SWSPI.
Updated connection:
Exercise Code:
rpPico2W_Arduino_GFX_Dual_170x320.ino, Color Test on two LCD.
rpPico2W_Arduino_GFX_Dual_170x320_random.ino, Random Pattern.
rpPico2W_Arduino_GFX_Dual_170x320_rot.ino, Rotation.
rpPico2W_Arduino_GFX_Dual_170x320_grouped.ino, Grouped two LCD in one canvas - left/right.
rpPico2W_Arduino_GFX_Dual_170x320_grouped_cube.ino, Display a floating cube in grouped canvas, left/right.
rpPico2W_Arduino_GFX_Dual_170x320_grouped_cube_topbottom.ino, Display a floating cube in grouped canvas, top/bottom.
rpPico2W_Arduino_GFX_Dual_170x320_Spiral_Sierpinsk.ino, Grouped two LCD as one canvas, display Spiral and Sierpinski.
In previous exercise, I used a Raspberry Pi Pico 2 W to drive two LCDs: a 2.4-inch and a 2.0-inch 240×320 ST7789 SPI IPS. Both displays shared a common SPI bus without any problems. However, when I replaced them with two 1.9-inch 170×320 ST7789 SPI LCDs, the setup did not work. Using the same code and connections, only the second LCD would turn on. To solve this, I separated the SPI connections for the two displays: the first one (on the left) is connected via Arduino_RPiPicoSPI, and the second one (on the right) is connected via Arduino_SWSPI.
Updated connection:
Raspberry Pi Pico 2 W
GP28| LCD2_RST -----------------+
GND | |
GP27| LCD2_DC ----------------+ |
GP26| LCD2_CS --------------+ | |
Run | | | |
GP22| LCD_RST ------+ | | |
GND | | | | |
GP21| LCD_DC -------|-+ | | |
GP20| LCD_BL -------|-|---+ | | |
GP19| SPI_SDA ----+ | | | | | |
GP18| SPI_SCL --+ | | | | | | |
GND | | | | | | | | |
+-----|GP14 GP17| LCD_CS ---|-|-|-|-+ | | | |
| +---|GP15 GP16| no use | | | | | | | | |
| | +------------+ | | | | | | | | |
| | | | | | | | | | |
1st ST7789 | | | | | | | | | | |
| | | | | | | | | | |
1 GND - GND | | | | | | | | | | |
2 VCC - 3V3 | | | | | | | | | | |
3 SCL --------|-|----------------------------+ | | | | | | | |
4 SDA --------|-|------------------------------+ | | | | | | |
5 RST --------|-|--------------------------------+ | | | | | |
6 DC --------|-|----------------------------------+ | | | | |
7 CS --------|-|------------------------------------+ | | | |
8 BL --------|-|---+----------------------------------+ | | |
| | | | | |
2nd ST7789 | | | | | |
| | | | | |
1 GND - GN | | | | | |
2 VCC - 3V3 | | | | | |
3 SCL --------+ | | | | |
4 SDA ----------+ | | | |
5 RST --------------|------------------------------------|-|-+
6 DC --------------|------------------------------------|-+
7 CS --------------|------------------------------------+
8 BL --------------+
Exercise Code:
rpPico2W_Arduino_GFX_Dual_170x320.ino, Color Test on two LCD.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Color Test on two LCD.
Notice:
Earlier (https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-dual.html),
I used a Raspberry Pi Pico 2 W to run two LCD screens (a 2.4-inch and a 2.0-inch,
both 240×320 ST7789). They shared the same SPI connection and worked fine.
But when I switched to two smaller 1.9-inch 170×320 ST7789 screens, things broke — only the
second screen would turn on with the same code and wiring. To fix it, I gave each screen its
own SPI connection: the left one uses Arduino_RPiPicoSPI, and the right one uses Arduino_SWSPI.
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART 35
#define TFT_ROWSTART 0
#define TFT2_ROTATION 0
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 35
#define TFT2_ROWSTART 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART, TFT2_ROWSTART);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library color test on two LCD 1.9 inch 170*320 ST7789 SPI LCD");
// Init Display
gfx->begin();
gfx2->begin();
gfx->fillScreen(RGB565_BLACK);
gfx2->fillScreen(RGB565_BLACK);
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);
gfx->setCursor(10, 10);
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx->println("Raspberry Pi Pico 2 W");
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->println();
gfx->println("Arduino_GFX_Library");
gfx2->setCursor(10, 10);
gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx2->println("Dual ST7789 exercise");
gfx2->println("Color Test");
delay(5000); // 5 seconds
}
#define num_of_color 5
int color[num_of_color] = {RGB565_RED, RGB565_GREEN, RGB565_BLUE, RGB565_WHITE, RGB565_BLACK};
String color_name[num_of_color] = {"RED", "GREEN", "BLUE", "WHITE", "BLACK"};
int color_index = 0;
void loop()
{
unsigned long startTime, stopTime;
//
startTime = millis();
gfx->fillScreen(color[color_index]);
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, color[color_index]^0xFFFF);
gfx->setTextColor(color[color_index]^0xFFFF);
gfx->setCursor(10, 10);
gfx->setTextSize(5 /* x scale */, 5 /* y scale */, 2 /* pixel_margin */);
gfx->println(color_name[color_index]);
stopTime = millis();
gfx->setCursor(10, 60);
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->printf("Arduino_RPiPicoSPI");
gfx->setCursor(10, 100);
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx->printf("%i ms", stopTime-startTime);
//
startTime = millis();
gfx2->fillScreen(color[color_index]);
gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, color[color_index]^0xFFFF);
gfx2->setTextColor(color[color_index]^0xFFFF);
gfx2->setCursor(10, 10);
gfx2->setTextSize(5 /* x scale */, 5 /* y scale */, 2 /* pixel_margin */);
gfx2->println(color_name[color_index]);
stopTime = millis();
gfx2->setCursor(10, 60);
gfx2->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx2->printf("Arduino_SWSPI");
gfx2->setCursor(10, 100);
gfx2->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx2->printf("%i ms", stopTime-startTime);
color_index++;
if (color_index==num_of_color){
color_index = 0;
}
delay(1000); // 1 second
}
rpPico2W_Arduino_GFX_Dual_170x320_random.ino, Random Pattern.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Random pattern
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART 35
#define TFT_ROWSTART 0
#define TFT2_ROTATION 0
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 35
#define TFT2_ROWSTART 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART, TFT2_ROWSTART);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library - Random Pattern");
// Init Display
gfx->begin();
gfx2->begin();
gfx->fillScreen(RGB565_BLACK);
gfx2->fillScreen(RGB565_BLACK);
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);
gfx->setCursor(10, 10);
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx->println("Raspberry Pi Pico 2 W");
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->println();
gfx->println("Arduino_GFX_Library");
gfx2->setCursor(10, 10);
gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx2->println("Dual ST7789 exercise");
gfx2->println("Random Pattern");
delay(5000); // 5 seconds
gfx->fillScreen(RGB565_BLACK);
gfx2->fillScreen(RGB565_BLACK);
}
void loop()
{
// Draw random circle in gfx
if (random(0, 2)) {
gfx->fillCircle(random(gfx->width()), random(gfx->height()), random(30), random(0xffff));
} else {
gfx->drawCircle(random(gfx->width()), random(gfx->height()), random(30), random(0xffff));
}
// Draw random circle in gfx2
gfx2->drawLine(random(gfx->width()), random(gfx->height()), random(gfx->width()), random(gfx->height()), random(0xffff));
//delay(500);
}
rpPico2W_Arduino_GFX_Dual_170x320_rot.ino, Rotation.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Rotation
Notice:
For 170*320 ST7789, to set rotation involve COLSTART2 and ROWSTART2.
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
/*
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART1 35
#define TFT_ROWSTART1 0
#define TFT_COLSTART2 0
#define TFT_ROWSTART2 0
#define TFT2_ROTATION 1
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART1 0
#define TFT2_ROWSTART1 0
#define TFT2_COLSTART2 35
#define TFT2_ROWSTART2 0
#define TFT_ROTATION 2
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART1 0
#define TFT_ROWSTART1 0
#define TFT_COLSTART2 35
#define TFT_ROWSTART2 0
#define TFT2_ROTATION 3
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART1 35
#define TFT2_ROWSTART1 0
#define TFT2_COLSTART2 0
#define TFT2_ROWSTART2 0
*/
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART1 35
#define TFT_ROWSTART1 0
#define TFT_COLSTART2 0
#define TFT_ROWSTART2 0
#define TFT2_ROTATION 1
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART1 0
#define TFT2_ROWSTART1 0
#define TFT2_COLSTART2 35
#define TFT2_ROWSTART2 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART1, TFT_ROWSTART1,
TFT_COLSTART2, TFT_ROWSTART2);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART1, TFT2_ROWSTART1,
TFT2_COLSTART2, TFT2_ROWSTART2);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library - Rotation");
// Init Display
gfx->begin();
gfx2->begin();
gfx->fillScreen(RGB565_BLACK);
gfx2->fillScreen(RGB565_BLACK);
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);
gfx->setCursor(10, 10);
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx->println("Raspberry Pi Pico 2 W");
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->println();
gfx->println("Arduino_GFX_Library");
gfx2->setCursor(10, 10);
gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx2->println("Dual ST7789 exercise");
gfx2->println("Rotation");
delay(5000); // 5 seconds
}
#define num_of_color 5
int color[num_of_color] = {RGB565_RED, RGB565_GREEN, RGB565_BLUE, RGB565_WHITE, RGB565_BLACK};
String color_name[num_of_color] = {"RED", "GREEN", "BLUE", "WHITE", "BLACK"};
int color_index = 0;
void loop()
{
unsigned long startTime, stopTime;
//
startTime = millis();
gfx->fillScreen(color[color_index]);
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, color[color_index]^0xFFFF);
gfx->setTextColor(color[color_index]^0xFFFF);
gfx->setCursor(10, 10);
gfx->setTextSize(5 /* x scale */, 5 /* y scale */, 2 /* pixel_margin */);
gfx->println(color_name[color_index]);
stopTime = millis();
gfx->setCursor(10, 60);
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->printf("Arduino_RPiPicoSPI");
gfx->setCursor(10, 100);
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx->printf("%i ms", stopTime-startTime);
//
startTime = millis();
gfx2->fillScreen(color[color_index]);
gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, color[color_index]^0xFFFF);
gfx2->setTextColor(color[color_index]^0xFFFF);
gfx2->setCursor(10, 10);
gfx2->setTextSize(5 /* x scale */, 5 /* y scale */, 2 /* pixel_margin */);
gfx2->println(color_name[color_index]);
stopTime = millis();
gfx2->setCursor(10, 60);
gfx2->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx2->printf("Arduino_SWSPI");
gfx2->setCursor(10, 100);
gfx2->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx2->printf("%i ms", stopTime-startTime);
color_index++;
if (color_index==num_of_color){
color_index = 0;
}
delay(1000); // 1 second
}
rpPico2W_Arduino_GFX_Dual_170x320_grouped.ino, Grouped two LCD in one canvas - left/right.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Grouped two LCD in one canvas, in rotation=0, left (170*320) + right (170*320) = canvas (340*320)
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART 35
#define TFT_ROWSTART 0
#define TFT2_ROTATION 0
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 35
#define TFT2_ROWSTART 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *lcd1 = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *lcd2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART, TFT2_ROWSTART);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
// Create a grouped Canvas (340x320): left 170x320 + right 170x320
Arduino_Canvas *canvas = new Arduino_Canvas(340, 320, nullptr);
uint16_t *fb;
// Custom flush,to draw canvas on both LCD
void flushDualLCD() {
for (int y = 0; y < 320; y++) {
// left (0..169)
lcd1->draw16bitRGBBitmap(0, y, fb + y * 340, 170, 1);
// right (170..339)
lcd2->draw16bitRGBBitmap(0, y, fb + y * 340 + 170, 170, 1);
}
}
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library - Grouped two LCD in one canvas.");
// Init Display
lcd1->begin();
lcd2->begin();
canvas->begin();
fb = canvas->getFramebuffer();
canvas->fillScreen(RGB565_BLACK);
flushDualLCD();
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
canvas->drawRect(0, 0, canvas->width()-1, canvas->height()-1, RGB565_WHITE);
flushDualLCD();
}
void loop()
{
// Draw random circle in canvas
if (random(0, 2)) {
canvas->fillCircle(random(canvas->width()), random(canvas->height()), random(30), random(0xffff));
} else {
canvas->drawCircle(random(canvas->width()), random(canvas->height()), random(30), random(0xffff));
}
flushDualLCD();
//delay(100);
}
rpPico2W_Arduino_GFX_Dual_170x320_grouped_cube.ino, Display a floating cube in grouped canvas, left/right.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Grouped two LCD in one canvas, in rotation=0, left (170*320) + right (170*320) = canvas (340*320)
Display a floating cube.
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART 35
#define TFT_ROWSTART 0
#define TFT2_ROTATION 0
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 35
#define TFT2_ROWSTART 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *lcd1 = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *lcd2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART, TFT2_ROWSTART);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
// Create a grouped Canvas (340x320): left 170x320 + right 170x320
Arduino_Canvas *canvas = new Arduino_Canvas(340, 320, nullptr);
uint16_t *fb;
float angleX = 0, angleY = 0, angleZ = 0;
float scale = 2000;
float distance = 1000;
// Custom flush,to draw canvas on both LCD
void flushDualLCD() {
for (int y = 0; y < 320; y++) {
// left (0..169)
lcd1->draw16bitRGBBitmap(0, y, fb + y * 340, 170, 1);
// right (170..339)
lcd2->draw16bitRGBBitmap(0, y, fb + y * 340 + 170, 170, 1);
}
}
// Multi-axis rotation function
void rotate3D(float &x, float &y, float &z, float ax, float ay, float az) {
float ty = y * cos(ax) - z * sin(ax);
float tz = y * sin(ax) + z * cos(ax);
y = ty; z = tz;
float tx = x * cos(ay) + z * sin(ay);
tz = -x * sin(ay) + z * cos(ay);
x = tx; z = tz;
tx = x * cos(az) - y * sin(az);
ty = x * sin(az) + y * cos(az);
x = tx; y = ty;
}
float cube[8][3] = {
{-40, -40, -40}, {40, -40, -40}, {40, 40, -40}, {-40, 40, -40},
{-40, -40, 40}, {40, -40, 40}, {40, 40, 40}, {-40, 40, 40}
};
int edges[12][2] = {
{0,1},{1,2},{2,3},{3,0},
{4,5},{5,6},{6,7},{7,4},
{0,4},{1,5},{2,6},{3,7}
};
void drawCube(){
int projected[8][2];
for (int i = 0; i < 8; i++) {
float x = cube[i][0], y = cube[i][1], z = cube[i][2];
rotate3D(x, y, z, angleX, angleY, angleZ);
int sx = (int)(x * scale / (z + distance)) + canvas->width()/2;
int sy = (int)(y * scale / (z + distance)) + canvas->height()/2;
projected[i][0] = sx;
projected[i][1] = sy;
}
canvas->fillScreen(RGB565_BLACK);
for (int e = 0; e < 12; e++) {
int a = edges[e][0], b = edges[e][1];
canvas->drawLine(projected[a][0], projected[a][1],
projected[b][0], projected[b][1], RGB565_WHITE);
}
//draw a small triangle on bottom right to show the canvas direction
canvas->fillTriangle(canvas->width()-5, canvas->height()-5,
canvas->width()-5, canvas->height()-25,
canvas->width()-25, canvas->height()-5,
RGB565_YELLOW);
}
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library - Display a floating cube in grouped canvas");
// Init Display
lcd1->begin();
lcd2->begin();
canvas->begin();
fb = canvas->getFramebuffer();
canvas->fillScreen(RGB565_BLACK);
flushDualLCD();
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
canvas->drawRect(0, 0, canvas->width()-1, canvas->height()-1, RGB565_WHITE);
flushDualLCD();
}
void loop()
{
drawCube();
unsigned long startTime, stopTime;
startTime = millis();
flushDualLCD();
stopTime = millis();
//Display on lcd1 directly
lcd1->setCursor(10, 10);
lcd1->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
lcd1->printf("%i ms", stopTime-startTime);
angleX += 0.03;
angleY += 0.02;
angleZ += 0.04;
delay(100);
}
rpPico2W_Arduino_GFX_Dual_170x320_grouped_cube_topbottom.ino, Display a floating cube in grouped canvas, top/bottom.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Grouped two LCD in one canvas, in rotation=3, top (320*170) + bottom (320*170) = canvas (320*340)
Display a floating cube.
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
#define TFT_ROTATION 3
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART1 35
#define TFT_ROWSTART1 0
#define TFT_COLSTART2 0
#define TFT_ROWSTART2 0
#define TFT2_ROTATION 3
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART1 35
#define TFT2_ROWSTART1 0
#define TFT2_COLSTART2 0
#define TFT2_ROWSTART2 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *lcd1 = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART1, TFT_ROWSTART1,
TFT_COLSTART2, TFT_ROWSTART2);
Arduino_GFX *lcd2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART1, TFT2_ROWSTART1,
TFT2_COLSTART2, TFT2_ROWSTART2);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
// Create a grouped Canvas (340x320): top 320x170 + bottom 320x170
Arduino_Canvas *canvas = new Arduino_Canvas(320, 340, nullptr);
uint16_t *fb;
float angleX = 0, angleY = 0, angleZ = 0;
float scale = 2000;
float distance = 1000;
// Custom flush to draw canvas on both LCD
// With LCDs arranged as top/bottom, draw16bitRGBBitmap() fill in a area rather that line-by-line.
// But, in my test, it's no signification improvement in speed.
void flushDualLCD() {
// up (0..319)
lcd1->draw16bitRGBBitmap(0, 0, fb, 320, 170);
// down (320..639);
lcd2->draw16bitRGBBitmap(0, 0, fb + 320*170, 320, 170);
}
// Multi-axis rotation function
void rotate3D(float &x, float &y, float &z, float ax, float ay, float az) {
float ty = y * cos(ax) - z * sin(ax);
float tz = y * sin(ax) + z * cos(ax);
y = ty; z = tz;
float tx = x * cos(ay) + z * sin(ay);
tz = -x * sin(ay) + z * cos(ay);
x = tx; z = tz;
tx = x * cos(az) - y * sin(az);
ty = x * sin(az) + y * cos(az);
x = tx; y = ty;
}
float cube[8][3] = {
{-40, -40, -40}, {40, -40, -40}, {40, 40, -40}, {-40, 40, -40},
{-40, -40, 40}, {40, -40, 40}, {40, 40, 40}, {-40, 40, 40}
};
int edges[12][2] = {
{0,1},{1,2},{2,3},{3,0},
{4,5},{5,6},{6,7},{7,4},
{0,4},{1,5},{2,6},{3,7}
};
void drawCube(){
int projected[8][2];
for (int i = 0; i < 8; i++) {
float x = cube[i][0], y = cube[i][1], z = cube[i][2];
rotate3D(x, y, z, angleX, angleY, angleZ);
int sx = (int)(x * scale / (z + distance)) + canvas->width()/2;
int sy = (int)(y * scale / (z + distance)) + canvas->height()/2;
projected[i][0] = sx;
projected[i][1] = sy;
}
canvas->fillScreen(RGB565_BLACK);
for (int e = 0; e < 12; e++) {
int a = edges[e][0], b = edges[e][1];
canvas->drawLine(projected[a][0], projected[a][1],
projected[b][0], projected[b][1], RGB565_WHITE);
}
//draw a small triangle to show the direction
canvas->fillTriangle(canvas->width()-5, canvas->height()-5,
canvas->width()-5, canvas->height()-25,
canvas->width()-25, canvas->height()-5,
RGB565_YELLOW);
}
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library - Display a floating cube in grouped canvas");
// Init Display
lcd1->begin();
lcd2->begin();
canvas->begin();
fb = canvas->getFramebuffer();
canvas->fillScreen(RGB565_BLACK);
flushDualLCD();
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
canvas->drawRect(0, 0, canvas->width()-1, canvas->height()-1, RGB565_WHITE);
flushDualLCD();
}
void loop()
{
drawCube();
unsigned long startTime, stopTime;
startTime = millis();
flushDualLCD();
stopTime = millis();
//Display on lcd1 directly
lcd1->setCursor(10, 10);
lcd1->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
lcd1->printf("%i ms", stopTime-startTime);
angleX += 0.03;
angleY += 0.02;
angleZ += 0.04;
delay(100);
}
rpPico2W_Arduino_GFX_Dual_170x320_Spiral_Sierpinsk.ino, Grouped two LCD as one canvas, display Spiral and Sierpinski.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.
Using separated SPI.
- 1st LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_RPiPicoSPI)
- 2nd LCD 1.9" 170*320 ST7789 SPI LCD (Arduino_SWSPI)
Grouped two LCD as one canvas, display Spiral and Sierpinski.
details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-two-19.html
Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico
Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html
*/
/*******************************************************************************
* Start of Arduino_GFX setting
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define SPI1_SCK 18
#define SPI1_MOSI 19
#define TFT1_RST 22
#define TFT1_DC 21
#define TFT1_CS 17
#define SPI2_SCK 14
#define SPI2_MOSI 15
#define TFT2_RST 28
#define TFT2_DC 27
#define TFT2_CS 26
#define TFT_BL 20
#define TFT_ROTATION 0
#define TFT_WIDTH 170
#define TFT_HEIGHT 320
#define TFT_COLSTART 35
#define TFT_ROWSTART 0
#define TFT2_ROTATION 0
#define TFT2_WIDTH 170
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 35
#define TFT2_ROWSTART 0
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT1_DC, TFT1_CS, SPI1_SCK, SPI1_MOSI, GFX_NOT_DEFINED /* MISO */);
//Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_SWSPI(TFT2_DC, TFT2_CS, SPI2_SCK, SPI2_MOSI, GFX_NOT_DEFINED /* MISO */);
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *lcd1 = new Arduino_ST7789(bus, TFT1_RST, TFT_ROTATION, true /* IPS */,
TFT_WIDTH, TFT_HEIGHT,
TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *lcd2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
TFT2_WIDTH, TFT2_HEIGHT,
TFT2_COLSTART, TFT2_ROWSTART);
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
// Create a grouped Canvas (340x320): left 170x320 + right 170x320
Arduino_Canvas *canvas = new Arduino_Canvas(340, 320, nullptr);
uint16_t *fb;
int sierpinski_color = RGB565_WHITE;
int sierpinski_depth = 0;
// Custom flush,to draw canvas on both LCD
void flushDualLCD() {
for (int y = 0; y < 320; y++) {
// left (0..169)
lcd1->draw16bitRGBBitmap(0, y, fb + y * 340, 170, 1);
// right (170..339)
lcd2->draw16bitRGBBitmap(0, y, fb + y * 340 + 170, 170, 1);
}
}
void setup(void)
{
delay(1000);
Serial.begin(115200);
delay(500);
Serial.println("--- Start ---");
Serial.println("Arduino_GFX_Library - Display Spiral and Sierpinski");
// Init Display
lcd1->begin();
lcd2->begin();
canvas->begin();
fb = canvas->getFramebuffer();
canvas->fillScreen(RGB565_BLACK);
flushDualLCD();
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); //Turn On Backlight
canvas->drawRect(0, 0, canvas->width()-1, canvas->height()-1, RGB565_WHITE);
flushDualLCD();
drawSpiral();
flushDualLCD();
delay(5000);
}
void drawSpiral(){
int centerX = canvas->width()*2/3;
int centerY = canvas->height()*2/3;
for (float t=0; t<90*PI; t+=0.1) {
int x = centerX + (int)(t * cos(t));
int y = centerY + (int)(t * sin(t));
canvas->drawPixel(x, y, canvas->color565((int)(t*20)%255, 255, 255));
}
}
void drawSierpinski(int x0, int y0, int x1, int y1, int x2, int y2, int depth) {
if (depth == 0) {
canvas->fillTriangle(x0, y0, x1, y1, x2, y2, sierpinski_color);
} else {
int mx01 = (x0 + x1) / 2;
int my01 = (y0 + y1) / 2;
int mx12 = (x1 + x2) / 2;
int my12 = (y1 + y2) / 2;
int mx20 = (x2 + x0) / 2;
int my20 = (y2 + y0) / 2;
drawSierpinski(x0, y0, mx01, my01, mx20, my20, depth - 1);
drawSierpinski(x1, y1, mx12, my12, mx01, my01, depth - 1);
drawSierpinski(x2, y2, mx20, my20, mx12, my12, depth - 1);
}
}
void loop()
{
canvas->fillScreen(RGB565_BLACK);
drawSierpinski(10, canvas->height()-10,
canvas->width()-10, canvas->height()-10,
canvas->width()/2, 10,
sierpinski_depth);
flushDualLCD();
//Display on lcd1 directly
lcd1->setCursor(10, 10);
lcd1->setTextSize(2, 2, 2);
lcd1->printf("depth: %i", sierpinski_depth);
sierpinski_depth=sierpinski_depth+1;
if (sierpinski_depth >=8){
sierpinski_depth = 0;
sierpinski_color = RGB565(random(220, 256), random(220, 256), random(220, 256));
}
delay(200);
}
Comments
Post a Comment