Buttons not working on WeMos D1 ESP8266

Hey there

I'm making a secure remote control for a robot
I have 4 buttons connected to the WeMos D1 (same size as the uno) and only 1 is working.
The buttons are connected to pins 4, 5, 6, and 7.
I'm using the button example as a base for "interfacing" with them

I have Serial.print(); for each button so I'm aware when it is working

here is my code ( issue in void move() )

//robot control
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//=============
//finger print
#include <Adafruit_Fingerprint.h>
//=============
//wifi point
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "WebAuth.h"
#include "Armed.h"
#include "Disarmed.h"
//=============

//fingerprint
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, use software serial...
// pin #2 (GREEN wire)
// pin #3 (WHITE wire)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
//=============

//wifi point
#ifndef APSSID
#define APSSID "LauncherV2"
#define APPSK "thereisnospoonj7cl5"
#endif
//=============

//variables
/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;

bool verify1 = true;
bool serverActive = false;
bool verify2 = false;
bool armed = false;

const int forward = D4;
const int backward = D5;
const int left = D6;
const int right = D7;

int forwardState = 0;
int backwardState = 0;
int leftState = 0;
int rightState = 0;

//test variables
bool fingerprint = false;
//=============52
//creating objects
//create the RF object and bind to "radio"
RF24 radio(9, 10);
//address where the RF modules communicate
const byte address[6] = "j7cl5";

//create the fingerprint object and bind to "finger"
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//create the server object and bind to "server"
ESP8266WebServer server(80);
//=============

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  pinMode(forward, INPUT);
  pinMode(backward, INPUT);
  pinMode(left, INPUT);
  pinMode(right, INPUT);

  radio.begin();
  //open the connection
  radio.openWritingPipe(address);
  //set as transmitter
  radio.stopListening();

  //fingerprint startup
  while (!Serial)
    ;  // For Yun/Leo/Micro/Zero/...
  delay(100);

  if (fingerprint == true) {
    Serial.println("\n\nAdafruit finger detect test");

    // set the data rate for the sensor serial port
    finger.begin(57600);
    delay(5);
    if (finger.verifyPassword()) {
      Serial.println("Found fingerprint sensor!");
    } else {
      Serial.println("Did not find fingerprint sensor :(");
      while (1) { delay(1); }
    }

    Serial.println(F("Reading sensor parameters"));
    finger.getParameters();
    Serial.print(F("Status: 0x"));
    Serial.println(finger.status_reg, HEX);
    Serial.print(F("Sys ID: 0x"));
    Serial.println(finger.system_id, HEX);
    Serial.print(F("Capacity: "));
    Serial.println(finger.capacity);
    Serial.print(F("Security level: "));
    Serial.println(finger.security_level);
    Serial.print(F("Device address: "));
    Serial.println(finger.device_addr, HEX);
    Serial.print(F("Packet len: "));
    Serial.println(finger.packet_len);
    Serial.print(F("Baud rate: "));
    Serial.println(finger.baud_rate);

    finger.getTemplateCount();

    if (finger.templateCount == 0) {
      Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
    } else {
      Serial.println("Waiting for valid finger...");
      Serial.print("Sensor contains ");
      Serial.print(finger.templateCount);
      Serial.println(" templates");
    }
  }
  //===============
  //Wifi startup
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);

  server.on("/armed", armBot);
  server.on("/disarmed", disarmBot);
  server.on("/rearm", handleRoot);
}

void loop() {
  // put your main code here, to run repeatedly:

  if (verify1 != true) {
    getFingerprintID();
  } else if (serverActive != true) {
    server.begin();
    Serial.println("HTTP server started");
    handleRoot();
    serverActive = true;
  } else if (verify2 != true) {
    server.handleClient();
    move();
  }
}

//=====ROBOT CONTROL=====
void move() {  // Print to Serial Monitor

  forwardState = digitalRead(forward);
  backwardState = digitalRead(backward);
  leftState = digitalRead(left);
  rightState = digitalRead(right);
  if (armed == false) {
    
    if (forwardState == HIGH) {
      //message to send
      Serial.print("forward");
      char move[] = "1";
      radio.write(&move, sizeof(move));  //_ , 2 , 3, 4 working clockwise

    } else if (backward == HIGH) {
      //message to send
      Serial.print("backward");
      char move[] = "3";
      radio.write(&move, sizeof(move));  //1 , 2 , _, 4 working clockwise

    } else if (leftState == HIGH) {
      //message to send
      Serial.print("left");
      char move[] = "4";
      radio.write(&move, sizeof(move));  //1 , 2 , 3, _ working clockwise

    } else if (rightState == HIGH) {
      //message to send
      Serial.print("right");
      char move[] = "2";
      radio.write(&move, sizeof(move));  //1 , _ , 3, 4 working clockwise

    } else {
      //message to send
      char move[] = "0";
      radio.write(&move, sizeof(move));  //stop
    }
  } else {
    //message to send
    char move[] = "0";
    radio.write(&move, sizeof(move));  //stop
  }
}
//========================

//===FINGERPRINT SENSOR===
uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
    move();

  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);
  move();
  verify1 = true;
  return finger.fingerID;
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK) return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK) return -1;

  // found a match!
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);
  return finger.fingerID;
}
//========================

//====WIFI ACCESSPOINT====
void handleRoot() {
  server.send(200, "text/html", HTML);
  move();
}

void armBot() {
  armed = true;
  Serial.print("\nArmed State ="); Serial.print(armed);
  Serial.print("\narmBot");
  //(send "arm" to the bot)
  //enable "armed" light
  server.send(200, "text/html", ARMED);
}

void disarmBot() {
  armed = false;
  Serial.print("\nArmed State ="); Serial.print(armed);
  Serial.print("\ndisarmBot");
  //(send "disarm" to the bot)
  // disable "armed" light
  server.send(200, "text/html", DISARMED);
}
//========================

Would someone be able to help
thanks

Not sure if this is an issue but You should probably use the Dx notation for all pins

—-

How are things wired? Do you have external pull down?

Have you checked if your button pins don’t have a special role for SPI or whatever hardware you might use?

Use INPUT_PULLUP and detect press when digitalRead == LOW

Yes, I think it is important to use the Dx numbers. If you simpy use plain numbers these are interpreted as GPIO numbers, but the GPIO numbers are different from the Dx numbers on the board. Of course you must select the correct board in the IDE, because Dx -> GPIO mapping differs between different boards.

And you must be aware, that the ESP8266 has less IO's than an UNO. Therefore some of the pins are connected internally. You can see that from the Dx definitions in ...\packages\esp8266\hardware\esp8266\3.0.2\variants\d1\pins_arduino.h . Some Dx refer to the same GPIO.

static const uint8_t D0   = 3;
static const uint8_t D1   = 1;
static const uint8_t D2   = 16;
static const uint8_t D3   = 5;
static const uint8_t D4   = 4;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 0;
static const uint8_t D9   = 2;
static const uint8_t D10  = 15;
static const uint8_t D11  = 13;
static const uint8_t D12  = 12;
static const uint8_t D13  = 14;
static const uint8_t D14  = 4;
static const uint8_t D15  = 5;

Example:
If you would like to use the contact labeled on the board with D1 for your button
and would like to use a pure number the code looks like this

const byte myButton = 5;

.

If you use the symbol "D1" D1 is not a pure number. It is a sequence of letter "D" and digit "1"

the code looks like this

const byte myButton = D1;

If you can use the symbol "D1" depends on which board you have chosen in the Arduino-IDE and if the board-definition has this symbol defined or not.

best regards Stefan

As per the previous post

➜ It is called a constant (or const variable or named constant)

Maybe I've not read your code carefully enough but I can't see where you read the buttons. What happens if you write a short sketch that just reads the buttons and prints the results?

Thought this was this part

And the following if

hey there
turns out I'm using a redundant board :roll_eyes: , ill be switching to the Arduino mega with wifi
this is because it will be slightly easier for me to understand, whilst providing enough functions for my project

thanks for helping