ESP32 MCUFRIEND_kbv with 3.5" touch display

Hello everyone,
I'm using an 3.5" touch display with ESP32-WROOM and I have loaded the file "MCUFRIEND_kbv/button simple", after running the "TouchScreen_Calibr_native.ino" with the following result:


const int XP=27,XM=15,YP=4,YM=14; //320x480 ID=0x9486
const int TS_LEFT=907,TS_RT=200,TS_TOP=816,TS_BOT=58;

PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=907, RT=200, 0, 320)
y = map(p.y, TOP=816, BOT=58, 0, 480)

LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=816, RT=58, 0, 480)
y = map(p.x, TOP=200, BOT=907, 0, 320)


I made the appropriate substitutions in the main file, and the 3.5" display shows me only a red rectangle with two buttons underneath, one "ON" and one "OFF," but both do not react to pushing them, causing everything to remain unchanged.
I honestly had been expecting any graphical reaction.
Where am I going wrong or omitting something?
Thank you for your help,
Roberto

Please make it easy for users of the forum and post the example code here rather than requiring a find it in the library source

Here you can read my code:


*************************************
#if 1

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

const int XP = 27, XM = 15, YP = 4, YM = 14; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 200, TS_TOP = 816, TS_BOT = 58;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button on_btn, off_btn;

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
        pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
    }
    return pressed;
}

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

void setup(void)
{
    Serial.begin(9600);
    uint16_t ID = tft.readID();
    Serial.print("TFT ID = 0x");
    Serial.println(ID, HEX);
    Serial.println("Calibrate for your Touch Panel");
    if (ID == 0xD3D3) ID = 0x9486; // write-only shield
    tft.begin(ID);
    tft.setRotation(0);            //PORTRAIT
    tft.fillScreen(BLACK);
    on_btn.initButton(&tft,  60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2);
    off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2);
    on_btn.drawButton(false);
    off_btn.drawButton(false);
    tft.fillRect(40, 80, 160, 80, RED);
}

/* two buttons are quite simple
 */
void loop(void)
{
    bool down = Touch_getXY();
    on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
    off_btn.press(down && off_btn.contains(pixel_x, pixel_y));
    if (on_btn.justReleased())
        on_btn.drawButton();
    if (off_btn.justReleased())
        off_btn.drawButton();
    if (on_btn.justPressed()) {
        on_btn.drawButton(true);
        tft.fillRect(40, 80, 160, 80, GREEN);
    }
    if (off_btn.justPressed()) {
        off_btn.drawButton(true);
        tft.fillRect(40, 80, 160, 80, RED);
    }
}
#endif
*******************************************
.........

Many thanks for your help.
Roberto

You haven't described your project in detail what you want to show on the display

How about using a Nextion Display which has its own controller to do the low-level stuff

How about using an unused smartphone or older tablet which will have much more pixels and let the ESP32 create a website over which you see/control everything?

How about using a teensy 4.0 as the display-controller which has 1000kB of RAM

As you haven't described your project it can't be said which alternative would be a good solution

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.