SOLVED---Waveshare 4inch Touch LCD Shield to be used with arduino due

Hello!

Does anybody have a solution for the Waveshare 4inch Touch LCD Shield for Arduino to be use with an arduino due?

The Display ist sold here: https://www.waveshare.com/product/modules/oleds-lcds/arduino-lcd/4inch-tft-touch-shield.htm

I tried to compile the sample code offered on the web page there, but it didnt compile.

The Module is using the ILI9486 Interface and the XPT2046 controller for touch...

Maybe there are libraries for this LCD-Module, I couldnt find anything?

With best regards

Werner

Hi OE7WPA,

Have you seen there is a library available through Library Manager for this display: just search for ILI9486 in the Library Manager.

Its source is here: https://github.com/ImpulseAdventure/Waveshare_ILI9486

I have not checked if this library compiles for Arduino Due, nor if it supports SW SPI.
It uses HW SPI.

The display shield pinout is for Arduino UNO, the Due has the HW SPI pins only on the 2x3 header.

You could also check if Ucglib is suitable for your display.

Jean-Marc

Thanks a lot for this information, i coudnt find anything usefull on the net...
I will have a look on the examples and report, if i was successful in compiling!

With best regards
Werner

Thanks again, i was able to compile all the included examples on create.arduino.cc…
In the hext days iam going to make it work with a real arduino due, wiring with dupont cables shouldnt be the problem!

Iwill report back when i see it working!

With best regards

Werner

Hello there!

I could compile the code examples on create.arduino.cc and upload them to my arduino due.
The same worked on my raspberry pi, where i have installed the IDe 1.8.10 (Here I had to install the library with the library manager and to install the githup-Master as .zip)
It didnt work on my windows 10 computer, i made the same steps, but it always exits while compiling...

This is a bit funny.
So I uses the arduino online Tool and uploaded to my arduino due. Upload is OK, arduino resets and starts, but I dont get any picture on my LCD....

I am now double checking all the wiring I made with dupont-cables....

Hallo Everybody!

I just wanted to let you all know, that my Waveshare display is now working like a charme!

Althought, i cant compile with windows 10 ans IDE 1.8.10 (I dont know why), I was able to bring it to work compilling with a either Raspberry pi and IDE 1.8.10 and also by using create.arduino.cc.

First i connected everything using dupond wires, but that didnt work (I am sure one or two cables are defective...).
Afterwards I just plugged the board to my due and verything is working like charme now!!!!!

It is really a very nice display although a bit slow...

Thanks again to everybody foe their fast replies!!

With best regards

Werner, OE7WPA

@OE7WPA,

Thanks for the feedback, good to know that it works.

Your post and experience could be of much more help to others, if you tell which library you used, and maybe the constructor you selected.

As you could connect the display directly to your Arduino Due, I assume you use SW SPI.

It is really a very nice display although a bit slow...

This could be partly because of the use of SW SPI.
And the library may not be optimized for speed over SPI.

I just tried to use my Raspi ILI9486 HVGA SPI display with Adafruit_SPITFT, but was not successful.
My display has SPI with some peculiarities - most of these are the same - so this comes as no surprise.

Jean-Marc

The Waveshare Shield uses the 3x2 SPI header. So it should work with Uno, Mega, Leo, Due, Zero, ...

I am always rude about the Waveshare design.
But I am sure that Calvin's library should work with all Arduinos with 3x2 header.

If a reader has a problem, ask here. Calvin often replies.

The real mystery is: why would anyone use Dupont wires when a Shield mates with the Due as Nature intended.

David.

Hi David,

The real mystery is: why would anyone use Dupont wires when a Shield mates with the Due as Nature intended.

Maybe because I didn't look good enough at the pictures, and gave incomplete (incompetent?) advice to the Original Poster. :slight_smile:

Btw: the jumper switches need be set correctly to use the ISCP signals.

Jean-Marc

Hi Everybody!

I am building a HAM Transceiver-Shield for 23/13/9/6 cm wavelenghs for the Arduino Due. On the shield there ist a MAX2871 PLL_SYnthesizer-Chip, which i want to control over the second SPI, then there also is mixer i have to turn on/off, two SHF-switches to select the right bands and bandpass-filters, and a reflectometer with two A/D - conversters to meassure forwarded and reflected SHF-power. Furtermore i need a rotary-encoder with push-button and the touch-display to show and modify parameters in the menu.

So i am already using up quite a lot of analog and digital pins of the due. Thats also why i want to connect the touch-shield with dupond-cables and make it work, my shield will sit on top of the arduino, the display will be mounted to a metal-case...

I have looked into the GitHub - ImpulseAdventure/Waveshare_ILI9486: Arduino library for Waveshare ILI9486 supporting the Waveshare 3.5" & 4" TFT Touch Shields for Arduino. Includes GFX-compatible API and touchscreen driver resources and was able to compile the examples for the 4'' display and also the ws_graphictest, but only on create.arduino.cc.
On windows 10 and on my Raspberry, some examples didnt compile, i dont know why, but at least i can use create.arduino.cc...

Here is a short example (just a rudimentary test for the menu) with some graphics, which is working, using the ws_graphictest:

//*************************************************************************
// This is a Test, using The WaveShare 4'' Touch display!!!
// (c) 18.10.2019 Werner Pichl, OE7WPA
// Intended to make a useable Touchscrenn Interface for the MAX2871 PLL!
//***********+++++++++++++++++++*****************************************/

//#define TEST_FONTS // Comment out to disable custom fonts
#define USE_FONTS

#include "SPI.h"
#include "Wire.h"
#include "SimpleRotary.h"
#include "Waveshare_ILI9486_GFX.h"

// Waveshare shield has fixed pin mapping (defined by DEV_config.h)
Waveshare_ILI9486_GFX tft = Waveshare_ILI9486_GFX();

uint8_t rotation = 3;

boolean DebuggingMode=1;// If set to 1, Debugging Information to Serial Monitor will be available (115600 Baud), but System will slow down a little bit!

//////////////////////////////////////////////////////////////////
//VERSION INFO TO BE DISPLAYED///////////////////////////////////
char SoftwareVersion0[]="------------------------------------------";
char SoftwareVersion1[]="Waveshare 4'' MenuTest";
char SoftwareVersion2[]="for MAX 2871 Synthesizer Test";
char SoftwareVersion3[]="Software Version 0.90";
char SoftwareVersion4[]="(C) 18.10.2019 OE7WPA, Werner Pichl";
char SoftwareVersion5[]="------------------------------------------";
//////////////////////////////////////////////////////////////////

// STATE OF THE ROTARY ENCODER////////////////////////////////////////////////////////////////////////////////////
// Pin A, Pin B, Button Pin
SimpleRotary rotary(A1,A2,A3);
unsigned int RE_Counter = 0;
unsigned int RE_eval = 0x0 ;  // 0 = LEFT(-), 1=RIGHT(+), 2=PRESSED
boolean ReverseEncoderRotation = 0; // Change to 1 if your RotaryEncoder ist rotating in the wrong Direction or try to exchange CLK and DT (As this is no real digital, but only an analog device) !!!!
byte Rotation; //Rotation of the Rotary Encoder (0=No Action, 1=CW, 2=CCW)
unsigned int TimeButtonPressedShort =  20; //Time in Milliseconds for Button pressed short
unsigned long TimeButtonPressedLong = 1000;  //Time in Milliseconds for Button pressed long
unsigned long DebounceTimerButtonPressedLong = 900; //Debounce Time for Button Pressed Long
unsigned long TimeButtonPressedVeryLong = 3999; //Time in Milliseconds for Button pressed very long
unsigned long PushTimeMilliSeconds; //Time in Milliseconds of Time the Button was pushed
boolean PressedLong = false ; //True if Button is pressed long
boolean PressedVeryLong = false ; //True if Button is pressed very long
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void setup() {
tft.begin();
if (DebuggingMode) Serial.begin(9600);
if (DebuggingMode) Serial.println("ILI9486 Menu Test!");
}


void loop(void) {
ShowInfoScreen();
delay(5000);
tft.fillScreen(ILI9486_BLACK);
int RX=124150000;
int TX=124000000;
ShowRX(0, 0, RX);
ShowTX(0, 50, TX, 1);
ShowShift(0,100,RX,TX);
delay(10000);
//}
}
int ShowInfoScreen() {
tft.setRotation(rotation);
tft.fillScreen(ILI9486_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ILI9486_YELLOW);
tft.setTextSize(2);
#if defined(USE_FONTS)
tft.setFont(&Font16); // 11x16 vs GFX(2): 6*2x8*2=12x16
#endif
tft.println(SoftwareVersion0);
tft.println(SoftwareVersion1);
tft.println(SoftwareVersion2);
tft.println(SoftwareVersion3);
tft.println(SoftwareVersion4);
tft.println(SoftwareVersion5);
}

int ShowTX(int x, int y, int TX_FREQUENCY, bool TX_ACTIVE) {
if (! TX_ACTIVE) {
  tft.fillRect(x, y, 300, 50, ILI9486_BLUE);
  tft.setCursor(x+5, y+15);
  tft.setTextColor(ILI9486_YELLOW);
  tft.setTextSize(3);
  #if defined(USE_FONTS)
tft.setFont(&Font24); // 11x16 vs GFX(2): 6*2x8*2=12x16
  #endif
}
if (TX_ACTIVE) {
  tft.fillRect(x, y, 300, 50, ILI9486_RED);
  tft.setCursor(x+5, y+15);
  tft.setTextColor(ILI9486_YELLOW);
  tft.setTextSize(3);
  #if defined(USE_FONTS)
tft.setFont(&Font24); // 11x16 vs GFX(2): 6*2x8*2=12x16
  #endif
}
tft.print("TX: ");
tft.print(TX_FREQUENCY);
tft.println(" KHz");
}

int ShowRX(int x, int y, int RX_FREQUENCY) {
tft.fillRect(x, y, 300, 50, ILI9486_GREEN);
tft.setCursor(x+5, y+15);
tft.setTextColor(ILI9486_BLACK);
tft.setTextSize(3);
#if defined(USE_FONTS)
tft.setFont(&Font24); // 11x16 vs GFX(2): 6*2x8*2=12x16
#endif
tft.print("RX: ");
tft.print(RX_FREQUENCY);
tft.println(" KHz");
}

int ShowShift(int x, int y, int RX_FREQUENCY, int TX_FREQUENCY) {
tft.fillRect(x, y, 320, 50, ILI9486_BLUE);
tft.setCursor(x+5, y+15);
tft.setTextColor(ILI9486_BLACK);
tft.setTextSize(3);
#if defined(USE_FONTS)
tft.setFont(&Font24); // 11x16 vs GFX(2): 6*2x8*2=12x16
#endif
tft.print("SHIFT: ");
tft.print(RX_FREQUENCY - TX_FREQUENCY);
tft.println(" KHz");
}

int ShowMenu() {
tft.setRotation(rotation);
tft.fillScreen(ILI9486_BLACK);
tft.fillRect(0, 0, 100, 50, ILI9486_BLUE);
tft.setCursor(0, 0);
tft.setTextColor(ILI9486_WHITE);
tft.setTextSize(1);
#if defined(USE_FONTS)
tft.setFont(&Font8); // 5x8 vs GFX(1): 6*1x8*1=6x8
#endif
tft.println(SoftwareVersion0);
tft.println(SoftwareVersion1);
tft.println(SoftwareVersion2);
tft.println(SoftwareVersion3);
tft.println(SoftwareVersion4);
tft.println(SoftwareVersion5);
tft.setCursor(0, 100);
tft.setTextColor(ILI9486_YELLOW);
tft.setTextSize(2);

#if defined(USE_FONTS)
tft.setFont(&Font16); // 11x16 vs GFX(2): 6*2x8*2=12x16
#endif

tft.println(SoftwareVersion0);
tft.println(SoftwareVersion1);
tft.println(SoftwareVersion2);
tft.println(SoftwareVersion3);
tft.println(SoftwareVersion4);
tft.println(SoftwareVersion5);

tft.fillRect(100, 100, 50, 50, ILI9486_YELLOW);

}

At this moment i am not sure, if the Display uses software or hardware SPI, the shield connects to the due hardware 3x2 SPI header...
In the next step i will investigate, which pins on the due i have to use, at the moment i am using more than i would like to, because i will need every pin available for my transceiver-shield...

With best regards

Werner, OE7WPA

Hello Werner,

could you please edit your last post and put the code into code tags, <> - command symbol.

This makes it easier to read, and also easy to select and copy.

Thanks

Jean-Marc

Hello Werner,

thank you for modifying with code tags.

I add here the link from your original post:

4inch Touch LCD Shield for Arduino

On this page you have a list of the pins used by this board.

The pins taken and unavailable for other purposes depend on the resources of the display board you use, tft, touch, and sd-card.

You shouldn't use SCK (SCLK), MISO and MOSI for anything else, but you might connect other SPI slaves as well. Same for LCD_DC.

You shouldn't use LCD_CS, TP_CS and SD_CS for anything else, as it would activate other pins of these resources.

The other pins should be available, if the resource is not used/selected.

But it is wise to use only pins that are not on this list.

Note that the SPI pins on the 3x2 header are duplicated on the 2x18 header.

I have not yet tried to compile with the library you use, I will check.
Example ws_graphicstest.ino compiles on Windows 10 Arduino IDE 1.8.10 for Due.

I have added support for ILI9486 for use with SPI to my 2 new libraries:

Both have no Touch support contained, ILI9486_SPI is faster on ESP8266.
I need to add the constructor example for Arduino Due to the ILI9486_SPI examples. done.
Just in case you want to try.

Jean-Marc

Both libraries are about the same speed on Arduino Due:

ILI9486_SPI on Arduino Due

setup
tft.init() done
Benchmark                Time (microseconds)
Screen fill              2572430
Text                     262221
Lines                    5825446
Horiz/Vert Lines         222957
Rectangles (outline)     135133
Rectangles (filled)      6273398
Circles (filled)         1319347
Circles (outline)        2496262
Triangles (outline)      1102606
Triangles (filled)       2464335
Rounded rects (outline)  767731
Rounded rects (filled)   6415926
Done!

ZxTFT_ILI9486 on Arduino Due

setup
init
tft.init() done
Benchmark                Time (microseconds)
Screen fill              2737603
Text                     237223
Lines                    5205658
Horiz/Vert Lines         235153
Rectangles (outline)     139734
Rectangles (filled)      6675726
Circles (filled)         1239749
Circles (outline)        2233234
Triangles (outline)      988723
Triangles (filled)       2513875
Rounded rects (outline)  701287
Rounded rects (filled)   6783323
Done!

Note that the SPI pins on the 3x2 header are duplicated on the 2x20 2x18 header.

Not on a Due. (they are duplicated on a Mega i.e. 50-52)

David.

n.b. I have hacked the quote.

Hello everybody!

I just dicovered a very funny thing:

I was not able to compile the ws_graphicstest.ino, which is an example in the Waveshare_ILI9486 library on Windows 10, IDE 1.8.10 nor on my RaspberryPi with IDE 1.8.10.
Today i discovered that i cant compile, when the Library is installed in the IDE with the Scatch->Include Library-> Manage Libraries (Library Manager). If I remove the automatically installed library and directly install the Waveshare_ILI9486-master, downloaded from GitHub - ImpulseAdventure/Waveshare_ILI9486: Arduino library for Waveshare ILI9486 supporting the Waveshare 3.5" & 4" TFT Touch Shields for Arduino. Includes GFX-compatible API and touchscreen driver in the libraries folder, everything works like a charm and everything compiles immediately!

So maybe there are different versions that are installed when done manually/automatic?

With best regards

Werner, OE7WPA

Hello Everybody!

I also found the XPT2046_Touchscreen library, which can be installed with the library manager and is working for me with some modifications.

See my Code, which at the moment is only a simple test of a menu, i want to implement into my project:

#define USE_FONTS

#include "SPI.h"
#include "Wire.h"
#include "SimpleRotary.h"
#include "Waveshare_ILI9486_GFX.h"
#include "XPT2046_Touchscreen.h"
#include "DEV_Config.h"
#include "LCD_Driver.h"

#define CS_PIN  4
// MOSI=11, MISO=12, SCK=13

//XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN  3
//XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255);  // Param 2 - 255 - No interrupts
XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling
// Waveshare shield has fixed pin mapping (defined by DEV_config.h)
Waveshare_ILI9486_GFX tft = Waveshare_ILI9486_GFX();

uint8_t rotation = 3;

boolean DebuggingMode=1;// If set to 1, Debugging Information to Serial Monitor will be available (115600 Baud), but System will slow down a little bit!

//////////////////////////////////////////////////////////////////
//VERSION INFO TO BE DISPLAYED///////////////////////////////////
char SoftwareVersion0[]="------------------------------------------";
char SoftwareVersion1[]="Waveshare 4'' MenuTest";
char SoftwareVersion2[]="for MAX 2871 Synthesizer Test";
char SoftwareVersion3[]="Software Version 0.90";
char SoftwareVersion4[]="(C) 18.10.2019 OE7WPA, Werner Pichl";
char SoftwareVersion5[]="------------------------------------------";
//////////////////////////////////////////////////////////////////

// STATE OF THE ROTARY ENCODER////////////////////////////////////////////////////////////////////////////////////
// Pin A, Pin B, Button Pin
SimpleRotary rotary(A1,A2,A3);
unsigned int RE_Counter = 0;
unsigned int RE_eval = 0x0 ;  // 0 = LEFT(-), 1=RIGHT(+), 2=PRESSED
boolean ReverseEncoderRotation = 0; // Change to 1 if your RotaryEncoder ist rotating in the wrong Direction or try to exchange CLK and DT (As this is no real digital, but only an analog device) !!!!
byte Rotation; //Rotation of the Rotary Encoder (0=No Action, 1=CW, 2=CCW)
unsigned int TimeButtonPressedShort =  20; //Time in Milliseconds for Button pressed short
unsigned long TimeButtonPressedLong = 1000;  //Time in Milliseconds for Button pressed long
unsigned long DebounceTimerButtonPressedLong = 900; //Debounce Time for Button Pressed Long
unsigned long TimeButtonPressedVeryLong = 3999; //Time in Milliseconds for Button pressed very long
unsigned long PushTimeMilliSeconds; //Time in Milliseconds of Time the Button was pushed
boolean PressedLong = false ; //True if Button is pressed long
boolean PressedVeryLong = false ; //True if Button is pressed very long
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int RX=1247600000; //RX Frequency at startup
int TX=1240000000; //TX Frequency at startup
double SWR=2.15;
double Pv=1;
double Pr=0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {
  //LCD_SCAN_DIR Lcd_ScanDir = SCAN_DIR_DFT;    //SCAN_DIR_DFT = D2U_L2R
  //LCD_Init( Lcd_ScanDir, 200);  
  //if (DebuggingMode) Serial.println("Init Touch Pad...");
  //TP_Init( Lcd_ScanDir );
  //TP_GetAdFac();
  //TP_Dialog();
  //unsigned int TouchData;
  tft.begin();
  tft.setRotation(rotation);
  //tft.fillScreen(ILI9486_BLACK); //This doesnt work!!!
  tft.fillRect(1, 1, 360, 480, ILI9486_BLACK);
  
  ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 1000));
  
 if (DebuggingMode) Serial.begin(9600);
 if (DebuggingMode) Serial.println("ILI9486 Graphics Menu Test!");
 ShowInfoScreen();
  delay(5000);
  tft.fillScreen(ILI9486_BLACK);
  UpdateMenu();
  
 delay(10000);
}


void loop() {
  int X;
  int Y;
  double Z;
  if (ts.touched()) {
    TS_Point p = ts.getPoint();
    X = (p.x-130)*480/3800;//Touch Panel returns X-Values between 130 and 3800 -> X 0-480
    Y = 320-(p.y-198)*320/3680;//Touch Panel returns Y-Values between  198 and 3680 -> Y 0-320
    if (DebuggingMode) Serial.print("Pressure = ");
    if (DebuggingMode) Serial.print(p.z);
    if (DebuggingMode) Serial.print(", x = ");
    if (DebuggingMode) Serial.print(X);
    if (DebuggingMode) Serial.print(", y = ");
    if (DebuggingMode) Serial.print(Y);
    delay(30);
    if (DebuggingMode) Serial.println();
  }
}

I had to delete most of the programm, but you can see the setup at least…
Added atachment…

With best regards

Werner, OE7WPA

RxTxMenuWaveShare4Inch.ino (11.3 KB)

OE7WPA:
Hello everybody!

I just dicovered a very funny thing:

So maybe there are different versions that are installed when done manually/automatic?

With best regards

Werner, OE7WPA

Yes, the version the Library Manager knows is the last tagged version, the last release.

The version with the last fixes is not (yet) tagged as release.

Hi OE7WPA — ZinggJM is correct. I had pushed updates to the GitHub library but haven’t generated a release yet, so that likely explains the differences you are observing. I am away at the moment but will create the updated release when I return. Thanks!