TouchScreen on Arduino Duo

hi,
I have an MCUFRIEND 2.8 TFT touchscreen Chinese clone from Banggood.

I used the MCUFRIEND_kbv library, the Adafruit_GFX and the TouchScreen library (I think its by MCUFRIEND also) and it worked perfectly on my Chinese UNO.

I bought an Arduino Due (I needed more RAM) and i tried to use it with the screen with the same libraries.
The screen itself works perfectly (the MCUFRIEND_kbv with Adafruit_GFX) but when I try a code that uses the TouchScreen library it doesn't compile (I'm working on VisualStudio with VisualMicro, but I tried to run it on the original IDE also, both doesn't work).

I have seen that at the examples of the MCUFRIEND_kbv ("Touch_Shield_new") that it only works on AVRs.

Since I'm using Due which is not an AVR board (it's an ARM board) it obviously shouldn't work and it isn't a problem in the code.

What should I do to use the touch functions? is there any other library works on Duo? or is there any version of TouchScreen library that works on Duo?

Thanks for your help, and sorry if my English is poor (I'm not a native speaker).
nirki.

Install / Update MCUFRIEND_kbv via the IDE Library Manager.

Run the Calibration sketch on the Uno. The results should be "ok" for the Uno or Due.

The Due can not diagnose the Touch pins. I am guessing that your shield uses A2,A3,8,9. The Uno sketch will tell you the correct Touch pins.

If you put the correct XP, XM, ... values into the Calibration sketch, it will calibrate on a Due.

David.

Yeah I already used that sketch on the UNO yesterday (TouchScreen_Calibr_native).

and it corrected the pins perfectly for the UNO.

i made this sketch to tell the x and y coordinates of the click.

#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>
MCUFRIEND_kbv display;



const int XP = 7, XM = A1, YP = A2, YM = 6;
const int TS_LEFT = 891, TS_RT = 125, TS_TOP = 125, TS_BOT = 892;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

TouchScreen touch_screen = TouchScreen(XP, YP, XM, YM, 300);
TSPoint touch_screen_point;
uint16_t ID;

#define MINPRESSURE 50
#define MAXPRESSURE 1000

class Static_functions {
public:
    static int16_t maxmin(int16_t number, int16_t min, int16_t max) {
        if (number > max) {
            number = max;
        }
        else if (number < min) {
            number = min;
        }
        return number;
    }
};

void setup(){
    Serial.begin(9600);
    while (!Serial);
    display.reset();
    ID = display.readID();
    display.begin(ID);
    display.setRotation(0);
    display.fillScreen(BLACK);
}

void loop(){
    int16_t xpos, ypos;
    touch_screen_point = touch_screen.getPoint();
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    //display.fillScreen(BLACK);
    if (touch_screen_point.z > MINPRESSURE && touch_screen_point.z < MAXPRESSURE) {
        xpos = map(touch_screen_point.x, TS_LEFT, TS_RT, 0, display.width());
        ypos = map(touch_screen_point.y, TS_TOP, TS_BOT, 0, display.height());
        display.setTextSize(2);
        display.setTextColor(GREEN, BLACK);
        display.setCursor(0, (display.height() * 3) / 4);


        xpos = Static_functions::maxmin(xpos, 0, display.width());
        ypos = Static_functions::maxmin(ypos, 0, display.height());


        display.setCursor(0, display.height() / 4);
        display.print("width: " + String(display.width()) + " height: " + String(display.height()));

        display.setCursor(0, display.height()/2);
        display.print("x: " + String(xpos));
        display.setCursor(0, (display.height() * 3) / 4);
        display.print("y: " + String(ypos));
        

    }
    else {
        //display.fillScreen(BLACK);
    }
}

it worked on the UNO but it fails to compile for the Due

Please run the examples. That is what they are there for.

You only have to copy-paste your calibration lines into Button_simple, TouchShield, ...
and it should work on both Uno or Due.

I am happy to try your sketch but only after you have run all the examples.

David.

Thanks for your help but I can't run the examples on the Due the compiler fails

this is the message:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Due (Programming Port)"

In file included from C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/pins_arduino.h:20:0,

from C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:6:

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp: In member function 'TSPoint TouchScreen::getPoint()':

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:63:65: error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]

#define digitalPinToPort(P) ( g_APinDescription[P].pPort )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:57:21: note: in expansion of macro 'digitalPinToPort'

uint8_t xp_port = digitalPinToPort(_xp);

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:63:65: error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]

#define digitalPinToPort(P) ( g_APinDescription[P].pPort )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:58:21: note: in expansion of macro 'digitalPinToPort'

uint8_t yp_port = digitalPinToPort(_yp);

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:63:65: error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]

#define digitalPinToPort(P) ( g_APinDescription[P].pPort )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:59:21: note: in expansion of macro 'digitalPinToPort'

uint8_t xm_port = digitalPinToPort(_xm);

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:63:65: error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]

#define digitalPinToPort(P) ( g_APinDescription[P].pPort )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:60:21: note: in expansion of macro 'digitalPinToPort'

uint8_t ym_port = digitalPinToPort(_ym);

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:73:4: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(yp_port) &= ~yp_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:74:4: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(ym_port) &= ~ym_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:82:4: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(xp_port) |= xp_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:83:4: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(xm_port) &= ~xm_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:98:5: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(xp_port) &= ~xp_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:102:5: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(yp_port) |= yp_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:121:5: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(xp_port) &= ~xp_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:125:5: note: in expansion of macro 'portOutputRegister'

*portOutputRegister(ym_port) |= ym_pin;

^

C:\Users\user\AppData\Local\arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:66:44: error: base operand of '->' is not a pointer

#define portOutputRegister(port) ( &(port->PIO_ODSR) )

^

C:\Program Files (x86)\Arduino\libraries\TouchScreen\TouchScreen.cpp:129:5: note: in expansion of macro 'portOutputRegister'

Multiple libraries were found for "MCUFRIEND_kbv.h"

*portOutputRegister(yp_port) &= ~yp_pin;

Used: C:\Users\user\Documents\Arduino\libraries\MCUFRIEND_kbv

^

Not used: C:\Program Files (x86)\Arduino\libraries\MCUFRIEND_kbv-master

exit status 1

Error compiling for board Arduino Due (Programming Port).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

First off. Leave the IDE. Delete any duplicate library directories. Start IDE.
Install / Update MCUFRIEND_kbv via the IDE Library Manager.

It is always wise to check your Library versions. It is not essential to update the IDE with every Release. But it is worth keeping reasonably up to date.

I built the Touch_shield_new example (with my calibration lines).
And ran it on a Due.

Using library Mcufriend_kbv at version 3.0.0-Beta in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv 
Using library Adafruit_GFX_Library at version 1.9.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Adafruit_TouchScreen at version 1.1.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_TouchScreen 
Using library Adafruit_BusIO at version 1.3.2 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Wire at version 1.0 in folder: C:\Users\David Prentice\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\Wire 
Using library SPI at version 1.0 in folder: C:\Users\David Prentice\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\SPI 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_939574/Touch_shield_new.ino.elf"
Sketch uses 42200 bytes (8%) of program storage space. Maximum is 524288 bytes.

David.

p.s. Don't worry about my 3.0.0-Beta version. You should be using 2.9.9-Release

Thank you very much!

It works now.

I caused the problem, I didn't install Adafruit TouchScreen library properly.

I wonder why it worked on the UNO it shouldn't work.