horizontal scrolling text on tft screen

Hello every body and sorry for my poor english.

I use google translate.

Below the time displayed as HH:MM:SS across the width of the screen (320 pixel), I would like to make a nice horizontal scrolling of the date (saturday 30 september 2017) longer than the screen. Now it is shorter (sat 30 sep 2017)

The solution to remove the first letter by adding one at the end is way too jerky.

:slight_smile: Thanks to the wonderful work of David Prentice, here is a part of his code:

uint16_t scrollbuf[320]; 

int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
{   uint16_t *p;
    for(int row = 0; row < h; row++) 
    {   p = block + row * w;
        for(int col = 0; col < w; col++) 
        {   *p++ = tft.readPixel(x + col, y + row);
}   }   }

void windowScroll(int16_t x, int16_t y, int16_t wid, int16_t ht, int16_t dx, uint16_t *buf)
{  if(dx)
   {  for(int16_t row = 0; row < ht; row++) 
      {   READGRAM(x, y + row, buf, wid, 1);
          tft.setAddrWindow(x, y + row, x + wid - 1, y + row);
          tft.pushColors(buf + dx, wid - dx, 1);
          tft.pushColors(buf + 0, dx, 0);
}  }  }

setup
{
}

loop
{  tft.setTextSize(4);
   tft.setCursor(10,150);
   tft.print("saturday 30 september 2017");
   for(int16_t i = 320, dx = 4; i > 0; i -= dx) 
   {  windowScroll(0, 140, 320, 60, dx, scrollbuf);
}  }

I understood :

  • that a buffer scrollbuf [320] should be defined, (my sreen is 320px width and 240px height)
  • Copy each pixel of the screen to put it in scrollbuf.
  • shifting the beginning of scrollbuff to copy each pixel on the screen
  • Copying the shifting pixels to the end of the screen
  • And so on

How to have a text much longer than the width of the screen?
1)

  • convert all my texts (7x day, 12x month, 10x digit) into compiled images C,
  • save them in 840 files stored in the sd card,
  • read them as needed?
  • on a black screen (0x0000), write the entire date on two lines in near black color (0x0001),
  • concatenate the two lines in a bigger scrollbuf [640],
  • change the color 0x0001 to 0xFFFF,
  • write on the screen the two part of the offset date
  • do it for each offset?

A part of 1) and 2)

  • read the 8 necessary files from 840 on the sd card
  • concatenate them in a static scrollbuf [640]
  • ignore identical pixels if more than two characters longuer
    monday 1 may 2017
    saturday 30 september 2017
  • make 2 loops for the display (from the offset to the end and from the start to the offset)?

other …

What is the fastest solution to display and the least memory intensive?

Thank you very much for yours suggestions.

Most controllers can Scroll the whole screen vertically in hardware. Modern ones can scroll a specific band.

None of the supported controllers can scroll in both directions. (The RA8875 can)

So you are stuck with doing it in software. My graphictest_kbv example shows you how to move some text horizontally. This works quite pleasantly on a Uno, Due, Zero, ... but is really slow on Mega2560 or Leonardo.

If you want it to look faster:

  1. move several pixels at a time.
  2. move a larger block at a time.

But quite honestly, if it is known text, just redraw it in rubout mode. i.e. setTextColor(foreground, background)
Of course, this technique works with write-only screens (and every library)

Incidentally, a RA8875 can do this all in hardware. Faster than your eyes can see. Just like your VertScroll() can work instantly.

David.

david_prentice:
My graphictest_kbv example shows you how to move some text horizontally.

As I said, the code come from your job.

My tft screen is 2.4’ ili9342 320x240

My text is a date and change each day, I know it, but I do not understand what you mind

david_prentice:
just redraw it in rubout mode.

Now, with a short date as ‚Äúsat 30 sep 2017‚ÄĚ scroll horitally work fine.
My problem is with a long date as ‚Äúsaturday 30 september 2017‚ÄĚ because it is longer than 320 pixel.
How can I scroll this long date ?

I want something like that :

But much more fluid, less jerky.
Instead the text moves character after character, I would like it to be 1/4 character, and for that I have to use a graphical buffer ... How can I do this with "picture" more longer than 320 pixels ?

Make sure that you have an ‚Äúup to date‚ÄĚ Adafruit_GFX library. e.g. v1.2.2

Here is an example sketch:

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#include <fonts/FreeSans9pt7b.h>
#include <fonts/FreeSans12pt7b.h>
#include <fonts/FreeSans18pt7b.h>
#include <fonts/FreeSans24pt7b.h>

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup()
{
    uint16_t ID = tft.readID();
    tft.begin(ID);
    tft.setRotation(1);
}

void scrolltext(int x, int y, const char *s, uint8_t dw = 1, const GFXfont *f = NULL, int sz = 1)
{
    int16_t x1, y1, wid = tft.width(), inview = 1;
    uint16_t w, h;
    tft.setFont(f);
    tft.setTextColor(YELLOW, BLACK);
    tft.setTextSize(sz);
    tft.setTextWrap(false);
    tft.getTextBounds((char*)s, x, y, &x1, &y1, &w, &h);
    //    w = strlen(s) * 6 * sz;

    for (int steps = wid + w; steps >= 0; steps -= dw) {
        x = steps - w;
        if (f != NULL) {
            inview = wid - x;
            if (inview > wid) inview = wid;
            if (inview > w) inview = w;
            tft.fillRect(x > 0 ? x : 0, y1, inview + dw, h, BLACK);
        }
        x -= dw;
        tft.setCursor(x, y);
        tft.print(s);
        if (f == NULL) tft.print("  "); //rubout trailing chars
        delay(5);
    }
}


void loop()
{
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE);
    tft.setFont(NULL);   //System Font
    tft.setTextSize(1);
    tft.setCursor(0, 0);
    tft.println("Here are some scrolling examples");
    tft.println("System Font can be drawn in rubout mode");
    scrolltext(0, 30, "Default 100 pixels/s.  System Font.  sz = 1", 1, NULL, 1);
    scrolltext(0, 30, "David Prentice is a jolly good chap.  1000 pixels/s.  System Font",
               10, NULL, 1);
    scrolltext(0, 30, "200 pixels/s. System. sz=2", 2, NULL, 2);
    scrolltext(0, 30, "200 pixels/s. System. sz=3", 2, NULL, 3);
    scrolltext(0, 30, "500 pixels/s. System. sz=4", 5, NULL, 4);
    scrolltext(0, 30, "Saturday 30 September 2017", 2, NULL, 3);
    scrolltext(0, 60, "Saturday 30 September 2017", 10, NULL, 3);
    tft.setTextColor(WHITE);
    tft.setFont(&FreeSans9pt7b);   //Free Font
    tft.setTextSize(1);
    tft.setCursor(0, 40);
    tft.println("Free Fonts look nicer, only transparent");
    tft.println("re-painting background for rubout is nasty");

    scrolltext(0, 100, "200 pixels/s. FreeSans9pt7b. sz=1", 2, &FreeSans9pt7b, 1);
    scrolltext(0, 100, "Saturday 30 September 2017", 5, &FreeSans12pt7b);
    scrolltext(0, 200, "David", 10, &FreeSans18pt7b);
    delay(2000);
}

The Adafruit_GFX can only print in transparent mode. I could render the FreeFonts in my library. In other words: I could render in both transparent and rubout mode. The rubout mode could be faster than the GFX transparent.

Quite honestly. I do not want to override the GFX methods. In practice, you seldom want to scroll text. You do want to overwrite text (i.e. rubout mode). Re-painting the background is not noticeable for small areas of text.

David.

Edit. Added a const qualifier and a (char*) cast to keep the STM32 Compiler happy.
It should make no difference to AVR compilers.

Thank you very much David

I copy your sketch and past it in new one. I save it in "test_scolling_horiz/test_scolling_horiz.ino"

I download Adafruit GFX Library from GitHub and extract Fonts repertory to C:\Users\myname\Documents\Arduino\libraries\

I have problem to compil

'GFXfont' has not been declared
in line 26 void scrolltext(int x, int y, const char *s, uint8_t dw = 1, GFXfont *f = NULL, int sz = 1)

'class MCUFRIEND_kbv' has no member named 'getTextBounds'
'class MCUFRIEND_kbv' has no member named 'setFont'

AND

In file included from C:\Users\myname\Documents\Arduino\test_scolling_horiz\test_scolling_horiz.ino:5:0:

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans9pt7b.h:99:7: error: 'GFXglyph' does not name a type

const GFXglyph FreeSans9pt7bGlyphs PROGMEM = {

^

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans9pt7b.h:196:7: error: 'GFXfont' does not name a type

const GFXfont FreeSans9pt7b PROGMEM = {

^

In file included from C:\Users\myname\Documents\Arduino\test_scolling_horiz\test_scolling_horiz.ino:6:0:

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans12pt7b.h:168:7: error: 'GFXglyph' does not name a type

const GFXglyph FreeSans12pt7bGlyphs PROGMEM = {

^

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans12pt7b.h:265:7: error: 'GFXfont' does not name a type

const GFXfont FreeSans12pt7b PROGMEM = {

^

In file included from C:\Users\myname\Documents\Arduino\test_scolling_horiz\test_scolling_horiz.ino:7:0:

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans18pt7b.h:350:7: error: 'GFXglyph' does not name a type

const GFXglyph FreeSans18pt7bGlyphs PROGMEM = {

^

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans18pt7b.h:447:7: error: 'GFXfont' does not name a type

const GFXfont FreeSans18pt7b PROGMEM = {

^

In file included from C:\Users\myname\Documents\Arduino\test_scolling_horiz\test_scolling_horiz.ino:8:0:

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans24pt7b.h:625:7: error: 'GFXglyph' does not name a type

const GFXglyph FreeSans24pt7bGlyphs PROGMEM = {

^

C:\Users\myname\Documents\Arduino\libraries\Fonts/FreeSans24pt7b.h:722:7: error: 'GFXfont' does not name a type

const GFXfont FreeSans24pt7b PROGMEM = {

^

test_scolling_horiz:26: error: 'GFXfont' has not been declared

void scrolltext(int x, int y, const char *s, uint8_t dw = 1, GFXfont *f = NULL, int sz = 1)

^

C:\Users\myname\Documents\Arduino\test_scolling_horiz\test_scolling_horiz.ino: In function 'void scrolltext(int, int, const char*, uint8_t, int*, int)':

test_scolling_horiz:30: error: 'class MCUFRIEND_kbv' has no member named 'setFont'

tft.setFont(f);

^

test_scolling_horiz:34: error: 'class MCUFRIEND_kbv' has no member named 'getTextBounds'

tft.getTextBounds(s, x, y, &x1, &y1, &w, &h);

^

C:\Users\myname\Documents\Arduino\test_scolling_horiz\test_scolling_horiz.ino: In function 'void loop()':

test_scolling_horiz:58: error: 'class MCUFRIEND_kbv' has no member named 'setFont'

tft.setFont(NULL); //System Font

^

test_scolling_horiz:72: error: 'class MCUFRIEND_kbv' has no member named 'setFont'

tft.setFont(&FreeSans9pt7b); //Free Font

^

test_scolling_horiz:72: error: 'FreeSans9pt7b' was not declared in this scope

tft.setFont(&FreeSans9pt7b); //Free Font

^

test_scolling_horiz:79: error: 'FreeSans12pt7b' was not declared in this scope

scrolltext(0, 100, "Saturday 30 September 2017", 5, &FreeSans12pt7b);

^

test_scolling_horiz:80: error: 'FreeSans18pt7b' was not declared in this scope

scrolltext(0, 200, "David", 10, &FreeSans18pt7b);

^

Go on. Install Adafruit_GFX from the Library Manager. Install MCUFRIEND_kbv from the Library Manager.

Everything gets installed correctly. The Fonts come with Adafruit_GFX automatically.

If you are someone that ‚Äúlikes to do things in your own way‚ÄĚ, you should delete any existing libraries first.
Then install things properly.

David.

I work fine with your MCUFRIEND_kbv since 3 month, because you help me to use my ILI9342 tft screen…

I will do what you say

…

some minutes later I have adafruit_gfx 1.2.2 and mcufriend_kbv 2.9.6

Same erreur

‚ÄėGFXfont‚Äô has not been declared in void scrolltext(int x, int y, const char *s, uint8_t dw = 1, GFXfont *f = NULL, int sz = 1)

The v2.9.6 of MCUFRIEND_kbv from the Library Manager should work just fine.
Likewise the v1.2.2 of Adafruit_GFX.

David.

Edit. I owe you an apology. I wrote the Scroll example on my Laptop which has GFX v1.2.2
I have just tried on my PC which had GFX v1.1.5 and the behaviour was different.The scroll examples rely on the GFX library ignoring any "off-screen" text. e.g. if the text cursor is at a negative value, or greater than screen width.

With v2.9.6 of MCUFRIEND_kbv from the Library Manager I have white screen :’(

Same situation https://forum.arduino.cc/index.php?topic=473885.0

I open the MCUFRIEND_kbv.cpp file with a regular editor.
I uncomment
//#define SUPPORT_9342 //costs +114 bytes
and save it back to disk.

Color, text, orientation are good ! Just text in yellow lanscape and portrait to switch for ILI9342.

Touch_shield_kbv is wrong.

TouchScreen_Calibr_new.ino and table serial say :
TouchScreen.h Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 34
Testing : (A2, D6) = 30
Diagnosing as:-
YP,YM: (A1, D7) = 34
XM,XP: (A2, D6) = 30I Tap the screen to continue, but nothing appear.

glue_demo_320x240 is in 240x320 color and text are good

lcd_id_readreg give in serial monitor
Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 00 00 ID: ILI9320, ILI9325, ILI9335, …
reg(0x0004) 00 00 00 00 Manufacturer ID
reg(0x0009) 00 00 61 00 00 Status Register
reg(0x000A) 00 08 Get Power Mode
reg(0x000C) 00 06 Get Pixel Format
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x0070) 00 00 Panel Himax HX8347-A
reg(0x00A1) 00 00 00 00 00 RD_DDB SSD1963
reg(0x00B0) 00 40 RGB Interface Signal Control
reg(0x00B4) 00 02 Inversion Control
reg(0x00B6) 00 0A 02 1D 04 Display Control
reg(0x00B7) 00 06 Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 26 09 09 09 09 09 09 09 Panel Control
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA
reg(0x00CC) 00 3A Panel Control
reg(0x00D0) 00 00 00 Power Control
reg(0x00D2) 00 00 00 03 03 NVM Read
reg(0x00D3) 00 00 93 42 ILI9341, ILI9488
reg(0x00D4) 00 00 00 00 Novatek ID
reg(0x00DA) 00 00 RDID1
reg(0x00DB) 00 00 RDID2
reg(0x00DC) 00 00 RDID3
reg(0x00E0) 00 0F 29 1E 06 0F 09 5A 86 3F 06 1C 04 13 0E 00 GAMMA-P
reg(0x00E1) 00 00 20 23 02 10 04 3E 20 43 01 0B 0B 31 33 0F GAMMA-N
reg(0x00EF) 00 00 00 00 00 00 ILI9327
reg(0x00F2) 00 00 00 00 00 00 00 00 00 00 00 00 Adjust Control 2
reg(0x00F6) 00 01 00 00 Interface Control

showbmp_kbv_uno show picture with good color, not mirrored, but all in landscape and portrait picture are troncated.

I do not remember what change I made in your file for all working well.
I do not make backup before update from MCUFRIEND_kbv-master_2-9-3 to MCUFRIEND_kbv-master_2-9-6, and now it is loosed. Nothing in trash ! I am very stupid.

When I open testcard_kbv I remember I replace tft.setRotation(1);
by if (ID == 0x9342)
{ tft.setRotation(0);
}
else
{ tft.setRotation(1);
},

  1. Yes, you have to enable SUPPORT_9342. Since you have a Mega2560, Flash usage is not important.
  2. What does

Just text in yellow lanscape and portrait to switch for ILI9342.

mean?
3. What does

Touch_shield_kbv is wrong.

mean?

  1. Yes, it appears that TouchScreen_Calibr_new.ino uses too much SRAM on Uno with some versions of the IDE.

  2. But you have plenty of SRAM on your 2560.

  3. Did you change the NUMSAMPLES ?

  4. There is little point in pasting the readreg output. You have posted it before.

  5. Yes, I know that we have a language difference.

  6. Google Translate can solve it. But you still have to describe your problem properly in your own language first.

  7. I am surprised that no one had mentioned the instabilty of TouchScreen_Calibr_new.ino before.

  8. It is due to the large amount of anonymous strings (that could have been placed in Flash)

David.

maybe you accept this sketch in your MCUFRIEND_kbv

/*
 * generate testcard similar to BMP
 * 15/06/2017 some change for 0x9342 and optimise accuracy of the clock
 */

#include <Adafruit_GFX.h>
#if defined(_GFXFONT_H_)           //are we using the new library?
#include <Fonts/FreeSans9pt7b.h>
#define ADJ_BASELINE 11            //new fonts setCursor to bottom of letter
#else
#define ADJ_BASELINE 0             //legacy setCursor to top of letter
#endif
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define RGB(r, g, b) (((r&0xF8)<<8)|((g&0xFC)<<3)|(b>>3))

#define GREY      RGB(127, 127, 127)
#define DARKGREY  RGB(64, 64, 64)
#define TURQUOISE RGB(0, 128, 128)
#define PINK      RGB(255, 128, 192)
#define OLIVE     RGB(128, 128, 0)
#define PURPLE    RGB(128, 0, 128)
#define AZURE     RGB(0, 128, 255)
#define ORANGE    RGB(255,128,64)
 
#include <stdio.h>

uint16_t ID;
uint8_t hh, mm, ss; //containers for current time

uint8_t conv2d(const char* p)
{
    uint8_t v = 0;
    if ('0' <= *p && *p <= '9') v = *p - '0';
    return 10 * v + *++p - '0';
}

void setup(void)
{
    Serial.begin(9600);
    tft.reset();
    ID = tft.readID();
    Serial.print("TFT ID = 0x");
    Serial.println(ID, HEX);
    //    if (ID == 0xD3D3) ID = 0x9481; // write-only shield
    if (ID == 0xD3D3) ID = 0x9486; // write-only shield
    tft.begin(ID);
    if (ID == 0x9342)
    {    tft.setRotation(0);
    }
    else
    {    tft.setRotation(1);
    }
    tft.fillScreen(BLACK);
#if defined(_GFXFONT_H_)
    tft.setFont(&FreeSans9pt7b);
#endif
    hh = conv2d(__TIME__);
    mm = conv2d(__TIME__ + 3);
    ss = conv2d(__TIME__ + 6);
    screendraw();
}

void screendraw(void)
{
    int16_t x, y, dx, dy, radius = 108, idx;
    uint16_t w, h, len, mask;
    uint16_t colors[8] = { BLACK, WHITE, YELLOW, CYAN, GREEN, MAGENTA, RED, BLUE };
    uint16_t height, width;
    width = tft.width();
    height = tft.height();
    tft.fillRect(0, 0, 7, 3, WHITE);
    tft.fillRect(313, 0, 7, 3, WHITE);
    tft.fillRect(0, 237, 7, 3, WHITE);
    tft.fillRect(313, 237, 7, 3, WHITE);
    for (y = 0, w = 18, h = 3; y < 240; y += 13 * w + h) {
        for (x = 25; x < 320 - 18; x += 2 * w) {
            tft.fillRect(x, y, w, h, WHITE);
        }
    }
    for (x = 0, w = 7, h = 18; x < 320; x += 17 * h + w) {
        for (y = 21; y < 240 - 18; y += 2 * h) {
            tft.fillRect(x, y, w, h, WHITE);
        }
    }
    tft.fillRect(7, 3, 17 * 18, 13 * 18, GREY);
    for (x = 7, y = 0, w = 1, h = 240; x < 320; x += 18) {
        tft.fillRect(x, y, w, h, WHITE);
    }
    for (x = 0, y = 3, w = 320, h = 1; y < 240; y += 18) {
        tft.fillRect(x, y, w, h, WHITE);
    }
    tft.fillRect(26, 22, 17, 99, TURQUOISE);
    tft.fillRect(26, 120, 17, 99, PINK);
    tft.fillRect(44, 22, 17, 35, AZURE);
    tft.fillRect(44, 184, 17, 35, ORANGE);
    tft.fillRect(260, 22, 17, 35, AZURE);
    tft.fillRect(260, 184, 17, 35, ORANGE);
    tft.fillRect(278, 22, 17, 99, OLIVE);
    tft.fillRect(278, 120, 17, 99, PURPLE);

    for (dx = radius; dx > -radius; dx--) {
        w = sqrt(radius * radius - dx * dx);
        y = 120 - dx;
        dy = (y - 3) / 18;
        mask = 7;
        colors[0] = (dy == 3) ? DARKGREY : BLACK;
        switch (dy) {
            case 0:
            case 1: idx = 1; len = 0; break;
            case 2: idx = 0; len = 0; break;
            case 3: idx = 0; len = 13; mask = 1; break;
            case 4:
            case 5: idx = 2; len = 38; break;
            case 6:
            case 7:
            case 8: idx = 0; len = 0; break;
            case 9: for (idx = 2; idx < 8; idx++) {
                    //dy = 0xFF >> (7 - idx);
                    dy = (idx - 2) * 51;
                    colors[idx] = tft.color565(dy, dy, dy);
                }
                idx = 2; len = 38; break;
            case 10: idx = 1; len = 0; break;
            case 11:
            case 12: colors[2] = YELLOW; idx = 2; len = 0; break;
        }
        if (len == 0)
            tft.fillRect(160 - w, y, w * 2, 1, colors[idx]);

        else {
            if (mask == 1) idx = 1 + (w) / len;
            dy = w % len;
            for (x = 160 - w; x < 160 + w; idx++) {
                tft.fillRect(x, y, dy, 1, colors[idx & mask]);
                x += dy;
                if (x + len > 160 + w) dy = w % len;
                else dy = len;
            }
        }

    }
    for (x = 72, y = 129, dx = 5, dy = 0; dx > 0; x += 2 * dx) {
        tft.fillRect(x, y, dx, 36, WHITE);
        dy += dx * 2;
        if (dy >= 36) {
            dy = 0;
            dx--;
        }
    }
    tft.fillRect(160 - 8, 5 * 18 + 3, 17, 3 * 18, BLACK);
    for (x = 3 * 18 + 7, y = 6 * 18 + 3, w = 1, h = 18; x < 160 + 108; x += 18) {
        tft.fillRect(x, y, w, h, WHITE);
    }
    tft.fillRect(160 - 108, 120, 108 * 2, 1, WHITE);
    tft.fillRect(160, 5 * 18 + 3, 1, 3 * 18, WHITE);
    tft.fillRect(108, 2 * 18 + 3, 6 * 18, 18, WHITE);
    //    tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
    tft.fillRect(160 - 8, 11 * 18 + 3, 17, radius - 18*9/2, RED);
    tft.setCursor(160 - 36, 24 + ADJ_BASELINE);
    tft.setTextColor(BLACK);
    tft.setTextSize(1);
    tft.print("320x240");
    tft.setCursor(109, 43 + ADJ_BASELINE);
    tft.setTextColor(BLACK);
    tft.setTextSize(1);
    tft.print(" ID=0x");
    tft.print(tft.readID(), HEX);
}

void showtime(void)
{ tft.setTextColor(WHITE, BLACK);
  //    tft.setFont(NULL);
  //    tft.setTextSize(2);
  if (++ss > 59) 
  {  ss = 0;
     mm++;
     if (mm > 59) 
     {  mm = 0;
        hh++;
        if (hh > 23)
        {  hh = 0;
  }  }  }
  char buf[20];
  sprintf(buf, "%02d:%02d:%02d", hh, mm, ss);
  tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
  tft.setCursor(128, 187 + ADJ_BASELINE);
  tft.print(buf);
}
    
void loop(void)
{ const unsigned long interval = 1000;
  static unsigned long previousMillis = interval;    
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval) 
  { previousMillis = currentMillis;
    showtime();
} }

testcard_kbv_new.ino (6.03 KB)

in graphictest_kbv if tft.id = 0x9342 switch word "portait" with "lanscape" in yellow text.

something like that

often google do not translate exactly my mind when I translate back in french the english text translated from my french text.

I do not understand that :

david_prentice:
5. But you have plenty of SRAM on your 2560.

  1. Did you change the NUMSAMPLES ?

  2. There is little point in pasting the readreg output. You have posted it before.

  3. Yes, I know that we have a language difference.

  4. I am surprised that no one had mentioned the instabilty of TouchScreen_Calibr_new.ino before.

  5. It is due to the large amount of anonymous strings (that could have been placed in Flash)

  1. You can do a better test for ILI9342. e.g. tft.setRotation((tft.getRotation() + 1) & 3)

  2. You will always want to rotate Portrait and Landscape from other people’s programs.

  3. You can use the System Font for text if you want.

  4. Yes, millis() is going to be more accurate than delay().

  5. Genuine Arduinos tend to have inaccurate resonators.

  6. Chinese Clones tend to have accurate crystals.

  7. Why not learn to press when you type a program?

  8. It keeps blocks nicely indented. (I configure for 4 spaces)

David.

david_prentice:
2. You will always want to rotate Portrait and Landscape from other people's programs.

A Landscape mode in other program is every time in portrait mode on my screen and troncated.
In few days I will make a video to show you this problem !
It is a 0x9342 problem.

Go on. Most programs set the required rotation in setup(). It is done once. Then you get on with the rest of your life.

Likewise, Touch Panels come in all directions and polarities.
You simply determine which is LEFT and which is RIGHT. And map it to the Pixel coordinates.
Calibrate once. Get on with the rest of your life.

Yes, I know that all my programs call the Vertical Scroll direction "Portrait"
This "looks" wrong on a 800x480 SSD1963.

Yes, I could put conditional code to keep the one ILI9342 owner (you) or the two SSD1963 owners.
Against that, there are 40 other supported controllers with hundreds if not thousands of users.

Aha. Looking at your posts it appears that you have a Uno.
So it is very important that I fix the new Calibration sketch. (Probably tomorrow)

David.

I have first :


and after :

I bought the second UNO for later when my projet will be finished with first and specialy this one to flash sonoff

Maybe I need more I/O and buy an third "arduino"... but it is the mater of this topic.

How can I scroll text more longer than screen ?

I know the first clone. I find the ‚ÄúGolden‚ÄĚ version more convenient because it has a micro-USB connector.

I do not recognise the second ‚Äúclone‚ÄĚ. Please post a link to where you bought it from.

I have published an official MCUFRIEND_kbv v2.9.6 Release
I posted an example ‚Äútext scroll‚ÄĚ sketch.

If you have a problem with library examples or a Beta sketch, please report back with accurate information.

Yes, I am very grateful that you have uncovered the problem with the Beta TouchScreen_Calibr_new.ino sketch.

I have re-written it to use native GFX methods

David.

TouchScreen_Calibr_native.ino (11 KB)

I have MCUFRIEND_kbv v2.9.7 beta

I test TouchScreen_Calibr_native.ino, but nothing after "touch screen to continue"...

serial tableTouchScreen.h GFX Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 31
Testing : (A2, D6) = 29
Diagnosing as:-
YP,YM: (A1, D7) = 31
XM,XP: (A2, D6) = 29
ID = 0x9342

Go on.

  1. Which version of the IDE?
  2. Which version of TouchScreen library?
  3. Have you changed NUMSAMPLES?

I wrote the sketch on the Desktop with Arduino v1.8.1
I will build it on this Laptop that is running v1.6.12

David.

Edit. Built and ran on v1.6.12
This is my Serial Output:

TouchScreen.h GFX Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 23
Testing : (A2, D6) = 31
Diagnosing as:-
XM,XP:  (A1, D7) = 23
YP,YM:  (A2, D6) = 31
ID = 0x7783

cx=192 cy=129 cz=615
cx=198 cy=496 cz=602
cx=179 cy=877 cz=529
cx=513 cy=137 cz=540
cx=497 cy=877 cz=546
cx=855 cy=134 cz=527
cx=861 cy=496 cz=563
cx=863 cy=884 cz=525
MCUFRIEND_kbv ID=0x7783  240 x 320
PORTRAIT CALIBRATION     240 x 320
x = map(p.x, LEFT=158, RT=889, 0, 240)
y = map(p.y, TOP=108, BOT=903, 0, 320)
Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6
LANDSCAPE CALIBRATION    320 x 240
x = map(p.y, LEFT=108, RT=903, 0, 320)
y = map(p.x, TOP=889, BOT=158, 0, 240)