Swapping Display from Uno to Mega

Hello,
I spend the last few days on making a GUI with a Homescreen and some under menus.
This is my first Project where I try to avoid to use the delay function and do all the timings with
millis. For a better overview I just post the Setup. On the UNO (Original) everything works perfect.
But due to the lack of unused pins a need a Mega to get all the Hardware connected. And thats my Problem:
Connected to the Mega( Not Original, link at the End) I only get a white Screen. I´ve got some Serial Print for debugging on each button on the Screen and it seems that the Touch is working properly.
The diagnose Sketches from MCUfriend are working correctly. The Chip is a 9341. So I think it need something to do with my Sketch..

#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4



#define TS_MINX 898 // TS_LEFT 75
#define TS_MINY 915 // TS_TOP 901
#define TS_MAXX 75 // TS_RIGHT 918
#define TS_MAXY 105 // TS_BOTTOM 98

#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 GRAY    0x94B2

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
const int XP = 8;
const int XM = A2;
const int YP = A3;
const int YM = 9;
int pixel_x, pixel_y;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); // Resistance between D8 and A2


byte Homepage = true;
byte SettingsAll = false;
byte SettingsDuration = false;
byte SettingsIntensity = false;
byte TouchDebounce = false; // false= inaktiv , true= aktiv
byte RemainTimeUpdate = false; // Restdauer Zähler Nur Anzeige?

byte MainProgrammReady = true;
byte MainProgrammRunning = false;
byte MainProgrammPaused = false;
byte MainProgrammContinued = false;
byte MainProgrammFinished = false;
byte MainProgrammColorUpdate = true;


byte WasherYReferenz = false;
byte WasherYPosUP; // false = unten im Glas , true = Oben für Referenz

byte WasherXReferenz = false;
byte WasherXPos1;
byte WasherXPos2;



int RPMPos1 = 200;
int DurationPos1 = 30;
int DurationInsgesamt;


// Timings
unsigned long currentTime;
unsigned long previousTimeTouchDebounce = 0; // Start Millis, wird geupdatet
unsigned long IntervalTouchDebounce = 1000; // Debounce Time

unsigned long previousTimeRemainTime = 0;
unsigned long IntervalRemainTime = 1000; // Remain Time Update Interval

unsigned long MainProgrammRemainTime = 0;
unsigned long MainProgrammStartTime = 0;




//-----------------------------------------------------------------SETUP-----------------------
void setup() {
  Serial.begin(9600);
  Serial.println("Starting...");
  tft.reset();
  tft.begin(0x9341);
  tft.setRotation(1);
  Homepage = true; 
  DrawHomepage(); // declared later, draws all the Button etc

}

Is there a point I´m missing where I need to say the TFT that it is mounted to an Mega?

Arduino:
https://www.amazon.de/gp/product/B01MCX1CIN/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&th=1

Display:
https://www.amazon.de/gp/product/B01EUVJYME/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1

Seems to be a pin conflict there.

As far as I know they are shared between the Touchscreen and the Display.

I doubt it, but what do I know.

Maybe more than I do :smiley:

Those pins are typical on the Blue 2.8 inch "Mcufriend" shields,

I am more familiar with the MCUFRIEND_kbv examples. I suggest that you run all of the MCUFRIEND_kbv examples.
Report any problems. Quote example by name.

I would expect Adafruit_TFTLCD library to "work".
i.e. test with MCYFRIEND_kbv first.
then repeat with Adafruit_TFTLCD. report any problems.

If you are running a "library example" just quote the name.
If it is some custom code, please paste / attach the build-able code.

If it uses third-party libraries, make sure that these are all available via the IDE Library Manager,

Note that this applies to your "Adafruit_TFTLCD.h" too.
I would not trust anything that you have obtained from random sites on the internet (especially Elegoo)

David.

So it seems that the graphics part of all the MCU Sketches work. The button_simple sketch shows the two buttons but the Touchscreen don´t work. No matter where I press on the Screen. But the TouchScreen_Calibr_native works fine. This is what I get:

20:19:12.634 -> Testing : (A2, D8) = 22
20:19:12.634 -> Testing : (A3, D9) = 28
20:19:13.189 -> ID = 0x9341


20:19:35.623 -> *** COPY-PASTE from Serial Terminal:
20:19:35.716 -> const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
20:19:35.901 -> const int TS_LEFT=914,TS_RT=101,TS_TOP=77,TS_BOT=898;
20:19:36.085 -> 
20:19:36.085 -> PORTRAIT  CALIBRATION     240 x 320
20:19:36.270 -> x = map(p.x, LEFT=914, RT=101, 0, 240)
20:19:36.455 -> y = map(p.y, TOP=77, BOT=898, 0, 320)
20:19:36.639 -> 
20:19:36.639 -> LANDSCAPE CALIBRATION     320 x 240
20:19:36.824 -> x = map(p.y, LEFT=77, RT=898, 0, 320)
20:19:37.008 -> y = map(p.x, TOP=101, BOT=914, 0, 240)

The Adafruit Sketches aren´t working.. Still got that all white Screen. I got this from the Adafruit TFTLCD Library:

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

The Librarys I´m using are all installed via the IDE and up to date. So it seems that the MCU Library has something magical that make it all work :smiley:
Is there something else I can test?

If you want me to help please follow my suggestions in #6.

I tested most of the MCUFRIEND Examples. i think that all the important ones are listed. If I oversee one that I also have to check, just tell me. There are also the results of the Adafruit TFTLCD Library and the Adafruit GFX Library

**MCUFRIEND_KBV Library: Downloaded via IDE and Up to date**

**Aspect_kbv =** TFT works, No Touch function

**Button_simple =** TFT works, Touch function works with changed Pinout(const int XP = 8, XM = A2, YP 
= A3, YM = 9; //ID=0x9341)

**Diagnose_TFT_support** = TFT Works , No Touch function

**Diagnose_touchpins =** No TFT, Serial output works
Testing : (A2, D8) = 22
Testing : (A3, D9) = 28
Diagnosing as:-
XM,XP:  (A2, D8) = 22
YP,YM:  (A3, D9) = 28 

**Graphictest_kbv** = TFT works, No Touch function
Serial took 0ms to start
ID = 0x9341

**Graphictest_slim =** TFT works, No Touch function
Serial took 0ms to start
ID = 0x9341

**Testcard_kbv** = TFT works, No Touch function

**Touch_shield_new** = TFT works, Touch works with changed Pinout(const int XP = 8, XM = A2, YP 
= A3, YM = 9; //ID=0x9341)
Please Calibrate.
ID=0x9341
Screen is 240x320
Calibration is: 
LEFT = 907 RT  = 136
TOP  = 942 BOT = 139
Wiring is always PORTRAIT
YP=57 XM=56
YM=9 XP=8 
Touchscreen_calibrate_native = TFT works, Touch works
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 : (A2, D8) = 22
Testing : (A3, D9) = 29
ID = 0x9341

cx=871 cy=98 cz=624  X, Y, Pressure
cx=867 cy=487 cz=500  X, Y, Pressure
cx=875 cy=873 cz=437  X, Y, Pressure
cx=503 cy=102 cz=552  X, Y, Pressure
cx=507 cy=875 cz=321  X, Y, Pressure
cx=132 cy=102 cz=543  X, Y, Pressure
cx=132 cy=487 cz=383  X, Y, Pressure
cx=128 cy=874 cz=206  X, Y, Pressure

*** COPY-PASTE from Serial Terminal:
const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
const int TS_LEFT=904,TS_RT=96,TS_TOP=74,TS_BOT=899;

PORTRAIT  CALIBRATION     240 x 320
x = map(p.x, LEFT=904, RT=96, 0, 240)
y = map(p.y, TOP=74, BOT=899, 0, 320)

LANDSCAPE CALIBRATION     320 x 240
x = map(p.y, LEFT=74, RT=899, 0, 320)
y = map(p.x, TOP=96, BOT=904, 0, 240)

**Adafruit GFX Library**: Downloaded via IDE and Up to date

GFXcanvas = TFT white Screen, No Touch function
Serial Output is a lot of 0 and 1 with the right baudrate

**Mock_ili9341** = TFT White Screen, No Touch Function
ILI9341 Test!
Display Power Mode: 0x0
MADCTL Mode: 0x0
Pixel Format: 0x0
Image Format: 0x0
Self Diagnostic: 0x0
Benchmark                Time (microseconds)
Screen fill              1497456
Text                     178444
Lines                    1472236
Horiz/Vert Lines         127284
Rectangles (outline)     84108
Rectangles (filled)      3108324
Circles (filled)         506024
Circles (outline)        630216
Triangles (outline)      324304
Triangles (filled)       1365740
Rounded rects (outline)  247904
Rounded rects (filled)   3137892
Done! 
**Adafruit TFTLCD Library: Downloaded via IDE and Up to date**

**Graphictest =** White Screen, No Touch (Mega)
TFT LCD test
Using Adafruit 2.8" TFT Breakout Board Pinout
TFT size is 240x320
Unknown LCD driver chip: 0
If using the Adafruit 2.8" TFT Arduino shield, the line:
  #define USE_ADAFRUIT_SHIELD_PINOUT
should appear in the library header (Adafruit_TFT.h).
If using the breakout board, it should NOT be #defined!
Also if using the breakout, double-check that all wiring
matches the tutorial.


********Graphictest = tested with my UNO works properly**

TFT LCD test
Using Adafruit 2.8" TFT Breakout Board Pinout
TFT size is 240x320
Found ILI9341 LCD driver
Benchmark                Time (microseconds)
Screen fill              1380000
Text                     356660
Lines                    3405764
Horiz/Vert Lines         144332
Rectangles (outline)     104224
Rectangles (filled)      3268568
Circles (filled)         922924
Circles (outline)        1478220
Triangles (outline)      735784
Triangles (filled)       1714192
Rounded rects (outline)  508636
Rounded rects (filled)   3419548
Done!

Mounted to the UNO the Adafruit TFT Graphictest can "find" the ili9341 but not when the shield is
mounted to the MEGA..

If theres anything I can test please be specific on what to do.
I hope your experienced eyes sees whats wrong :slight_smile:

Since no one has mentioned it, the SPI pins on a Mega are not the same as on an UNO, though normally speaking they are not required for the display, only for the SD card reader.

My suggestion was.
run all MCUFRIEND_kbv examples. report problems.
run MCUFRIEND_kbv examples with Adafruit_TFTLCD constructor.

Obviously some methods are not available with Adafruit_TFTLCD e.g. scrolling.
The MCUFRIEND_kbv setAddrWindow() was compatible with the original Adafruit_TFTLCD setAddrWindow() but not the current method.

Since you are interested in the Touch functions, I would try those examples first. But most importantly. Quote which example (name) you are using. So that I can replicate your problem.

David.

I followed my advice.

  1. ran Touch_shield_new.ino from the examples (with my calibration).
  2. verified that the "Paint" section worked 100% all over the Blue 2.8 inch Shield.
  3. changed the include / constructor lines e.g.
//#include <MCUFRIEND_kbv.h>
//MCUFRIEND_kbv tft;       // hard-wired for UNO shields anyway.
#include <Adafruit_TFTLCD.h>             //replace include
Adafruit_TFTLCD tft(A3, A2, A1, A0, A4); //replace constructor
#include <TouchScreen.h>

char *name = "Please Calibrate.";  //edit name of shield
const int XP=6,XM=A2,YP=A1,YM=7; //ID=0x9341
const int TS_LEFT=907,TS_RT=136,TS_TOP=942,TS_BOT=139;

Note that this is the correct calibration for my Blue 2.8 screen.
Blue Mcufriend screens vary just like Red screens. (which is why you read the ID and why you calibrate for the Touch wiring)

Everything sort of worked. Except that Adafruit did not know which way up PORTRAIT should be.
So the whole screen was drawn 180 degrees. And the "stylus" draws in the wrong directions.

It is not my job to question Adafruit. But I am using the "current libraries" and building via the Web Editor. Surely everyone knows which way the Queen should be on a postage stamp.

If you really want to draw Portrait applications with Adafruit_TFTLCD you should use tft.setRotation(2);

The real mystery is WHY do you want to use Adafruit ?

David.

Edit. My apologies I ran those tests on a Uno (which worked).
You are using a Mega2560. Adafruit_TFTLCD is pretty crap. It does not really support Uno Shields on a Mega. Nor does it support LCD_RST argument on a Shield.
In fact Adafruit_TFTLCD is a bit of a disaster. Some features are corrected in some of the many hacked Adafruit_TFTLCD versions.

Well again that is not consistent for all displays.

Go on. Adafruit is Adafruit. I don't think that they really support Adafruit_TFTLCD library.

I make an effort for MCUFRIEND_kbv to support multiple controllers, shields, ... in a consistent way.

There is no dispute as to the correct way for a face Portrait to be shown. i.e. eyes at the top, mouth at the bottom. (micro-ribbon at bottom of panel)
Personally, I regard Landscape as USB to the left, micro-ribbon to the right. (i.e. just like the printing on Uno, Mega, Leo, ... boards)
However some people treat Landscape as ribbon to the left, USB to the right.

The actual rotation "value" does not matter too much. You simply choose the rotation that suits your application. Most of the MCUFRIEND_kbv examples can be built for all 4 rotations.

rattionline was complaining that Adafruit_TFTLCD gave a White Screen.
I was just verifying that Adafruit_TFTLCD "works" albeit with "unusual" rotation.

David.

About the rotation i have screens that have the touchscreen inverted compared to the display and ones that are not inverted. The only thing i know for sure is that portrait refers to the screen higher than wide and landscape the screen wider than high.

I suspect that your country does not have a Queen.

Our Queen Elizabeth is 96 years old. And she has her Portrait with eyes at the top.

Likewise, I am reading this PC screen with the text showing top to bottom.
And I am not upside down.

Obviously things might be done differently in different parts of the world.

It would be unkind to make a 96 year old stand on her head.

David.

We;'ve had 3 queens here in succession, but now we have a King. It is just that it all depends as to what side you see as up, and actually the top of the Arduino is the side the TFT shield is on and is in another plane alltogether, but where we consider the zero point of the screen is open to debate, and what we consider X and Y is as well.

Go on. I know which way is up for me. i.e. head in the air, feet on the ground.

I know which way the printing goes on an Arduino PCB. Both back and front.

I know which way LCD controllers, OLED controllers, TFT controllers set their coordinates.

I also know that some projects are better suited to 180 degree rotation. e.g. for USB cable.
Or 90 or 270 degree.

You write your sketch to use the regular X, Y coordinates of the target rotation. I find that conventional X, Y avoids my head hurting.

Of course you can do everything backwards or upside down if your King is that way inclined.

David.

Take it easy!

In some places you have to be extremely careful how you refer to the King! :face_with_raised_eyebrow:

Thailand you mean, yes. Here not, here he is just the joke of the nation as a king should be.