Sainsmart 3.2 TFT and Shield Help

Hi all. I am not a noob with any of this except the TFT. I have the Sainsmart 3.2 TFT with touch and SD shield connected to a Mega 2560. I can connect the modules together and the backlight comes on. I can download various sketches (not related to the TFT) to the 2560 and they run. I have the TFT and UTFT libs installed. What I need is a sketch that someone has running on this module combination so I can verify that it is good. I know this is not breaking news, many people have it up and running, there is just something I am missing. I have found various bits of code here and there, but they seem not only to be different, but in some cases, they directly contradict each other.

Any help would awesome. Thanks.

Buddy

Ok, I got the pins and initialization figured out. Just keep searching and you eventually find something that helps!

Next issue… has anyone ever had a situation where the display works, but wont print? I can clear the screen, change colors, gill rectangles, etc. But when I print text I get nothing, regardless of the color combinations I use. My code is short, and compiles with no errors. I get a green rectangle across the top, but no text.

#include <UTFT.h>
extern uint8_t SmallFont;
UTFT myGLCD(ITDB32S,38,39,40,41);
void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
}
void loop()
{
myGLCD.clrScr();
delay(2000);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRect(0, 0, 300, 40);
myGLCD.setColor(255,0,0);
myGLCD.print(“TEST”,0,0);
delay(3000);
}

Just to add as much info as possible, I was getting this error:

error: variable 'BigFont' must be const in order to be put into read-only section by means of 'attribute((progmem))'

so I hanged the font file BigFont from:

uint8_t BigFont[3044] PROGMEM={

tO;

const BigFont[3044] PROGMEM={

Maybe this is incorrect and I created the problem???

Ok, GLCD noob is getting it. I added const to the declaration like this:

const uint8_t BigFont[3044] PROGMEM={

and that works!

So an odd problem, maybe someone else has run across this. When the download is finished, the code executes, my menu buttons are displayed properly, looks good. About half the time, the touch screen buttons work as displayed on the LCD. Other times the buttons appear to be mapped to a completely different area of the screen than where the buttons are draw on the LCD. Anyone seen this issue?

Thanks.

Update.

I have calibrated the unit twice - same results. I have tried a different Mega - same results. I am at this point thinking that the touch controller or screen itself is just bad. Any input?

Thanks.

Hello,

Hard to help without seeing your code. Do you use the Utouch library and are the Utouch examples working as it should ?

About that const thing, you seem to use an outdated UTFT library. Download them from here (look at the left menu for other useful libraries) ;)

:’( You are doing a grand job of talking to yourself :P. I thought I would just chip in to say hi, and you deserve credit for persevering alone and doing all the things that you should do, well done!

My 'tuppence worth, I assume since you are only running a Mega2560 that you are only using V1.05/6 of the IDE. Bite the bullet. Dump 1.0.x, get 1.5.x, several benefits, some of which include fixing mysterious weird problems for no apparent reason :wink:

Since you been plodding along quite merrily doing your own reading and research, I assume you are now no stranger to the prolific problems revolving around Sainsmart merchandise! :roll_eyes:

First things first. Clear out old IDE and UTFT libraries. Start from fresh and also get the latest genuine versions of UTFT from Henning Henning - UTFT Warnings bells are ringing from your third and fourth posts :frowning:

bmooney:
error: variable ‘BigFont’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’

so I changed the font file BigFont from:

uint8_t BigFont[3044] PROGMEM={
to;
const BigFont[3044] PROGMEM={

Maybe this is incorrect and I created the problem??? <==== No, but see later!!

bmooney:
Ok, GLCD noob is getting it. I added const to the declaration like this:
const uint8_t BigFont[3044] PROGMEM={
and that works! <===== Maybe so, but see later!!

The end result is that you have stumbled upon the correct fix, but the point is, if you had the latest genuine version, you would not even have encountered that particular problem…

IF you have the genuine UTFT libraries direct from the author, your font definition file would read like this

// DO NOT ADD YOUR OWN FONTS TO THIS FILE
// If you want to use your own fonts you should just drop the font .c file into your sketch folder.
// ------------------------------------------------------------------------------------------------

#if defined(__AVR__)
 #include <avr/pgmspace.h>
 #define fontdatatype const uint8_t
#elif defined(__PIC32MX__)
 #define PROGMEM
 #define fontdatatype const unsigned char
#elif defined(__arm__)
 #define PROGMEM
 #define fontdatatype const unsigned char
#endif

// SmallFont.c 
// Font Size : 8x12
// Memory usage : 1144 bytes
// # characters : 95

fontdatatype SmallFont[1144] PROGMEM={   
//.......
};


// BigFont.c (C)2010 by Henning Karlsen
// Font Size : 16x16
// Memory usage : 3044 bytes
// # characters : 95

fontdatatype BigFont[3044] PROGMEM={
//.......
};


// SevenSegNumFont.c
// Font Size : 32x50
// Memory usage : 2004 bytes
// # characters : 10

fontdatatype SevenSegNumFont[2004] PROGMEM={
//.......
};

So, I can only surmise that if you are not using genuine UTFT, you are probably not using Genuine UTouch or UTFT_Buttons?

Having said ALL OF THAT, I too have a Sainsmart TFT_320QVT, HORRIFIC Sainsmart MEGA TFT shield, and Sainsmart Mega2560. I have 2 +ve comments, the Mega has been rock solid, as has the display. Until recently, I haven’t used my Mega for about a year, since I upgraded to a DUE, with CTE TFT Shield ( NOT Sainsmart!! ). The display and Touch is flawless. However, when my DUE recently expired, I was obliged to resurrect my Mega and Sainshit shield, TOUCH, VERY intermittent, but it I have figured out why… If you have fitted/removed/fitted/removed/fitted/removed the TFT Shield from the Mega, you might have slightly poor connections on pins 6,5,4,3,2… a quick waft of the soldering iron with some lovely toxic rosin cored leaded solder (private joke, different thread :stuck_out_tongue_closed_eyes: ), on the pins of the shield, just to help pad them out a bit, and that seems to have done the trick.

Take your pick which parts of my advice you wish to implement, but take the lack of answers as evidence how badly thought of the Sainsmart stuff is! The £10 that you saved, you have already lost in tearing your hair out and wasted electric figuring out how to make it work!! Not to mention the hour of my evening I will never get back penning this response to you! Some Karma would be appreciated, and if you decide to follow all of my advice and still you are having problems, then you can be fairly sure that you have a faulty touch screen! :wink:

Just one final point, you did use a narrow pointed ‘stylus’ to perform the touch calibration, and you did edit the UTouchCD.h file, and have you squirted your calibration results through Henning’s calibration checker? Henning’s Touch Calibration Checker.

Best of luck!

Graham

Thanks for your help, and the lengthy reply. Nice to get genuine interest in helping, I do so on several other forums (AVR and Flight Sim stuff), and I always help as much as I can. God knows enough people had aided me when I need it. The guys over on AVR Freaks are always extremely helpful, much like you.

I am using the libs I downloaded from the Henning website, see code below.

I have no original code involved in my problems with this touch screen, just the demo code, see code below.

I am running IDE Version 1.5.8

The LCD display itself seems to be very solid.

I have 2 different Mega 2560 boards, 1 is a Funduino and the other is a generic Mega 2560, no brand on it anywhere. Both behave in identical manners.

I am ordering another shield and TFT to help try and figure this out.

The thing that makes me sort of doubt the touch controller or resistive pad being bad, is that the failure mode is not random. If it fails or works correctly seems to be random, but the symptom itself is always the same. After compiling and uploading, the sketch may behave as expected, or not, it’s a 50 / 50 chance at this point. If the board behaves as expected, all buttons work perfectly. But, regardless of when the board decides not behave properly, the errant behavior is always the same. All of the buttons drawn on the display are where they should be, but when the failure occurs, all buttons don’t work. By trial and error I found that if I press in the general area of butx, it detects but2. I say in the general area of butx, because the area that responds is not in the exact area defined for butx. If I repeat this process 50 times, however many of those times the board fails to behave as expected, each of those times fail in exactly the same manner. Mind you that it either works or doesn’t, following a reboot. If it works as expected, it does so until reboot. It never works and then stops working properly in the middle of execution. It’s only following a reboot that it either fails or works.

/ UTFT_Buttons_Demo_320x240 (C)2013 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A small demo to demonstrate the use of some of the
// functions of the UTFT_Buttons add-on library.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels, but should work on larger screens as
// well.
//
// This program requires both the UTFT and UTouch libraries
// in addition to the UTFT_Buttons add-on library.
//

#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>

// Declare which fonts we will be using
extern uint8_t SmallFont;
extern uint8_t BigFont;
extern uint8_t Dingbats1_XL;

// Set up UTFT…
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino 2009/Uno/Leonardo shield : ,19,18,17,16
// Standard Arduino Mega/Due shield : ,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due : ,25,26,27,28
// Standard chipKit Uno32/uC32 : ,34,35,36,37
// Standard chipKit Max32 : ,82,83,84,85
// AquaLEDSource All in One Super Screw Shield : ,82,83,84,85
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB32S,38,39,40,41);

// Set up UTouch…
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino 2009/Uno/Leonardo shield : 15,10,14,9,8
// Standard Arduino Mega/Due shield : 6,5,4,3,2
// CTE TFT LCD/SD Shield for Arduino Due : 6,5,4,3,2
// Standard chipKit Uno32/uC32 : 20,21,22,23,24
// Standard chipKit Max32 : 62,63,64,65,66
// AquaLEDSource All in One Super Screw Shield : 62,63,64,65,66
UTouch myTouch(6,5,4,3,2);

// Finally we set up UTFT_Buttons :slight_smile:
UTFT_Buttons myButtons(&myGLCD, &myTouch);

void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);

myTouch.InitTouch();
myTouch.setPrecision(PREC_LOW);

myButtons.setTextFont(BigFont);
myButtons.setSymbolFont(Dingbats1_XL);
}

void loop()
{
int but1, but2, but3, but4, butX, butY, pressed_button;
boolean default_colors = true;

but1 = myButtons.addButton( 10, 20, 300, 30, “Button 1”);
but2 = myButtons.addButton( 10, 60, 300, 30, “Button 2”);
but3 = myButtons.addButton( 10, 100, 300, 30, “Button 3”);
but4 = myButtons.addButton( 10, 140, 300, 30, “Button 4”, BUTTON_DISABLED);
butX = myButtons.addButton(279, 199, 40, 40, “a”, BUTTON_SYMBOL);
butY = myButtons.addButton( 0, 199, 100, 40, “I”, BUTTON_SYMBOL | BUTTON_SYMBOL_REP_3X);
myButtons.drawButtons();

myGLCD.print(“You pressed:”, 110, 205);
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("None ", 110, 220);

while(1)
{
if (myTouch.dataAvailable() == true)
{
pressed_button = myButtons.checkButtons();

if (pressed_button==butX)
{
if (myButtons.buttonEnabled(but4))
myButtons.disableButton(but4, true);
else
myButtons.enableButton(but4, true);
}
else if (pressed_button==butY)
{
if (default_colors)
{
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_YELLOW, VGA_BLUE, VGA_GRAY);
myButtons.relabelButton(butY, “_”);
myButtons.drawButtons();
default_colors=false;
}
else
{
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
myButtons.relabelButton(butY, “I”);
myButtons.drawButtons();
default_colors=true;
}
}
if (pressed_button==but1)
myGLCD.print(“Button 1”, 110, 220);
if (pressed_button==but2)
myGLCD.print(“Button 2”, 110, 220);
if (pressed_button==but3)
myGLCD.print(“Button 3”, 110, 220);
if (pressed_button==but4)
myGLCD.print(“Button 4”, 110, 220);
if (pressed_button==-1)
myGLCD.print("None ", 110, 220);
}
}
}

Ah, and regarding the last question, I did use a fine-tipped stylus during calibration, and the calibration numbers check good on the checker.

Ok, not constructive, but can I recommend you learn how to use link, code, quote tags.... post code correctly, or you will likely get flamed as a newbie.... I will fire up my Mega and shield and tft, close as I can get to same as your setup....

Post your cal figures.... I will compare with my own.

I will get back to you with my summary of your sketch.

Graham

Thanks for the advice on posting! Will do. Here are the CAL figures:

#define CAL_X 0x00478F42UL
#define CAL_Y 0x03D44176UL
#define CAL_S 0x000EF13FUL

Just quickly, did you specify myTouch.setPrecision(PREC_LOW); ?

Yes, I did.

Now I am piqued.......

Recall the symptoms I told you I had with what I considered to be poor joints?......

I inadvertently experienced your exact same symptoms..... and removing and replugging the shield 'appeared' to fix it, hence why I used the soldering iron to tin the pins.... which I considered to have fixed the issue, but I am having the identical situation now.....

So, without touching anything..... upload, test, work, upload, test, work, upload, test, fail, upload, test, work, upload, test, work, upload, test, fail...... is this what you are talking about?

I am having more success with myTouch.setPrecision(PREC_MEDIUM);

The plot thickens.... :( But this issue does not exist with this screen on my other shield on my DUE!!..... So i can PROMISE it is more likely library related at this point......

:fearful: Sadly, Henning will not entertain ANY issues that go like this............ blah blah yadah yadah Sainsmart.....

G

Yes! This exactly what I have happening.

When touch is 'not' working, does the 'pencil' give button 2 pressed........... Consistently?

Thank you again for your help.

Yes, this is what I am experiencing. I changed the precision to medium, no effect. It almost seems like some sort of erroneous initialization problem. I am disappointed to hear that you are having the issue as well. It would have been much easier to just have a bad shield or touch screen....

If I come up with anything, I will post here. By the way, is there another brand that's considered more reliable, or better supported than the Sainsmart?

Buddy

Sorry, yes, the area in an around the 'pencil' gives button 2.

This is a library problem, guaranteed. Henning won't like it, or accept it, but I have had trouble free motoring from this hardware setup after the initial teething problems until now, and the only thing that has changed is Hennings libraries and IDE version.

This exact screen on a CTE shield on a DUE works perfect all the time EVERY time..... I will pursue this.

You can rest assured we have proven your display is NOT faulty! I appreciate the outcome is not great....

Ok, remember all my bluster and bravado earlier in the evening, scrap 1.0.x IDE and older UTFT?

Well, try this, IDE V1.0.6, all the latest UTFT libraries, exactly as you have now, and the sketch you have now. I have uploaded, tested, powered off, powered on, tested, uploaded, tested, uploaded, tested, powered off, powered on, tested, all is AOK...............

Henning broke UTFT_Buttons at V1.01 !!! Are you brave enough to tell him? ;) Joking aside, I am REALLY please we have got to the bottom of this, because now I realise I may have condemned a few peoples displays when actually it is the library to blame on this RARE occasion!!?? :( :slightly_frowning_face:

Do I get my dose of Karma now please? And I will notify Henning....

Regards,

Graham