Hi I have a DC motor with encoder which has a PPR count of 990 (No load RPM = 107). However, I tried to read the number of ticks (on a Raspberry Pi 3B) by rotating the wheel 1 turn and I get a PPR count way too low, let's say 200 (It varies each time). The following is my Python code.
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
enc_L = 4; tick_L = 0; # Left motor encoder pin
sleep(1)
def my_callback_L(channel):
global tick_L
tick_L+=1
print(tick_L)
GPIO.setup(enc_L, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(enc_L, GPIO.RISING,callback=my_callback_L)
Now I tried to do the same thing on an Arduino Nano and to my surprise, the Nano gave exactly 990 PPR. The following is my Arduino code.
const int enc_pin1 = 2;
volatile long ticks1 = 0;
int tpr = 990;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(enc_pin1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(enc_pin1),countTicks1, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
}
void countTicks1(){
ticks1++;
Serial.println(ticks1);
}
So my question is why is the Pi missing encoder counts? Is it due to bouncetime? Or is there some other issue?, and how do I get the correct tick values? I need it so that I can calculate motor RPM.