Ghost button presses on SPI pin

Hi forum,

I’m having a weird issue with the behaviour of some pins that are related to SPI - so hopefully I’m in the right forum :slight_smile:

I have an ESP32 from Waveshare that has a special connector for ePaper-Displays, which uses SPI.
This uses internally these PINs for the SPI communication with the display (which are non standard SPI pins):

#define PIN_SPI_SCK 13
#define PIN_SPI_DIN 14
#define PIN_SPI_CS 15
#define PIN_SPI_BUSY 25
#define PIN_SPI_RST 26
#define PIN_SPI_DC 27

I use the GxEPD2_GFX for drawing on the screen. This library uses per default the standard SPI pins , so there’s a documented workaround on how to get around that:

GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25)); // GDEW0213I5F
.
.
.
//Init Display
  display.init(115200); // uses standard SPI pins, e.g. SCK(18), MISO(19), MOSI(23), SS(5)
  // *** special handling for Waveshare ESP32 Driver board *** //
  // ********************************************************* //
  SPI.end(); // release standard SPI pins, e.g. SCK(18), MISO(19), MOSI(23), SS(5)
  //SPI: void begin(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);
  SPI.begin(13, 12, 14, 15); // map and init SPI pins SCK(13), MISO(12), MOSI(14), SS(15)
  // *** end of special handling for Waveshare ESP32 Driver board *** //
  // **************************************************************** //
  // first update should be full refresh
  display.setRotation(1);

With this, the display works perfectly.
And as far as I understand the standard SPI pins should be available for other purposes.

I have connected some buttons to the ESP32 - one of them on PIN 18 (which is SPI CLK for standard SPI pins).

But although I define all the button-related stuff after the lines above, there are some “Ghost presses” that the Button library (EasyButton) recognizes during some bigger refreshs of the screen.

Here’s the code for the button, that comes after the display related stuff in the setup()

//Before setup()
EasyButton leftButton(BTN_LEFT_PIN);
EasyButton rightButton(BTN_RIGHT_PIN);
EasyButton backButton(BTN_BACK_PIN);
EasyButton centerButton(BTN_CENTER_PIN);

setup(){
  //display stuff (see above)

  
  leftButton.begin();
  rightButton.begin();
  backButton.begin();
  centerButton.begin();

  leftButton.onPressedFor(800, onLeftLongPress);
  rightButton.onPressedFor(800, onRightLongPress);
  backButton.onPressedFor(800, onCenterLongPress);
  centerButton.onPressedFor(800, onBackLongPress);

  leftButton.onPressed(onLeftPress);
  rightButton.onPressed(onRightPress);
  backButton.onPressed(onCenterPress);
  centerButton.onPressed(onBackPress);
}

I suspect that the SPI somehow still is active on that PIN, although SPI.end() is called.
Sadly I cannot switch to other PINs for my buttons since my project needs lots of pins.

Does anybode know what’s going on here and if there are possibilities to really free this PIN?

Thank you!
Martin

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