Button input doesn't work on an ESP8266 board with a Waveshare 4.2inch e-Paper display

I want to use a NodeMCU ESP8266 (ESP-12F) board with a Waveshare 4.2inch e-Paper display and a button to change pages.

I was able to get the display to work using the GxEPD library connecting it like this:

  • BUSY -> GPIO4 (D2)

  • RST -> GPIO5 (D1)

  • DC -> GPIO0 (D3)

  • CS -> GPIO15 (D8)

  • CLK -> GPIO14 (D5)

  • DIN -> GPIO13 (D7)

  • GND -> GND

  • 3.3V -> 3.3V

I tried to connect the button to GPIO12 (D6) and to configure the pin as INPUT_PULLUP but digitalRead always returns 0 and I can't get it to work.

These are the things I tried to do to fix the problem:

  • I checked for obvious errors in the code but I haven’t found anything

  • I uploaded a simple sketch to check the the button status without the code necessary to run the display and it worked, I did the same thing with a pull-down resistor and it worked as well.

  • I kept the pull-down resistor and I added the code necessary to run the display but the input value remains always 0

This is the code that I'm using, I hope someone can help me out.

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ArduinoOTA.h>

#include <GxEPD.h>
// select the display class to use, only one, copy from GxEPD_Example
#include <GxGDEW042T2/GxGDEW042T2.h>      // 4.2" b/w

#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#include <Fonts/FreeSansBold9pt7b.h>


// mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
// BUSY -> GPIO4(D2), RST -> GPIO5(D1), DC -> GPIO0(D3), CS -> GPIO15(D8), CLK -> GPIO14(D5), DIN -> GPIO13(D7), GND -> GND, 3.3V -> 3.3V
//RST modified from GPIO2 (factory) to GPIO5


// constructor for AVR Arduino
GxIO_Class io(SPI, /*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
GxEPD_Class display(io, /*RST=D1*/ 5, /*BUSY=D2*/ 4); // default selection of D4(=2), D2(=4)


// constants
const int ledPin = 2;      // the number of the LED pin
const int buttonPin = 12;      // the number of the BUTTON pin


void setup() {


  Serial.begin(115200);
  delay(5000);

  pinMode(buttonPin, INPUT);

  display.init();
  display.setFont(&FreeSansBold9pt7b);
  display.setTextColor(GxEPD_BLACK);
  display.fillScreen(GxEPD_WHITE);
  display.update();

  display.setTextSize(1);
  display.setCursor(0, 20);
  display.println("TEST");
  display.update();
}

void loop() {
  Serial.println(digitalRead(buttonPin));

}

Thanks a lot

Please also post the button test code that worked.

There it is

const int buttonPin = 12;     

void setup() {
   Serial.begin(115200);

  pinMode(buttonPin, INPUT);

}

void loop() {
Serial.println(digitalRead(buttonPin));
}

You didn't use INPUT_PULLUP there

During the tests I used INPUT and INPUT_PULLUP based on whether or not there was the pull-down resitor. I guess the last time I used the resistor.

So you changed both the code and the hardware? That won't help with troubleshooting, as it introduces additional doubts. You need to test the code with the same hardware so you know whether it's a software or hardware problem.

I tried one thing at a time. I uploaded the sketch without the part of the code for the display using INPUT_PULLUP and it worked. Without touching the hardware part I uploaded the complete sketch and the input stopped working.

I did the same thing with INPUT and the pull-down resistor: I uploaded the sketch without the part of the code for the display and it worked, I uploaded the complete sketch and the input stopped working.

That approach fails to leverage the working button only sketch.

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