No you can't!Since the output voltage specs show a range of 0.05 to 4.8 volts you can attach it directly to GPIO pins of your choice.
Code: Select all
import time from serial import Serial count = 0 COUNTS_TO_METERS = 0.001 # this depends on the encoder system def main_loop(): ser = Serial('/dev/tty.usbserial0', 115200) while True: time.sleep(1) # time depends on speed of robot position += count * COUNTS_TO_METERS count = 0 # a super simple serial response to report position if ser.read() == 'p': ser.write(position) # an interrupt that gets called every time A or B changes # you can do this with RPi.GPIO on the raspberry pi def interrupt_AB(): A, B = readEncoderPins() if A ^ B == 1: count += 1 else: count -= 1
Thank you! I actually got this same encoder working on the arduino. I'm not too familiar with the pi but i'm experimenting with it today. I want to eventually make it work with an LCD and a few other sensors
Exactly what i needed !! I used a voltage divider with resistors are discussed above and it seems to work. My numbers are off though but i'll dig into this some more. My encoder has 1000 counts per rev but im getting like 3500 per rev! Maybe i can just add a divider in my code to compensate? Thanks a ton for the vidsOutoftheBOTS wrote: ↑Tue Sep 11, 2018 7:31 pmThe code that was linked isn't complete and is just Python Pseudo Code not complete python code.
Reading quadrature encoders in python on RPi isn't very efficient to do because the fact that python on RPi isn't real time and has a lot of latency. The very easiest way to do it is with an external quadrature counter.
Here is a good video explaining the working of the encoder and best way of writing python code to count it see https://www.youtube.com/watch?v=p4BCFhIuC88&t=461s
And here is a video showing the advantage of using an external counter to do it. see https://www.youtube.com/watch?v=41ogu0UlwCc&t=12s