Closed eagl1 closed 6 months ago
@eagl1 First thing I noticed in your code is what I assume is to cause a LED flashing your pin is in an unknown state. Your setup code should set the initial state
// initialize digital pin LED_BUILTIN as an output.
pinMode(13, OUTPUT);
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
Also, you should first add code with a serial print and look at the serial monitor debug output to make sure its not a hardware issue.
// Output a message when the button is pressed
static uint8_t val = 0;
val ^= 1;
val ? Serial.println("ON") : Serial.println("OFF");
digitalWrite(13, val); // turn the LED on/off
break;
If this doesn't work then to help further a few hints will be required:
ard-adagfx-ili9341-stmpe610
Post a zip file of your sample button App project folder. Include all files and folders in that directory.
Paul--OK, I found one main problem which is this problem happens with STM32 boards. I tested this code on maple mini, black pill and rp2040. The code works perfectly with the rp2040 board but not with the SMT32 boards.
The display link:
http://www.lcdwiki.com/4.0inch_SPI_Module_ST7796
// STM32:
// ------------------------------------------------------
//#include "../configs/stm32-adagfx-mcufriend-notouch.h"
//#include "../configs/stm32-adagfx-mcufriend-simple.h"
#include "../configs/stm32-tftespi-default-xpt2046.h"
// #include "../configs/rp2040-tftespi-default-xpt2046.h"
Here are my files: GUIslice.zip
@eagl1 You failed to include an important config file TFT_ESPI User_Setup.h Your app won't work unless you first edit User_Setup.h and comment out TOUCH_CS By the way make sure the TFT_eSPI examples work before trying GUIslice. If they do and GUIslice api still doesn't you will need help from @ImpulseAdventure Calvin, I only support the Builder. Paul--
'class TFT_eSPI' has no member named 'getTouch'
// Button widget demo, requires SPI display with touch screen
// Requires widget library here:
// https://github.com/Bodmer/TFT_eWidget
#include "Free_Fonts.h" // Include the header file attached to this sketch
#include <TFT_eSPI.h> // Hardware-specific library
#include <TFT_eWidget.h> // Widget library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define CALIBRATION_FILE "/TouchCalData1"
#define REPEAT_CAL false
ButtonWidget btnL = ButtonWidget(&tft);
ButtonWidget btnR = ButtonWidget(&tft);
#define BUTTON_W 100
#define BUTTON_H 50
// Create an array of button instances to use in for() loops
// This is more useful where large numbers of buttons are employed
ButtonWidget* btn[] = {&btnL , &btnR};;
uint8_t buttonCount = sizeof(btn) / sizeof(btn[0]);
void btnL_pressAction(void)
{
if (btnL.justPressed()) {
Serial.println("Left button just pressed");
btnL.drawSmoothButton(true);
}
}
void btnL_releaseAction(void)
{
static uint32_t waitTime = 1000;
if (btnL.justReleased()) {
Serial.println("Left button just released");
btnL.drawSmoothButton(false);
btnL.setReleaseTime(millis());
waitTime = 10000;
}
else {
if (millis() - btnL.getReleaseTime() >= waitTime) {
waitTime = 1000;
btnL.setReleaseTime(millis());
btnL.drawSmoothButton(!btnL.getState());
}
}
}
void btnR_pressAction(void)
{
if (btnR.justPressed()) {
btnR.drawSmoothButton(!btnR.getState(), 3, TFT_BLACK, btnR.getState() ? "OFF" : "ON");
Serial.print("Button toggled: ");
if (btnR.getState()) Serial.println("ON");
else Serial.println("OFF");
btnR.setPressTime(millis());
}
// if button pressed for more than 1 sec...
if (millis() - btnR.getPressTime() >= 1000) {
Serial.println("Stop pressing my buttton.......");
}
else Serial.println("Right button is being pressed");
}
void btnR_releaseAction(void)
{
// Not action
}
void initButtons() {
uint16_t x = (tft.width() - BUTTON_W) / 2;
uint16_t y = tft.height() / 2 - BUTTON_H - 10;
btnL.initButtonUL(x, y, BUTTON_W, BUTTON_H, TFT_WHITE, TFT_RED, TFT_BLACK, "Button", 1);
btnL.setPressAction(btnL_pressAction);
btnL.setReleaseAction(btnL_releaseAction);
btnL.drawSmoothButton(false, 3, TFT_BLACK); // 3 is outline width, TFT_BLACK is the surrounding background colour for anti-aliasing
y = tft.height() / 2 + 10;
btnR.initButtonUL(x, y, BUTTON_W, BUTTON_H, TFT_WHITE, TFT_BLACK, TFT_GREEN, "OFF", 1);
btnR.setPressAction(btnR_pressAction);
//btnR.setReleaseAction(btnR_releaseAction);
btnR.drawSmoothButton(false, 3, TFT_BLACK); // 3 is outline width, TFT_BLACK is the surrounding background colour for anti-aliasing
}
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18);
// Calibrate the touch screen and retrieve the scaling factors
//touch_calibrate();
initButtons();
}
void loop() {
static uint32_t scanTime = millis();
uint16_t t_x = 9999, t_y = 9999; // To store the touch coordinates
// Scan keys every 50ms at most
if (millis() - scanTime >= 50) {
// Pressed will be set true if there is a valid touch on the screen
bool pressed = tft.getTouch(&t_x, &t_y);
scanTime = millis();
for (uint8_t b = 0; b < buttonCount; b++) {
if (pressed) {
if (btn[b]->contains(t_x, t_y)) {
btn[b]->press(true);
btn[b]->pressAction();
}
}
else {
btn[b]->press(false);
btn[b]->releaseAction();
}
}
}
}
If they do and GUIslice api still doesn't you will need help from @ImpulseAdventure Calvin, I only support the Builder. Paul--
Thank you so much for the support, but how to contact @ImpulseAdventure Calvin ?
``I think I found something that might be the cause of the problem with STM32 boards specifically.
I found this in GUIslice_drv_tft_espi.cpp
- line: 58-76.
#if defined(DRV_TOUCH_ADA_STMPE610)
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_STMPE610.h"
#elif defined(DRV_TOUCH_ADA_FT6206)
#include <Wire.h>
#include "Adafruit_FT6206.h"
#elif defined(DRV_TOUCH_ADA_SIMPLE)
#include <stdint.h>
#include <TouchScreen.h>
#elif defined(DRV_TOUCH_XPT2046_STM)
// NOTE: This file is located in the Arduino_STM32 library:
// Arduino_STM32/STM32F1/libraries/Serasidis_XPT2046_touch/src/XPT2046_touch.h
#include <XPT2046_touch.h>
#elif defined(DRV_TOUCH_XPT2046_PS)
#include <XPT2046_Touchscreen.h>
#elif defined(DRV_TOUCH_HANDLER)
#include <GUIslice_th.h>
#endif
So this:
// NOTE: This file is located in the Arduino_STM32 library:
// Arduino_STM32/STM32F1/libraries/Serasidis_XPT2046_touch/src/XPT2046_touch.h
#include <XPT2046_touch.h>
My question now is where to find XPT2046_touch.h
?
Is it this one https://github.com/PaulStoffregen/XPT2046_Touchscreen
? but it's not the same letters count.
@eagl1 you can send email to guislice@gmail.com
I don't think you want PaulStoffregen/XPT2046_Touchscreen I just followed the path given Arduino_STM32/STM32F1/libraries/Serasidis_XPT2046_touch/ and zipped it for you. No idea if it will work or not. Unzip to your Arduino/libraries folder Serasidis_XPT2046_touch.zip Paul--
@eagl1 Before you try that new touch library, if you have TFT_eSPI working without it then I would keep TOUCH_CS uncommented and instead inside your GUIslice/configs/stm32-tftespi-default-xpt2046.h change to use the TFT_eSPI internal touch driver like so
// -----------------------------------------------------------------------------
// SECTION 1: Device Mode Selection
// - The following defines the display and touch drivers
// and should not require modifications for this example config
// -----------------------------------------------------------------------------
#define DRV_DISP_TFT_ESPI // bodmer/TFT_eSPI
#define DRV_TOUCH_TFT_ESPI // TFT_eSPI integrated XPT2046 touch driver
#define DRV_TOUCH_IN_DISP // Use display driver (TFT_eSPI) for touch events
// #define DRV_TOUCH_XPT2046_STM // XPT2046 touch driver (rogerclarkmelbourne/Arduino_STM32)
// #define DRV_TOUCH_XPT2046_PS // PaulStoffregen/XPT2046_Touchscreen
Paul--
Worked perfectly :)
Thank you so much man !
Hi,
I'm working on a simple project to test the touch functionality, it turns out the button is pressed without touching the display.
Here's the code: