Whell Encoder help me please!

Hi,

My English is bad. I’m trying to use the encoder with the Arduino, I want to count rounds in one direction only.
So I used m1A and M2a, m1B and m2B free (my code 255).
But my codes not working. Here’s how I make a mistake, can you help me?

PololuWheelEncoders encoder;
void setup(){
    encoder.init(2,255,3,255);
}

Loop

void loop(){

   analogWrite(enableSolMotor, 120); // For pwm with L298N
   analogWrite(enableSagMotor, 120); // For pwm with L298N

      digitalWrite(leftMotor1, HIGH);
      digitalWrite(leftMotor2, LOW);
      digitalWrite(rightMotor1, HIGH);
      digitalWrite(rightMotor2, LOW);    
  
   while(encoder.getCountsM1() > 100  ){  // 101 rounds to count and stop
      digitalWrite(leftMotor1, LOW);
      digitalWrite(leftMotor2, LOW);
      digitalWrite(rightMotor1, LOW);
      digitalWrite(rightMotor2, LOW);
   }
   

}

Hello.

Even if you only want to count rotations in one direction, you still need to monitor both the A and B outputs of the encoder when using our library code. At a minimum, you will need:

encoder.init(2,3,255,255);

If you have two motors with encoders, you will need to use four pins. For example:

encoder.init(2,3,4,5);

Note that if you know that your motor will always only spin in one direction, you can get by with monitoring only one encoder output, but you would have to write your own code to do this.

- Ben

Hi Ben,

I thought can be done using only one exit, thank you for information.
I want to ask something else;
I using the Arduino Uno, but only 2,3 no pin interrupt pins. Other pins aren’t interrupt functions. Arduino Uno uses pins 2,3,4,5 with Can I use your library functions?
For example;

encoder.init(2,3,4,5);

The Arduino Uno only has a few “external interrupt” pins, but all of the digital I/O pins have what are called “pin-change interrupts”. Our encoder library uses these interrupts, so you can use any digital I/O pins for your encoders.

- Ben

Thanks Ben, I worked my code.