I'm using a Raspberry Pi 3 with some Cylewet KY-040 rotary encoders that I bought from Amazon to set up an art installation with Processing 3. Pi is just running the stock Raspbian NOOBS.

Right now, I'm trying to to adjust the radius of a circle with one of the rotary encoders, but the radius value is rapidly fluctuating from -1 to 1 with each turn/"click" when it should be increasing or decreasing by 1 depending on the direction of rotation.

I am VERY new to Processing and coding a Raspberry Pi with GPIO, so I'm not sure if this is an issue with my wiring or with the code :P

I have experimented with the delay() and it hasn't helped much to slow it down, as the values are just as incorrect, but print more slowly.

The values printing to the console are kinda accurate-- the circle's radius does match what prints to the console. Ideally, the console should be printing counter + 1 when rotated clockwise and counter - 1 when rotated counterclockwise, however...

when turning the encoder clockwise only, the radius values are printing to the console as follows:

1
2
3
2
3
4
3
2
1
2

A similar result is produced when turning the encoder counter-clockwise, but with negative values:

-1
-2
-3
-2
-3
-2
-1
0

Note: when I turn the encoder slowly and lightly pull the rotating knob on the encoder, I am able to get closer to the result I want.

As a matter of interest what happens if you change the two GPIO.INPUT_PULLDOWN to GPIO.INPUT_PULLUP?
– joanJan 8 at 9:11

@joan It doesn't seem to make much of a difference when I change it from PULLDOWN to PULLUP.
– anokheeJan 8 at 14:51

1

Okay, I just checked the shopping FAQ and it does say the module already has pull-ups. Please note that you should be powering the device from 5V and you should be using a 5V to 3V3 voltage converter between the two outputs and the Pi GPIO. I suggest you try abyz.me.uk/rpi/pigpio/examples.html#Python_rotary_encoder_py to confirm the data being received.
– joanJan 8 at 15:51