basic encoder examples failing

I tried this basic encoder example

 <Encoder.h> 

// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(2,3);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

from this site

My serial monitor only shows a single digit on each line- either a zero or a one

Then I tried this code:

#include <Encoder.h> 
Encoder knob(2,3);

void setup()
{
  Serial.begin(9600);
  
}
long positionKnob  = -999;

void loop(){
 long newKnob;
  newKnob = knob.read();
   if (newKnob != positionKnob ) {
    Serial.print("Knob = ");
    Serial.print(newKnob);
   Serial.println();
    positionKnob = newKnob;
  }
  // if a character is sent from the serial monitor,
  // reset both back to zero.
  if (Serial.available()) {
    Serial.read();
    Serial.println("Reset both knobs to zero");
    knob.write(0);
   
  }
}

simplified from this site:
https://www.pjrc.com/teensy/td_libs_Encoder.html#optimize

SAME RESULT

Meanwhile the LED on my motor is lit red.
I am using an arduino UNO and this motor:

https://www.openimpulse.com/blog/products-page/25d-gearmotors/jga25-371-dc-gearmotor-encoder-201-rpm-12-v-2/

and the Adafruit shield v2.3

The motor runs fine with this code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);

void setup() {
  // put your setup code here, to run once:

AFMS.begin();
myMotor->setSpeed(150);
myMotor->run(FORWARD);
}

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

from this site:

What encoder? Post a link to the product page or data sheet.

How, exactly, did you connect the encoder to the Arduino? Post a hand drawn wiring diagram.

When experimenting with a new sensor, it is a great idea to use that sensor all by itself, with simple example code and without any other distracting things like motors, LCD displays, etc.

Connect the encoder according to one of the many on line tutorials (avoid Instructables, as most of them are crap), load the example program and twist the encoder shaft by hand to test it.

The encoder is attached to the motor i referenced in the link

https://www.openimpulse.com/blog/products-page/25d-gearmotors/jga25-371-dc-gearmotor-encoder-201-rpm-12-v-2/

It is the same motor/encoder used in the instructables example here

The tech page for the encoder on the motor is here

http://repository.sainsmart.com/index.php?share/file&user=bbu_sainsmart&sid=KgPpwOBr

The encoder is attached as in the attached picture
Motor+ and Motor- go to M1 on the adafruit shield

Did you try the following test, from that Instructable, to verify correct encoder operation?

A little experiment I did with multimeter :

power the encoder with 2 AA battery, attach multimeter GND cable to GND of the battery , and multimeter RED cable to the C1 or C2 output of the encoder.

As you turn the motor slowly, you can see that the output voltage of C1 and C2 change from 0V to 3V.

If you have 2 multimeter, attach C1 and C2 each to a multimeter, then turn the multimeter slowly you can see the value of multimeter change from 3V-3V, 0V-3V,0V-0V,3V-3V, which is the pulse according the background theory)