arduino:displays_for_classic_arduinos:1.8_and_1.44_tft_displays_and_classic_arduinos
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
arduino:displays_for_classic_arduinos:1.8_and_1.44_tft_displays_and_classic_arduinos [2018/01/27 22:48] – [Arduino TFT library] mithat | arduino:displays_for_classic_arduinos:1.8_and_1.44_tft_displays_and_classic_arduinos [2018/01/28 01:56] – [Adafruit ST7735 Library] mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 1.8" and 1.44" TFT Displays | + | ====== 1.8" and 1.44" TFT displays |
- | ===== Summary | + | ===== Summary |
Small 1.8" (160x128) and 1.44" (128x128) TFT displays with ST7735 controllers have been available for a while now. They are only slightly more expensive than the very inexpensive [[arduino: | Small 1.8" (160x128) and 1.44" (128x128) TFT displays with ST7735 controllers have been available for a while now. They are only slightly more expensive than the very inexpensive [[arduino: | ||
- | One of the concerns with with TFT displays is that they are data gluttons, meaning they put a lot of stress on piddly Uno/ | + | One of the concerns with with TFT displays is that they are data gluttons, meaning they put a lot of stress on a piddly Uno/ |
Unfortunately, | Unfortunately, | ||
Line 16: | Line 16: | ||
==== Ucglib ==== | ==== Ucglib ==== | ||
- | Oli Kraus' [[https:// | + | Oli Kraus' [[https:// |
I ran two test cases: one using transparent font rendering and the other with solid. In both cases, faster hardware SPI was used over slower software SPI. I ran both test cases with both a 3.3V 8 MHz Pro Mini and a 5V 16 MHz Nano, for a total of four tests. | I ran two test cases: one using transparent font rendering and the other with solid. In both cases, faster hardware SPI was used over slower software SPI. I ran both test cases with both a 3.3V 8 MHz Pro Mini and a 5V 16 MHz Nano, for a total of four tests. | ||
Line 24: | Line 24: | ||
Solid rendering with a 16 MHz processor is //almost// good enough, but a 16 Mhz implementation requires level shifting since no 16 MHz 3.3V boards are available. | Solid rendering with a 16 MHz processor is //almost// good enough, but a 16 Mhz implementation requires level shifting since no 16 MHz 3.3V boards are available. | ||
- | === Solid mode === | + | === Solid font rendering |
- | <file c++ display_st7735_1.44_ucglib_solid.ino> | + | {{youtube>eqLvI47nUFI? |
- | /* | + | |
- | * display_st7735_1.44_ucglib_solid.ino | + | |
- | | + | |
- | * Test screen update speed with large solid fonts on | + | |
- | * a 128x128 TFT screen that uses the ST7735 chip. | + | |
- | * | + | |
- | * Consumes 56% of program storage space and | + | |
- | * 13% of dynamic memory on a Pro Mini. | + | |
- | * | + | |
- | * Mithat Konar | + | |
- | */ | + | |
- | #include " | + | {{youtube> |
- | /* | + | [[display_st7735_1.44_ucglib_solid.ino | source code]] |
- | * Pin assignments: | + | |
- | * RST: 8 | + | |
- | * CE/CS/SCE: 10 | + | |
- | * DC/" | + | |
- | * DIN/ | + | |
- | * CLK/ | + | |
- | * VCC: 3.3V | + | |
- | * LIGHT/LED: ground through 1 ohm resistor (yields about 20mA) | + | |
- | * GND: ground | + | |
- | */ | + | |
- | const unsigned int CLOCK_PIN | + | === Transparent font rendering === |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | Ucglib_ST7735_18x128x160_HWSPI ucg(DC_PIN, CS_PIN, RESET_PIN); | + | {{youtube> |
- | unsigned int counter | + | {{youtube> |
- | void setup(void) | + | [[display_st7735_1.44_ucglib_transparent.ino | source code]] |
- | { | + | |
- | delay(1000); | + | |
- | ucg.begin(UCG_FONT_MODE_SOLID); | + | |
- | ucg.clearScreen(); | + | |
- | } | + | |
- | + | ||
- | void loop(void) | + | |
- | { | + | |
- | ucg.setColor(0, | + | |
- | ucg.setColor(1, | + | |
- | + | ||
- | ucg.setFont(ucg_font_profont15_mr); | + | |
- | ucg.setPrintPos(0, | + | |
- | ucg.print(" | + | |
- | + | ||
- | ucg.setFont(ucg_font_inr49_mr); | + | |
- | counter++; | + | |
- | + | ||
- | // draw new value | + | |
- | ucg.setPrintPos(0, | + | |
- | ucg.print(counter); | + | |
- | + | ||
- | // inherent frame rate of this loop is about 1 fps (8Mhz) | + | |
- | // and about 1.9 fps (16MHz) w/o added delay. | + | |
- | delay(500); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | === Transparent mode === | + | |
- | + | ||
- | <file c++ display_st7735_1.44_ucglib_transparent> | + | |
- | /* | + | |
- | * display_st7735_1.44_ucglib_transparent | + | |
- | * | + | |
- | * Test screen update speed with large transparent fonts on | + | |
- | * a 128x128 TFT screen that uses the ST7735 chip. | + | |
- | | + | |
- | * Consumes 53% of program storage space and | + | |
- | * 13% of dynamic memory on a Pro Mini. | + | |
- | * | + | |
- | * Mithat Konar | + | |
- | */ | + | |
- | + | ||
- | //#include < | + | |
- | #include " | + | |
- | + | ||
- | /* | + | |
- | * Pin assignments: | + | |
- | * RST: 8 | + | |
- | * CE/CS/SCE: 10 | + | |
- | * DC/" | + | |
- | * DIN/ | + | |
- | * CLK/ | + | |
- | * VCC: 3.3V | + | |
- | * LIGHT/LED: ground through 1 ohm resistor (yields about 20mA) | + | |
- | * GND: ground | + | |
- | */ | + | |
- | + | ||
- | const unsigned int CLOCK_PIN = 13, | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | Ucglib_ST7735_18x128x160_HWSPI ucg(DC_PIN, CS_PIN, RESET_PIN); | + | |
- | + | ||
- | unsigned int counter = 80; | + | |
- | + | ||
- | void setup(void) | + | |
- | { | + | |
- | delay(1000); | + | |
- | ucg.begin(UCG_FONT_MODE_TRANSPARENT); | + | |
- | ucg.clearScreen(); | + | |
- | } | + | |
- | + | ||
- | void loop(void) | + | |
- | { | + | |
- | ucg.setFont(ucg_font_7x13_tf); | + | |
- | ucg.setPrintPos(0, | + | |
- | ucg.setColor(255, | + | |
- | ucg.print(" | + | |
- | + | ||
- | ucg.setFont(ucg_font_logisoso58_tr); | + | |
- | + | ||
- | // because the font is rendered transparent, | + | |
- | // you need to clear the screen | + | |
- | // ucg.clearScreen(); | + | |
- | + | ||
- | // or draw over previous glyphs in background color | + | |
- | ucg.setColor(0, | + | |
- | ucg.setPrintPos(0, | + | |
- | ucg.print(counter); | + | |
- | + | ||
- | counter++; | + | |
- | + | ||
- | // draw new value | + | |
- | ucg.setColor(255, | + | |
- | ucg.setPrintPos(0, | + | |
- | ucg.print(counter); | + | |
- | + | ||
- | /* With 8MHz processor, inherent frame rate of this loop is about | + | |
- | 1.2 fps with ucg.clearScreen(), | + | |
- | With 16MHz processor, inherent frame rate of this loop is about | + | |
- | 2.4 fps with ucg.clearScreen(), | + | |
- | w/o added delay. The ucg.clearScreen() approach results in unacceptable | + | |
- | | + | |
- | delay(500); | + | |
- | } | + | |
- | </ | + | |
==== Arduino TFT library==== | ==== Arduino TFT library==== | ||
Line 180: | Line 46: | ||
Overall, the results are fast, but you need to be OK with the blocky text rendering and integer font size scaling. While blocky fonts have a certain charm, it's not the right charm for most applications. | Overall, the results are fast, but you need to be OK with the blocky text rendering and integer font size scaling. While blocky fonts have a certain charm, it's not the right charm for most applications. | ||
- | <file c++ display_st7735_1.44_TFT.ino> | + | {{youtube>P_bLs5rMH5c? |
- | /* | + | |
- | * display_st7735_1.44_TFT.ino | + | |
- | | + | |
- | * Test screen update speed with large solid fonts on | + | |
- | * a 128x128 TFT screen that uses the ST7735 chip. | + | |
- | | + | |
- | * Consumes 26% of program storage space and | + | |
- | * 5% of dynamic memory on a Pro Mini. | + | |
- | * | + | |
- | * Mithat Konar | + | |
- | */ | + | |
- | #include <TFT.h> // Arduino LCD library | + | [[display_st7735_1.44_TFT.ino | source code]] |
- | #include <SPI.h> | + | |
- | /* | ||
- | * Pin assignments: | ||
- | * RST: 8 | ||
- | * CE/CS/SCE: 10 | ||
- | * DC/" | ||
- | * DIN/ | ||
- | * CLK/ | ||
- | * VCC: 3.3V | ||
- | * LIGHT/LED: ground through 1 ohm resistor (yields about 20mA) | ||
- | * GND: ground | ||
- | */ | ||
- | |||
- | const unsigned int CLOCK_PIN = 13, | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | const unsigned int LEFT_MARGIN = 32; // number of pixels you need to shift for 128x128 screen | ||
- | |||
- | |||
- | TFT TFTscreen = TFT(CS_PIN, DC_PIN, RESET_PIN); | ||
- | char dispStr[4]; | ||
- | unsigned int counter = 80; | ||
- | |||
- | void setup() { | ||
- | TFTscreen.begin(); | ||
- | TFTscreen.background(0, | ||
- | |||
- | TFTscreen.stroke(255, | ||
- | TFTscreen.setTextSize(1); | ||
- | TFTscreen.text(" | ||
- | | ||
- | TFTscreen.setTextSize(7); | ||
- | } | ||
- | |||
- | void loop() { | ||
- | // draw over what you wrote last time | ||
- | TFTscreen.stroke(0, | ||
- | String(counter).toCharArray(dispStr, | ||
- | TFTscreen.text(dispStr, | ||
- | |||
- | // update and draw something new | ||
- | counter++; | ||
- | |||
- | TFTscreen.stroke(255, | ||
- | String(counter).toCharArray(dispStr, | ||
- | TFTscreen.text(dispStr, | ||
- | |||
- | // inherent frame rate of this loop is about 15 fps w/o added delay (8 MHz processor). | ||
- | delay(500); | ||
- | } | ||
- | |||
- | </ | ||
==== Adafruit ST7735 Library ==== | ==== Adafruit ST7735 Library ==== | ||
Line 259: | Line 59: | ||
The Adafruit library with its default font performs and looks almost the same as the Arduino TFT library. | The Adafruit library with its default font performs and looks almost the same as the Arduino TFT library. | ||
- | <file c++ display_st7735_1.44_adafruit_st7735.ino> | + | FIXME video |
- | /* | + | |
- | * display_st7735_1.44_adafruit_st7735.ino | + | |
- | | + | |
- | * Test screen update speed with large default fonts on | + | |
- | * a 128x128 TFT screen that uses the ST7735 chip. | + | |
- | * | + | |
- | * Consumes 26% of program storage space and | + | |
- | * 6% of dynamic memory on a Pro Mini. | + | |
- | * | + | |
- | * Mithat Konar | + | |
- | */ | + | |
- | #include < | + | [[display_st7735_1.44_adafruit_st7735.ino | source code]] |
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | /* | + | |
- | * Pin assignments: | + | |
- | * RST: 8 | + | |
- | * CE/CS/SCE: 10 | + | |
- | * DC/" | + | |
- | * DIN/ | + | |
- | * CLK/ | + | |
- | * VCC: 3.3V | + | |
- | * LIGHT/LED: ground through 1 ohm resistor (yields about 20mA) | + | |
- | * GND: ground | + | |
- | */ | + | |
- | + | ||
- | const unsigned int CLOCK_PIN = 13, | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | const unsigned int TOP_MARGIN = 32; // number of pixels you need to shift for 128x128 screen | + | |
- | + | ||
- | // Use hardware SPI. | + | |
- | Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, | + | |
- | unsigned int counter = 80; | + | |
- | + | ||
- | void setup(void) { | + | |
- | // mfk note: neither initializer below works for the 128x128 | + | |
- | tft.initR(INITR_BLACKTAB); | + | |
- | // tft.initR(INITR_144GREENTAB); | + | |
- | + | ||
- | tft.fillScreen(ST7735_BLACK); | + | |
- | tft.setTextWrap(false); | + | |
- | + | ||
- | tft.setCursor(0, | + | |
- | tft.setTextSize(1); | + | |
- | tft.setTextColor(ST7735_WHITE); | + | |
- | tft.setTextWrap(true); | + | |
- | tft.print(" | + | |
- | } | + | |
- | + | ||
- | void loop() { | + | |
- | tft.setTextSize(7); | + | |
- | + | ||
- | // draw over what you wrote last time | + | |
- | tft.setCursor(0, | + | |
- | tft.setTextColor(ST7735_BLACK); | + | |
- | tft.print(counter); | + | |
- | + | ||
- | // update and draw something new | + | |
- | counter++; | + | |
- | tft.setCursor(0, | + | |
- | tft.setTextColor(ST7735_WHITE); | + | |
- | tft.print(counter); | + | |
- | + | ||
- | // inherent frame rate of this loop is about 15 fps w/o added delay (8 MHz processor). | + | |
- | delay(500); | + | |
- | } | + | |
- | + | ||
- | </ | + | |
=== Fancy large font === | === Fancy large font === | ||
Line 339: | Line 67: | ||
When a large fancy font is used, the performance between the Adafruit library and Uclib narrows. I suspect that with a font as large as that used in the Uclib examples, the results would be close to identical. Which is to say, not fast (or light?) enough. | When a large fancy font is used, the performance between the Adafruit library and Uclib narrows. I suspect that with a font as large as that used in the Uclib examples, the results would be close to identical. Which is to say, not fast (or light?) enough. | ||
- | <file c++ display_st7735_1.44_adafruit_st7735_fonts.ino> | + | FIXME video |
- | /* | + | |
- | * display_st7735_1.44_adafruit_st7735_fonts.ino | + | |
- | | + | |
- | * Test screen update speed with large fancy font on | + | |
- | * a 128x128 TFT screen that uses the ST7735 chip. | + | |
- | * | + | |
- | * Consumes 53% of program storage space and | + | |
- | * 6% of dynamic memory on a Pro Mini. | + | |
- | * | + | |
- | * Mithat Konar | + | |
- | */ | + | |
- | + | ||
- | #include < | + | |
- | #include < | + | |
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | /* | + | |
- | * Pin assignments: | + | |
- | * RST: 8 | + | |
- | * CE/CS/SCE: 10 | + | |
- | * DC/" | + | |
- | * DIN/ | + | |
- | * CLK/ | + | |
- | * VCC: 3.3V | + | |
- | * LIGHT/LED: ground through 1 ohm resistor (yields about 20mA) | + | |
- | * GND: ground | + | |
- | */ | + | |
- | + | ||
- | const unsigned int CLOCK_PIN = 13, | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | const unsigned int TOP_MARGIN = 32; // number of pixels you need to shift for 128x128 screen | + | |
- | + | ||
- | // Use hardware SPI. | + | |
- | Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, | + | |
- | unsigned int counter = 80; | + | |
- | + | ||
- | void setup(void) { | + | |
- | // mfk note: neither initializer below works for the 128x128 | + | |
- | tft.initR(INITR_BLACKTAB); | + | |
- | // tft.initR(INITR_144GREENTAB); | + | |
- | + | ||
- | tft.fillScreen(ST7735_BLACK); | + | |
- | tft.setTextWrap(false); | + | |
- | + | ||
- | tft.setCursor(0, | + | |
- | tft.setTextSize(1); | + | |
- | tft.setTextColor(ST7735_WHITE); | + | |
- | tft.setTextWrap(true); | + | |
- | tft.print(" | + | |
- | + | ||
- | tft.setFont(& | + | |
- | } | + | |
- | + | ||
- | void loop() { | + | |
- | // draw over what you wrote last time | + | |
- | tft.setCursor(0, | + | |
- | tft.setTextColor(ST7735_BLACK); | + | |
- | tft.print(counter); | + | |
- | // update and draw something new | + | [[display_st7735_1.44_adafruit_st7735_fonts.ino | source code]] |
- | counter++; | + | |
- | tft.setCursor(0, | + | |
- | tft.setTextColor(ST7735_WHITE); | + | |
- | tft.print(counter); | + | |
- | + | ||
- | // inherent frame rate of this loop is about 2.5 fps w/o added delay (8 MHz processor). | + | |
- | delay(500); | + | |
- | } | + | |
- | </ |
arduino/displays_for_classic_arduinos/1.8_and_1.44_tft_displays_and_classic_arduinos.txt · Last modified: 2018/01/31 04:55 by mithat