gimpo
Well-known member
Just my little contribution here. I hope it help somebody.
Prologue
Before today, I was my using 1.44" TFT display from Aliexpress on my Arduino and (very) old Adarfruit libraries with success:
After "migrating" to Teensy 3.2 + latest version of Adafruit libraries* I was unable to achieve the same result: the 128x128 screen stay translated of some pixel towards right and/or up.
Even by tweaking the source code of the Adafruit_ST7735.cpp file at lines 223,224 I was not able to "center" the screen correctly. The same happens even by changing the screen orientation (with the setRotation() function).
(*) IIRC, versions 1.3.6 for GFX and version v. 1.2.6 for ST7735
Epilogue
After visiting this thread, I decided to give to the ST7735_t3 libs a chance. And they work!
The key is to tweak the code in the ST7735_t3.cpp file accordingly to the adopted rotation of the screen.
Here below the original code of the initR() function:
If you use the setRotation(2) function (screen upside-down), then tweak the code as follows:
if you use the standard screen orientation (i.e. setRotation(0)), then modify the code as follows:
Bonus
Here below a simple test code to verify your TFT.
It simply draw a tiny blue square in the up-left corner and a tiny red square in the bottom-right corner. It also print a surrounding green frame to check that all of the 128x128 area is available and visible.
Prologue
Before today, I was my using 1.44" TFT display from Aliexpress on my Arduino and (very) old Adarfruit libraries with success:
After "migrating" to Teensy 3.2 + latest version of Adafruit libraries* I was unable to achieve the same result: the 128x128 screen stay translated of some pixel towards right and/or up.
Even by tweaking the source code of the Adafruit_ST7735.cpp file at lines 223,224 I was not able to "center" the screen correctly. The same happens even by changing the screen orientation (with the setRotation() function).
(*) IIRC, versions 1.3.6 for GFX and version v. 1.2.6 for ST7735
Epilogue
After visiting this thread, I decided to give to the ST7735_t3 libs a chance. And they work!
The key is to tweak the code in the ST7735_t3.cpp file accordingly to the adopted rotation of the screen.
Here below the original code of the initR() function:
Code:
// Initialization for ST7735R screens (green or red tabs)
void ST7735_t3::initR(uint8_t options)
{
commonInit(Rcmd1);
if (options == INITR_GREENTAB) {
commandList(Rcmd2green);
colstart = 2;
rowstart = 1;
} else if(options == INITR_144GREENTAB) {
_height = ST7735_TFTHEIGHT_144;
commandList(Rcmd2green144);
colstart = 2;
rowstart = 3;
} else {
// colstart, rowstart left at default '0' values
commandList(Rcmd2red);
}
commandList(Rcmd3);
// if black, change MADCTL color filter
if (options == INITR_BLACKTAB) {
writecommand(ST7735_MADCTL);
writedata(0xC0);
}
tabcolor = options;
}
If you use the setRotation(2) function (screen upside-down), then tweak the code as follows:
Code:
// Initialization for ST7735R screens (green or red tabs)
void ST7735_t3::initR(uint8_t options)
{
commonInit(Rcmd1);
if (options == INITR_GREENTAB) {
commandList(Rcmd2green);
colstart = 2;
rowstart = 1;
} else if(options == INITR_144GREENTAB) {
_height = ST7735_TFTHEIGHT_144;
commandList(Rcmd2green144);
colstart = 0; // <----- Here!
rowstart = 0; // <----- Here!
} else {
// colstart, rowstart left at default '0' values
commandList(Rcmd2red);
}
commandList(Rcmd3);
// if black, change MADCTL color filter
if (options == INITR_BLACKTAB) {
writecommand(ST7735_MADCTL);
writedata(0xC0);
}
tabcolor = options;
}
if you use the standard screen orientation (i.e. setRotation(0)), then modify the code as follows:
Code:
// Initialization for ST7735R screens (green or red tabs)
void ST7735_t3::initR(uint8_t options)
{
commonInit(Rcmd1);
if (options == INITR_GREENTAB) {
commandList(Rcmd2green);
colstart = 2;
rowstart = 1;
} else if(options == INITR_144GREENTAB) {
_height = ST7735_TFTHEIGHT_144;
commandList(Rcmd2green144);
colstart = 0; // <----- Here!
rowstart = 32; // <----- Here!
} else {
// colstart, rowstart left at default '0' values
commandList(Rcmd2red);
}
commandList(Rcmd3);
// if black, change MADCTL color filter
if (options == INITR_BLACKTAB) {
writecommand(ST7735_MADCTL);
writedata(0xC0);
}
tabcolor = options;
}
Bonus
Here below a simple test code to verify your TFT.
It simply draw a tiny blue square in the up-left corner and a tiny red square in the bottom-right corner. It also print a surrounding green frame to check that all of the 128x128 area is available and visible.
Code:
/*
* NOTE: file ST7735_t3.cpp was modified at lines 716,717 to make sketch working properly with ST7735/128x128/v2.1 TFT.
*
* if setOrientation(0), then set
*
* colstart = 0;
* rowstart = 32;
*
* if setOrientation(2), then set
*
* colstart = 0;
* rowstart = 0;
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <ST7735_t3.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
#define TFT_MOSI 11 // Data out
#define TFT_SCLK 13 // Clock out
ST7735_t3 tft = ST7735_t3(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void setup(void) {
tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab
tft.setRotation(2);
tft.fillScreen(ST7735_BLACK);
// up left
tft.fillRect(0,0,10, 10,ST7735_BLUE);
tft.setCursor(12,12);
tft.println("UP-LEFT");
delay(500);
// bottom right
tft.fillRect(tft.width()-10, tft.height()-10, 10, 10, ST7735_RED);
tft.setCursor(tft.width()-82,tft.height()-20);
tft.println("BOTTOM-RIGHT");
delay(500);
// area frame
tft.drawRect(0,0, tft.width(), tft.height(), ST7735_GREEN);
delay(1000);
}
void loop() {
}
Last edited: