Apr 182014
 

In the previous article (sorry but for now only in Italian) I presented the work I was doing about a new library created to control the shield “IteadStudio 2.8”. Today we will look the description of its internal functions and the download link. Meanwhile, I also decided to change the name of the library, which now is Ss_TFT. I remember that Ss are only the initials of my name.

Wiring

If you use the shield without modifications, you can connect it to Arduino like any other shield. I remind you, however, that on Arduino Uno are occupied all the pins thus making the shield itself completely useless. On Mega board SD doesn’t works for SPI pins incompatibility. If you decide to make it work with a shift register, there is a bit of work to do. Specifically, the shift register is only used to connect pins accessing the display. For SD and touch screen the pins are connected directly to Arduino. This allows you to save 5 digital pins, we can also choose to not use the touch features or the SD saving more pins.

tft2hc595The wiring diagram is on the side: above we see that the direct connection shield – Arduino. I drew only the pins necessary to control the display and not those related to SD, touch screen and power supply. For using the HC595 take a look to the second part of the diagram.

No, do not be scared, it’s much easier than it looks. The outputs of the shift register , from Q0 to Q7, are connected to the pins of the display, from first to the eighth, in sequence. The design seems complex because an output is on one side and the other one, also the traces must cross to match with the inputs of the display. Then we have power and ground in addition to the three pins needed to control the HC595 (latch, clock, data) that I drew in purple.

Look at the diagram carefully, you will agree with me that it is easier than it appears at first sight. But there is a subtlety that I would like to point out. Among the first eight pins of Arduino I could have used any three for controlling the shift register, but I decided to use the 2, 4 and 7. Why? First of all, releasing pins 0 and 1 allows you to use the serial port. This allows you to take advantage of the serial monitor with the PC, very useful in the stages of debugging, for an RS485 connection to connect to a network of other microcontrollers or other UART usages. I leave the pin 3 free on purpose, in fact, if you remember the articles on use of infrared transmitters and receivers, you will remember that this pin is used by IR-Remote so, if you leave it free, you can use IR transmitter together your TFT display without the need to change infrared port (you must edit IR-Remote code). For the same reason I left free the pins 5 and 6 that are PWN compliant. For now you can NOT change these pins, if you want to do it you must edit Ss_TFT.cpp at about line 47 and change the line My595=new hc595(3,4,7,1); with latch, clock, data and number of shift register used. Please notice that if you change these pins, you CAN NOT use direct port option (this reflects on a important speed lost). To activate the HC595 option, you have to decomment (remove //) the line //#define USE_HC595 in Ss_TFT.h. If you are interested maybe I will make another article on using SD card on Mega boards, for now I’ll limit myself because I what to quickly release this first version of the library.

How library works

In the installation package are some examples that show how to handle the colors, geometric primitives, fonts, the SD and the touch screen so I invite you to check it out to realize the potential of the library.

Funzione Versione Applicazione Descrizione Esempio di utilizzo
Ss_TFT 1.00 TFT / Touch Initial instance for display control Ss_TFT lcd;
Initialize 1.00 TFT / Touch Initialize display lcd.Initialize();
CleanLCD 1.00 TFT

This function empties the display content. Without parameter it uses the white color.
Alternatively you can select a color on the format 0xRRGGBB.

lcd.CleanLCD();

SetPORTRAIT

SetLANDSCAPE

1.00 TFT / Touch

It sets the display orientation. When you create the instance, the Display is sets to the portrait orientation. You can force this setting using SetLANDSCAPE or SetPORTRAIT. The coordinate 0,0 is on the right upper corner.

lcd.SetPORTRAIT();
SetFcolor(R,G,B); 1.00 TFT Sets foreground color lcd.SetFcolor(0,0,0);
SetBcolor(R,G,B); 1.00 TFT Set background color lcd.SetBcolor(255,255,255);
SetFont 1.00 TFT

Select the font type.Parameters changes if you use bitmap or vectorial font. If you use bitmap font you have to choice only the font pointer:

lcd.SetFont(BasicSmallFont);

extern unsigned char BasicSmallFont[];
...
lcd.SetFont(BasicSmallFont);

If you want to use the vectorial font you must use 4 parameters: font pointer, segment width, segment height, space between segments, more X width and Y height height (for change X:Y ratio).

extern unsigned char SegmentFont[]; 
...
lcd.SetFont(SegmentFont,2,1,0); 
 
DisplayString 1.00 TFT

This function writes a string to the display in the selected position, using actual font and colors. For vectorial font you need 3 parameters: X, Y and string

lcd.DisplayString(10,10,”MCMAJAN.COM”);

If you are using a bitmap font, you have to add a fourth parameter: this one at 0 indicate normal dimension, at 1 doubles X, at 2 doubles Y, at 3 doubles X and Y.

lcd.DisplayString(10,10,”MCMAJAN.COM”,3);

 
DisplayChar 1.00 TFT

This function is identical to DisplayString but it’ll write ongli a character and not a string.

 
Line 1.00 TFT Line(); Draws line from x,y to x2,y2. lcd.Line(0,0,50,70);
Rect 1.00 TFT Rect(x1,y1,x2,y2); Draws empty rectangle lcd.Rect(x,y,x+20,y+20);
RectFill 1.00 TFT RectFill(x1,y1,x2,y2); Draws filled rectangle lcd.RectFill(x,y,x+20,y+20);
Circle 1.00 TFT Circle(X,Y,R);Draws empty circle lcd.Circle(20,30,7);
CircleFill 1.00 TFT CircleFill(X,Y,R); Draws filled circle lcd.CircleFill(20,30,7);
Pixel 1.00 TFT Pixel(x,y); Draws single pxel lcd.Pixel(20,87);
TouchInitial 1.00 Touch Initialize touch screen lcd.TouchInitial();
TouchReady 1.00 Touch

Return true if touch sensor was touched

if(lcd.TouchReady()) …..
TouchGetPoint 1.00 Touch

Transforms raw touch screen coordinates to real X,Y pixel. If you need it, you can read original raw coordinates reading Tc_X e Tc_Y.

lcd.TouchGetPoint();

int lx=lcd.Tc_X;
int ly=lcd.Tc_Y;

         
         
         

Tweak e useful

The library was written with better flexibility in mind. If you want to manipulate directly every internal variable you can do it. In a next article I’ll write how use these capabilities, for now I want to inform you about some common variables you can use:

WIDTH: it represent the display width in pixel

HEIGTH: it represent the display height in pixel.

These values changes with display orientation.  If we keep the display in vertical, WIDTH represent the short side, but if we use it in a horizontal direction, represent the long side. Referring to these two values​​, you can create graphical interfaces that works with both orientations adapting automatically. If you are interested in the absolute values which not vary with the rotation of the display we have two more variables:

WW: pixels of short side

HH: pixels of long side

LocalFont.font_y_space: it represent the font height in pixels. This is useful to set the strings without overlap. In a next version of the library I’ll add some other functions for a better layout, but for now you have to use these variables for string location. LocalFont.font_x_space represent the font width in pixels.

In TFT.f file there are some useful definitions:

#define USE_HC595:basically it’s commented, if you remove the comment, the library uses the shift register (see diagram above).

#define SS_USEDIRECTPORT: the library is set to use direct port programming for speed increase. IF you have different board to UNO and Mega (for example clones), you maybe have compatibility problems. In this case you can comment this line to inhibit direct port programming and using my FastArduino library. This increase the compatibility but has a important speed decrease. You have another last step to increase the compatibility, locking FastArduino call and using native Arduino functions (see FastArduino.h).

Touch Screen Calibration

The library is just calibrated and you don’t need to do nothing to use touch screen. But if you notice that touch is not precise, I explain you how calibrate the touch screen. First of all you have to compile and send to Arduino the example “Calibrate” included in library examples. Now, when you touch the display,  you can see the coordinates. You have to read rx and ry, the minimum an maximum values on all sides. Please use a thin pen because fingers are note precise.

The movie

In this movie you can see my library in action. There are the library examples showed all togheter. I used Arduino UNO and direct port programming for fastest speed reachable.

Benchmark

I done a sketch to test the speed on all platforms with all compiled versions so you can know how many speed you lose changing board or software compilation options. Please note that for now Arduino DUE DON’T WORKS; I hope to resolve in future version.

  Base FastArduino DirectPort
Uno 38026 28178 1920
Mega 51281 28763 4423
74HC595 191718 25052
Due ? ? ?

Other compatibilities

The library probably is also compatible with other shields, so, since I do not have much hardware available and I’ve not money for any type of display, when you test the library with a different shield with success I would like to know it, so I could write it on these pages. If you are a company that produces display (or Arduino clones) and you would like to see this library compatible with your product , please contact me. In principle, I’m happy to have two free copies of the shield / display / board and a small donation isappreciated :-). Obviously, unless without “conspicuous donations”, I need several months of work because I use only my free time.

Download

I moved download link to this page. In this manner you’ll download my entire updated library pack . For now it’s only in Italian, the download link is at the end of the page.