Difficulties with interrupt using encoders for motor

I originally built my project on the Arduino Uno R4 Wifi. Everything seemed to work fine.

#include <Arduino.h>

#define CLK_PIN D2
#define DT_PIN D3

unsigned long lastTime = 0;
bool blinkState = true;

int leftEncoderAngle = 0;



void onLeftTrigger()
{
  bool dirState = digitalRead(DT_PIN);
  if (dirState)
    leftEncoderAngle++;
  else
    leftEncoderAngle--;
}

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

  pinMode(LED_BUILTIN, OUTPUT);

  pinMode(CLK_PIN, INPUT_PULLDOWN);
  pinMode(DT_PIN, INPUT_PULLDOWN);

  attachInterrupt(digitalPinToInterrupt(CLK_PIN), onLeftTrigger, RISING);
}

void loop()
{
  auto timeStamp = millis();
  if (timeStamp - lastTime >= 100)
  {
    if (blinkState)
    {
      digitalWrite(LED_BUILTIN, LOW);
    }
    else
    {
      digitalWrite(LED_BUILTIN, HIGH);
    }
    blinkState = !blinkState;
    lastTime = timeStamp;

    Serial.println(leftEncoderAngle);
  }
  delay(10);
}

I then tried to move the project to Arduino Nano ESP32 due to its form factor. I'm running the exact same code and the readings go totally wacko. Sometimes it triggers and other times it doesn't.

The bool dirState = digitalRead(DT_PIN); never seems to work, i.e. when leftEncoderAngle increments (on the random occasion) the state of the other pin is never detected

Here is an image of the encoder signals on a scope.

I am using the yellow and purple lines.

That indicates a hardware problem.

Post an annotated schematic, I believe @DrDiettrich nailed it. If there are two different boards post both annotated schematics.

I tried on two different Nano ESP32. Second was brand new out of the box.

What about the cables, pullup resistors...?

I tried pull-up and pull-down. Tried with and without my own 8.2K resistor. Doesn't seem to make a difference.

I also just tried a 0.1uF debounce capacitor (connected to D2 and GND), doesn't seem to make any difference.

I did notice something interesting by accident. When I tap the other pins with my finger it seems to trigger an interrupt.

That indicates an open input. You definitely have to apply pullup resistors until that effect disappears.