NodeMCU not working where Nano did

My project (a multi-led counter) was originally built on a Nano but I now want to enable wifi for it. The LEDs and Max7219s are all working on a soldered breadboard, with power, ground and the 3 wires for the Data, Load and Clock running to another breadboard. The counters are incremented/decremented by push buttons. When I use the Nano, I have flexibility with the pins used. The push buttons (set as pull up) work fine (though I still have to tweak the bounce). But when I try to use a NodeMCU, I can use only D5, D6 and D7 for the Data, Load and Clock. If I use any of the others, I get unpredictable results. I also cannot seem to use the D1-4 as the signal pins for the switches.

Here's the Nano code:

// Define Connections to MAX72XX
const int DATAIN = 8; //DataIn (1)
const int LOADPIN = 9; // LOAD (12)nm
const int CLKPIN = 10; // CLK (13)
// define pushbutton inpupts
const int INPUTPIN1 = 4;
const int INPUTPIN2 = 5;
const int INPUTPIN3 = 6;
const int INPUTPIN4 = 7;
int buttonPressed[4] = {INPUTPIN1, INPUTPIN2, INPUTPIN3, INPUTPIN4};

LedControl lc = LedControl(DATAIN, CLKPIN, LOADPIN, NUMCONTROLERS);

...

void setup()
{
  // assign push button pins
  for (int i = 0; i < 4; i++)
  {
    pinMode(buttonPressed[i], INPUT);
  }
}

Here's the NodeMCU Code

// Define Connections to MAX72XX
const int DATAIN = D5; //DataIn (1)
const int LOADPIN = D6; // LOAD (12)nm 
const int CLKPIN = D7; // CLK (13)
// define pushbutton inpupts
const int INPUTPIN1 = D1;
const int INPUTPIN2 = D2;
const int INPUTPIN3 = D3;
const int INPUTPIN4 = D4;
int buttonPressed[4] = {INPUTPIN1, INPUTPIN2, INPUTPIN3, INPUTPIN4};
...
void setup()
{
  // assign push button pins
  for (int i = 0; i < 4; i++)
  {
    pinMode(buttonPressed[i], INPUT);
  }
}

When connecting a volt meter to D1-4 I'm getting an output of 3v, which is why, when I connect the push button signal, all the counters think the button is being pushed even when it's closed.

Please post the complete codes and a real wiring diagram.

Railroader:
Please post the complete codes and a real wiring diagram. :slight_smile:

Including the switches.
Thanks.. Tom... :slight_smile:

Mind all the special functions on the pins of the NodeMCU...

GPIO16 (D0) is I remember connected to RESET on that board. It has an internal pull-down, no pull-up.
GPIO0 (D3) and GPIO2 (D4) have functionality in the boot process. Mind that if you connect anything special to it.

Railroader:
Please post the complete codes and a real wiring diagram. :slight_smile:

I didn't see the need to post all the code because both the Nano and NodeMCU code is identical except for the port declarations. I'm more looking for guidance on the behavior of the ports and why they seem to act differently on the NodeMCU even though they're declared as INPUT. If they're input, why are they emitting 3v? It's the 3v output that's causing the switches to register as open/high.

Then go deep into the documenatation for the controllers and look for differencies.

Controller inpu gives out 3 volt triggering switches.... Are You connecting two inputs to each other and get a trigger? An input is usually connected to an output.
Post a wiring please.

E.g. GPIO0 (D3) has a pull-up resistor and GPIO2 (D4) is connected to the on-board LED.

Do study the manuals, the pins of the NodeMCU (and the ESP8266 itself) are not as straightforward as those of the Arduino.

Railroader:
Controller inpu gives out 3 volt triggering switches.... Are You connecting two inputs to each other and get a trigger? An input is usually connected to an output.
Post a wiring please.

I'm just testing the pins on the breadboard with nothing attached and am getting output. I have the switches with a 10K resistor 5V on one side, GND on other and a connection from the GND side to a pin to detect when button is pushed (similar to Button Tutorial Example). When the leds started acting like the switch was closed, I decided to pull those wires and just test the pins, not expecting them to have any output.

#1, again.....

How do you know you are "getting output" while there is "nothing attached" to those pins?

Why do you pull up switches to 5V when using NodeMCU?

wvmarle:
How do you know you are "getting output" while there is "nothing attached" to those pins?

I'm connecting the + terminal of the voltmeter to the pin and the - to ground. Perhaps "output" is the wrong word. I'm getting voltage, which I would not expect when a pin is set to input.

wvmarle:
Why do you pull up switches to 5V when using NodeMCU?

The MAX7219 operates on 5V. Putting the switches on 3v might be a good idea, but I think I'm moving the project in a different direction, after exploring the ESP8266 and ESP32, and might move to the ESP32 with MicroPython. Although this project started as a stand-alone device, with no expectation for wifi connectivity, I'm seeing some features that would be nice via wifi or bluetooth. I'm also finding, upon more research, the ESP8266 and ESP32 are more complex than just setting them to input or output, and controling the interupts directly might be better suited to my needs.

But do you realise that the ESP is a 3.3 V device and you must not put any voltage higher than the 3.3 V supply on an input pin (or output pin for that matter)?

mc2software:
I'm just testing the pins on the breadboard with nothing attached and am getting output. ** I have the switches with a 10K resistor 5V on one side, GND on other and a connection from the GND side to a pin to detect when button is pushed** (similar to Button Tutorial Example). When the leds started acting like the switch was closed, I decided to pull those wires and just test the pins, not expecting them to have any output.

Ahh No..
Connect the input pin of your controller to the side of the button connected to the10K resistor.
This point will be at gnd when the button is open and 5V when the button is pressed, check with your DMM.
Where you have it "a connection from the GND side to a pin to detect when button is pushed " will always be GND.

Tom... :slight_smile:

Pulling up an ESP8266 (or ESP32) input to 5V through a 10k or larger resistor will just make the input rise to ~3.8V without doing any harm. It wont rise to 5V. The moment you set that pin to output however it won't get over 3.3V when set to high.

Unfortunately the max7219 does demand 3.5V for a guaranteed high so you will need to do some kind of level shifting. Can be as simple as a diode or a transistor and two resistors.

TomGeorge:
Ahh No..
Connect the input pin of your controller to the side of the button connected to the10K resistor.
This point will be at gnd when the button is open and 5V when the button is pressed, check with your DMM.
Where you have it "a connection from the GND side to a pin to detect when button is pushed " will always be GND.

Tom... :slight_smile:

I may not have been clear in how I have it wired, but the wiring diagram you display is what I'm doing. However, I wonder if Paul__B's point about 3.3v might complicate things. They work perfectly on the Nano, so they're wired correctly, but I still don't understand why I'm getting 3v output on the pins I've defined as input. I'm exploring ESP32 boards instead of the ES8266 since it has more ports without pulldown.

I got the LEDs working fine so I tried adding the buttons to increment/decrement the LEDs, but found that the project would reboot whenever I pressed a button, so after verifying continuity and soldering, I decided to test things out with a breadboard, only to find the same result. I then decided to build a separate pushbutton only breadboard to verify that I'm hooking up the pushbuttons correctly. This is the code I use and it works fine, but the second set of code (the one for the main project -- a straight pool counter ) started the reboot process. To be clear, NO changes are made to the breadboard. I upload the first code and pushbuttons works. I upload the second code, pushbuttons reboot the chip. Each of the four buttons blinks the LED a different number of times (1 to 4).

Multi-pushbutton Code:

int ledPin = 13;      // choose the pin for the LED
int input4Pin = 7;
int input3Pin = 6;
int input2Pin = 5;
int input1Pin = 4;

void setup()
{
  pinMode(ledPin, OUTPUT);   // declare LED as output
  pinMode(input4Pin, INPUT);
  pinMode(input3Pin, INPUT);
  pinMode(input2Pin, INPUT);
  pinMode(input1Pin, INPUT);
  // Setup Serial Monitor
  Serial.begin(9600);
  Serial.print("Setup :");
}

void loop()
{
  for(int i=4 ; i<=7 ; i++)
  {
    checkPush (i);
    delay(50);
  }
}

void checkPush(int pinNumber)
{
  int pushed = digitalRead(pinNumber);  // read input value
  if (pushed == HIGH) // check if the input is HIGH (button released)
    {
        // blink # times based on which button was pushed
        for(int i=4 ; i<=pinNumber ; i++)
        {
            digitalWrite(ledPin, HIGH);  // turn LED ON
            Serial.print("HIGH :");
            Serial.println(pinNumber);
            delay(500);
            digitalWrite(ledPin, LOW);  // turn LED OFF
            Serial.print("LOW :");
            Serial.println(pinNumber);
            delay(500);
        }
    }
}

Here's the Straight Pool Counter Code.

StraightPoolCounter.ino (30.3 KB)

I'm guessing a wiring problem where pushing the button drags down the 5V line causing the reset.