Go Down

Topic: 2.8" LCD TFT touch shield on mega (Read 660 times) previous topic - next topic

abby1010

I have an Arduino Mega wih a 2.8" LCD TFT touch shield and want to use the the shield in the serial mode.
The touch option is not relevant for me while i am not gana use it.
Can anaone help me with the wiring, the lib. and may some exampel ide??
thks in advance.

david_prentice

#1
Feb 25, 2018, 02:42 pm Last Edit: Feb 25, 2018, 02:43 pm by david_prentice
You have more hair than me.    Is it dyed?

Post a link to the actual display that you have bought.   e.g. Ebay sale.

David.

6v6gt

If the tft screen is really a shield designed for your Mega, then the wiring is the least of your problems. It simply plugs in. Anyway, post a link as requested and much should be revealed. There's a huge variety of similar looking screens out there with different, controllers, pin configurations, voltage tolerance, internal wiring, register settings, addresses etc. etc. Like snowflakes, no two are ever the same.

abby1010

#3
Mar 04, 2018, 04:41 pm Last Edit: Mar 04, 2018, 04:47 pm by abby1010 Reason: picture was too big
I bought the shield from a webshop in the Netherlands, called "Hackerstore". I asked the people for more info, but they couldn't help me....??(they sell product without any support).

The shield was designed for the Uno but it was said and written that it  could  used for the Mega as well. It was only a matter of downloading the library UTFT, uncomment line 7 and that's it.....??? Well I did, but without result.

I hope You can help me, while it is very frustrating.

Please have a look at the attach pic.

Kind regards,

Leo

david_prentice

I have made numerous attempts to upload your JPEG.   My PC is not happy.

Can you provide a link to the sale website or any website with an accurate photo of the pcb?

David.

david_prentice

#5
Mar 04, 2018, 11:18 pm Last Edit: Mar 04, 2018, 11:19 pm by david_prentice
My apologies.   It looks like PC has a problem with TWINUI.   IrfanView displayed fine.   

You have a "Blue 2.8 inch Mcufriend Uno Shield".     

Install MCUFRIEND_kbv via the Library Manager.   It should work on the Mega.

David.

abby1010

YEH!!!!! IT'S WORKING!!!! great David, thanks.
I tried several examples and they worked with no problems at all. The pin assignments are also
in line with the Mega board, so no wiring at all.
Now I am going to figure out to get the alpha numerical txt horizontally only, (reverse) in de setup and  in the not in the loop.

Thanks again.
rgds,

Leo.

abby1010

The display is working fine for now. Another thing I like to ask now is the following:

Once I have a standard text I want to display a variable in the next line. I don't like to refresh the whole page with "clearScreen(0x000); but just clear the appropriate line with the variable only.
What I did for now is overwriting all numbers in black and then go back to the origanal color and write the Val again. (bit stupid or not????)

Is there a standard expression (delete,erase,clear......) in the library or so??

thks in advance.

rgds,

Leo

david_prentice

#8
Mar 17, 2018, 11:38 am Last Edit: Mar 17, 2018, 11:38 am by david_prentice
There are two ways to overwrite text with a GFX style library:

1.  default System 7x5 font.   Use tft.setTextColor(foregroundcolor, backgroundcolor);
2.  Call tft.getTextBounds() to get the size of previous text.  Use tft.fillRect() to rub it out with backgroundcolor.

3.  Call tft.print() to draw the fresh text.

With the FreeFonts fonts you must always use (2)
In practice,   clearing a whole line is very fast with fillRect()

If your program "refreshes" a variable in several places it is worth writing a helper function that sets the cursor,  fills the background,  prints the variable.

David.

abby1010

Thanks David,

I tried, but but got the following reply:

no matching function for call to 'MCUFRIEND_kbv::fillRect()'

abby1010

The next error message I got was:

no matching function for call to 'MCUFRIEND_kbv::getTextBounds()'

david_prentice

fillRect() requires arguments.
from MCUFRIEND_kbv.h:
Code: [Select]

 virtual void     fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);

from Adafruit_GFX.h:
Code: [Select]

    void getTextBounds(char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);


You can see how to use GFX methods by GFX tutorial

Or just look at examples.   But the easiest way is to use the 7x5 font with setTextColor(foreground, background)

David.

abby1010

Thank You David, I tried various things, but unfortunately without results.
I'll give You some pieces within the program with the warnings:

#include <Adafruit_GFX.h> // Hardware-specific library
void getTextBounds(char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
void     fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFF
float Val0 = 0;

The FillRect() is not accepted:


Furthermore in the heading the word "virtual" is not accepted either.


 if (Val0 < 400) {
    tft.setCursor(0, 160);
    tft.setTextColor(CYAN, BLACK);
    tft.println("SENSOR UIT");
    tft.setCursor(0, 200);
    tft.fillRect();
    tft.println(Val0);

  }
  else if (Val0 > 400) {
    tft.setCursor(0, 160);
    tft.setTextColor(MAGENTA, BLACK);
    tft.println("SENSOR AAN");
    tft.setCursor(0, 200);
    tft.fillRect();
    tft.println(Val0);

  }
  delay(1000);

The FillRect() is not accepted:

no matching function for call to 'MCUFRIEND_kbv::fillRect()'


Any idea yet??

Sorry about Your sunday......

david_prentice

Sorry,   I make assumptions that a User can understand a formal function or class method declaration.

C is a lot easier to follow than C++.   But I did show you a link to a GFX tutorial.    And most Dutch citizens have an excellent command of the English language.

Please attach your complete sketch or paste it to your message in CODE window.

If you want to draw a YELLOW filled rectangle with width = 40 pixels, height = 20 pixels at coordinates (100, 150) you would say:
Code: [Select]

    tft.fillRect(100, 150, 40, 20, YELLOW);


The tutorial explains each graphical shape e.g. line, rectangle, circle, ...
And the graphictest_kbv example shows each graphical method.

In practice,  the easiest way to print a variable is:
Code: [Select]

    tft.setTextColor(CYAN, BLACK);  //CYAN foreground, BLACK background
    tft.setCursor(100, 150);   //where to print
    tft.print(variable);   //print the value
    tft.print(" ");   //followed by a space to rub out any previous digit

Normally you know how much screen to use for your variable.   e.g. six characters for "123.45"
So you can add your own padding spaces or use sprintf() to do the formatting.

And yes,   sprintf() takes many different arguments.    An empty list would be an error.

I would guess that there will be many Dutch language programming textbooks.     And probably Dutch language Arduino tutorials.

David.

abby1010

THANK YOU!!!!! It's working!! And now I am beginning to understand a bit of the graphics too.

Yes You are right, but I googled for a Dutch forum, I subscribed to it and got linked through to Yours!!??
The only Dutch part is a lot of (very nice) Youtube examples. But they don't have a forum where to ask questions.
I will have a look for some educational books in the Dutch language.

Thanks again and I hope not to disturb You much more in the near future.

Kind regards,

Leo

Go Up