SPI TFT question

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

How to make character display larger using spi tft 240x320 ?

Could someone help me please.

Thank you guys.

sirn

Last Edited: Thu. May 4, 2017 - 06:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'll find everything in here.  It works perfectly just a bit of porting to be done.

https://github.com/PaulStoffregen/ILI9341_t3

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is an easy way and a hard way.  

 

The easy way is to take the ASCII font and every place that it puts a single pixel you instead put a block of pixels.  So a size-1 character with a font matrix of 7 pixels (vertical: up and down)  by 5 pixels ( horizontal: left and right) becomes a size-2 character with pixel dimensions of 14 by 10.  Every single pixel in size-1 becomes a 2x2 block of pixels that are either the foreground or background color.  For size-3 characters, the pixel dimensions are 3x3; each single pixel in size-1 becomes a 3x3 block in size-3.    The characters get jagged with stair-step angular lines very quickly, but it does make big characters easily.

 

  The hard way is to remake the font table for larger characters.  The standard 7x5 font used by the TFT libraries starts at the top left of the character.  This is bit 0 of byte 0 of the character pixel matrix.  Then bit 1 of byte 0 is written directly below the first pixel for eight pixels (bit 7 is always 0 to make a vertical spacing line). After eight bits making up the left edge of the character, the next byte makes the next column of pixels to the right.

 

The TFT gets two bytes per pixel, converts the 16-bits to three colors (5 bits Red:6 bits Green: 5 bits Blue), and puts one pixel with this RGB value at the location pointed to by the Memory Address Register.  The Memory Address Register of TFT then moves one position to the right, and if at the right edge, one pixel downwards at the left edge.   The block where the pixels are written of the TFT screen is programmable in size.  The Arduino library makes a block that is 1 pixel by 1 pixel in size and the RGB data appears at that pixel location.   With each new pixel, the Adafruit TFT library rewrites the Memory block location for 1 by 1 pixel.  This wastes a lot of time, but it isn't noticeable because the text usually doesn't scroll or change on a display screen.  I'm thinking of information box labels, not serial terminal data in this case.

 

So to do big chars the hard way, you need new ASCII table data and a tweak of the TFT library.

 

A third way to make big numbers is to use the pre-defined picture elements like rectangle, circle, and triangle.  Here is a guide that I use:

The big digits are scaleable according to the parameter Xsize.  All the digits are Xsize wide and 2*Xsize high.

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//  Display Vector Digit
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void displayDigit(char myDigit, int myTop, int myLeft, int myXsize, uint16_t foreground, uint16_t background) {
  int myYsize;

  myYsize = myXsize * 2;
  tft.fillRect(myLeft, myTop, myXsize+2, myYsize+2, background);

  switch (myDigit)  {
  case 0 :
     tft.fillCircle( myLeft + (myXsize/2), myTop+(myYsize/4), myYsize/4, foreground);
     tft.fillCircle( myLeft + (myXsize/2), myTop+(myYsize/4), myYsize/8, background);
     tft.fillCircle( myLeft + (myXsize/2), myTop+(myYsize/2)+(myYsize/4), myYsize/4, foreground);
     tft.fillCircle( myLeft + (myXsize/2), myTop+(myYsize/2)+(myYsize/4), myYsize/8, background);
     tft.fillRect(myLeft + (myXsize/4), myTop+(myYsize/4),  myXsize/2, myYsize/2, background);
     tft.fillRect(myLeft + (myXsize/4)+(myXsize/2), myTop + (myYsize/4),  myXsize/4, myYsize/2, foreground);
     tft.fillRect(myLeft, myTop + (myYsize/4),  myXsize/4, myYsize/2, foreground);
     break;

  case 1 :
     tft.fillRect(myLeft+(myXsize/4), myTop, myXsize/4, myYsize, foreground);
     break;

  case 2 :
     tft.fillCircle( myLeft + (myXsize/2), myTop + (myYsize/4),  myYsize/4, foreground);
     tft.fillCircle( myLeft + (myXsize/2), myTop + (myYsize/4),  myYsize/8, background);
     tft.fillRect(myLeft, myTop+(myYsize/4)-2, myXsize/2, (myYsize/4)+8, background);
     tft.fillTriangle ( (myLeft+(myXsize-(myXsize/4))), myTop+(myYsize/4),
                         myLeft, (myTop+myYsize)-(myYsize/8),
                         myLeft+myXsize, myTop+myYsize,  foreground);
     tft.fillTriangle (  myLeft+myXsize, myTop+(myYsize/4),
                         myLeft+(myXsize/4), myTop+myYsize,
                         myLeft+myXsize, myTop+myYsize, background);
     tft.fillRect(myLeft,(myTop+myYsize)-(myYsize/8), myXsize, myYsize/8, foreground);
     tft.fillTriangle (  myLeft, myTop+(myYsize/4),
                         myLeft+(myXsize/2)+(myXsize/4), myTop+(myYsize/4),
                         myLeft, myTop+myYsize, background);
     break;

  case 3 :
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/4),             myYsize/4, foreground);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/4),             myYsize/8, background);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/2)+(myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/2)+(myYsize/4), myYsize/8, background);
     tft.fillRect(myLeft, myTop + (myYsize/4), myXsize/2, myYsize/2, background);
     break;

  case 4 :
     tft.fillRect(myLeft, myTop, myXsize/4, myYsize/2, foreground);
     tft.fillRect(myLeft, myTop+(myYsize/4)+(myYsize/8), myXsize, myYsize/8, foreground);
     tft.fillRect(myLeft + (myXsize-(myXsize/4)), myTop, myXsize/4, myYsize, foreground);
     break;

  case 5 :
     tft.fillCircle(myLeft+(myXsize/2), myTop+(myYsize/2)+(myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft+(myXsize/2), myTop+(myYsize/2)+(myYsize/4), myYsize/8, background);
     tft.fillRect(myLeft, myTop+(myYsize/2), myXsize/2, myYsize/4, background);
     tft.fillRect(myLeft, myTop, myXsize,   myYsize/8, foreground);
     tft.fillRect(myLeft, myTop, myXsize/4, myYsize/2, foreground);
     tft.fillRect(myLeft, myTop+(myYsize/2), myXsize - (myXsize/2), myYsize/8, foreground);
     break;

  case 6 :
     tft.fillCircle(myLeft + (myXsize/2), myTop + (myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft + (myXsize/2), myTop + (myYsize/4), myYsize/8, background);
     tft.fillCircle(myLeft + (myXsize/2), myTop + (myYsize/2)+(myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft + (myXsize/2), myTop + (myYsize/2)+(myYsize/4), myYsize/8, background);
     tft.fillRect(myLeft+(myXsize/4), myTop+(myYsize/4), (myXsize/2)+(myXsize/4)+2, myYsize/4, background);
     tft.fillRect(myLeft, myTop+(myYsize/4), (myXsize/4), myYsize/2, foreground);
     break;

  case 7 :
     tft.fillRect(myLeft, myTop, myXsize, myYsize/8, foreground);
     tft.fillTriangle ( myLeft+myXsize, myTop, myLeft, myTop+myYsize,
          myLeft+myXsize, myTop+myYsize,  foreground);
     tft.fillTriangle ( myLeft+myXsize, myTop+(myYsize/4),
          myLeft+(myXsize/4), myTop+myYsize, myLeft+myXsize, myTop+myYsize, background);
     break;

  case 8 :
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/4), myYsize/8, background);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/2)+(myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/2)+(myYsize/4), myYsize/8, background);
     break;

  case 9 :
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/4), myYsize/4, foreground);
     tft.fillCircle(myLeft +  (myXsize/2), myTop + (myYsize/4), myYsize/8, background);
     tft.fillRect( myLeft+(myXsize/2)+(myXsize/4), myTop, myXsize/4, myYsize, foreground);
     break;

  default :
     break;
  }
} //%%%%%%%% end of displayVectorDigit() %%%%%%%%%%%%%%%

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fianawarrior wrote:
You'll find everything in here. It works perfectly just a bit of porting to be done.
Surely that only applies if the controller happens to be ILI9341 ? All the OP said was 240x320 - no details about what controller is driving it??

 

In fact I would suggest the very next step is for OP to give more detail about the display in question - maybe links to sites/data for both the entire display module and/or the controller in use if known.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you simonetta.

here is my put character code, so where I have to change.

 

void putcharacter(char ch, int x, int y, int color)
{
    
    int pixel;
    int16_t row, col, bit, data, mask = 0x01;
    setaddwindow(x,y,x+4,y+6);
    writecmd(0x2C); //RAMWR
    for (row=0; row<7; row++)
    {
        for(col=0; col<5;col++)
        {
            data =pgm_read_byte(&(fontchar[ch-32][col]));
            bit = data & mask;
            if (bit == 0) pixel =red;
            else pixel = color;
            WriteWord(pixel);
        }
        mask <<=1;
    }
}

sirn

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Fianawarrior for responding

sirn

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that github is a nice place to search for libraries.

Github is not inexed very well by regular search enginges, so go there directle. For example with:

https://github.com/search?utf8=%...

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Mon. May 8, 2017 - 09:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
There is an easy way and a hard way.

 

I chose the hard way & wrote my own and documented it here. I forked the UTFT library and works well. I recently ported to use with my SAMD21 and its works well.

 

 

"When all else fails, read the directions"