Measuring encoder count for movement
We know what sequences to expect for our encoder, and we have a working knowledge of PIO assembler. So, we can bring these together to create the counter. We’ll start simple though; let’s see how to detect when a system has changed.
Making a simple PIO change detection loop
As we saw in the read two pins example, when we output the system’s state in a tight loop, it floods off anything interesting. We are interested in state changes, a step toward the full decoder. In the pio_one_encoder_when_changed.py
file, we go straight from imports into the assembler:
import board import rp2pio import adafruit_pioasm import array
We start by clearing y –
; we are going to use y
to store a pin value for comparison:
program = """ set y, 0
The following code creates a read
label; we can loop to this point to get new pin readings. It stores the old y
in x so that we can get a new...