I'm building automatic roller blinds and using encoder values to determine position of the blind.
However, during my testing, I noticed that there is an encoder drift.
For example, when I move the motor to position 0 then to position 100 and back a couple of times, positions shift higher off the ground.
Here is my interrupt handler:
Code: Select all
class Motor: def __init__(self, pins): self._enc2 = Pin(pins['enc2'], Pin.IN) self._enc1 = Pin(pins['enc1'], Pin.IN) self._enc1.irq(trigger = Pin.IRQ_FALLING, handler=self.handle_enc1) def handle_enc1(self, pin): if self._enc2.value() == 1: self._pos += 1 else: self._pos -= 1
I guess I have 3 questions:
1. Does this interrupt handler look good for handling encoder values? For example, would it be better to have a second handler for `enc2` pin instead of reading it's value inside of the `enc1` pin?
2. Would print statements affect values coming from interrupt handler? My understanding is that interrupt will fire no matter what, but maybe when I have print statements and serial communication (mpremote) it affects the performance of interrupts?
3. I'm using raspberry pi pico which has 2 cores. Is it possible to offload interrupt handling to a second core, so I don't have to worry about it clashing with the rest of the code?