Reading 64 CPR Encoder

Hi, I have difficult in reading encoder count using an interrupt.

I am using a 2826 motor with 64 CPR Encoder +Pololu Dual VNH5019 Motor Driver Shield for Arduino + Arduino 101.
I connected Encoder A signal to Arduino board pin 3 and Encoder B signal to pin 5. Then, the Arduino program attaches it to interrupt 3, attachInterrupt(3, leftEncoderEvent, CHANGE);, as below.

void leftEncoderEvent() {
if (digitalRead(LH_ENCODER_A) == digitalRead(LH_ENCODER_B)) {
    leftCount++;
  } else {
    leftCount--;
  }
  Serial.println(leftCount);
}

When, the motor was driven with md.setM1Speed(200), the reading is not correct. The count does not increase or decease as expected. Here are some weird reading as an example.
-88, -89, -88, -87, -88, -89, -90, -91, -90, -89, -88, -89, -90, -89, -88, -87, -86, -87, -88

Am I missing something? What can be wrong with my setup? I would appreciate any advices.

Hello.

The Arduino 101 does not support CHANGE mode interrupt on pin 3. You can look at the “Input and Output” section on its official page on the Arduino website to find another pin to use that supports CHANGE mode interrupt.

If you continue to have issues, please post your entire code here as well as pictures of your setup clearly showing all your connections so that I can better troubleshoot the problem.

- Amanda

Amanda,
Thank you for the support. Now the encoder works fine. I was able to read the encoder count with the interrupt!

Unfortunately, I encountered another problem.
I tested two motor channels of the Dual VNH5019 Motor Driver Shield , M1 and M2.
M1 runs fine for everything, but somehow M2 does not run.
For a test, I connected only M2A and M2B lines, and command md.setM2Speed(200).
With the wiring, the green led for forward direction is off (motor does NOT run)
Without the wiring, the green led for forward direction is on.

I did the same test with M1A and M1B, wtih md.setM1Speed(200).
With the wiring, the green led for forward direction is on (motor does run well)
So M1 works but M2 does not.
I would appreciate any advices to make M2 work.

It sounds like it might be a connection issue. Can you post pictures of the Dual VNH5019 Motor Driver Shield detached from your system that clearly show both sides of the board?

- Amanda

Hi Amanda,

I attached a PDF file showing Motor connection with M2 channels. Only motor power is wired. Please let me know if you need more images for troubleshoot.
Thank you!

image1.pdf (475.3 KB)

I added images of both top and bottom sides after taking the driver board out from Arduino 101.

image2.pdf (1005.9 KB)

Your connections look fine, but you should add more solder to pins M2A and M2B to ensure they are making good contact with pads on the board.

What kind of power supply are you using to power your setup?

- Amanda

I will add more solder to see if that is the problem.

I am using a sealed lead acid12V battery.

I added more solder at the pins M2A and M2B, but it does not improve.

Have you ever gotten M2 (M2A and M2B) to work before? Can you post pictures showing the solder you added?

- Amanda

No, it never worked before. Attached is an image with the added solder.

image3.pdf (211.9 KB)

The soldering looks fine to me. It does seem like M2 is not functioning properly. Please contact us by email (at support@pololu.com) with your order information and reference this thread and we can look into a replacement.

- Amanda