Effector (mover) | Encoder KY-040 by Keyes - filament monitor

grafik.png grafik.png grafik.png grafik.png grafik.png

Technical data:

Warning: Wrong wiring can destroy CLK/DT lines (painfully tested)

Used for

Basic example script for testing with Raspberry Pi (not used in production!)

https://pypi.org/project/pigpio-encoder
https://github.com/joan2937/pigpio

apt install python3-pip
pip3.7 install pigpio_encoder
cd /opt/gpio/
git clone https://github.com/modmypi/Rotary-Encoder/
cd Rotary-Encoder
vim rotaryEncoder.py #used pins: clk=6, dt=12, sw=5
from pigpio_encoder import pigpio_encoder
 
def rotary_callback(counter):
    print("Counter value: ", counter)
 
def sw_short():
    print("Switch short press")
 
def sw_long():
    print("Switch long press")
 
my_rotary = pigpio_encoder.Rotary(clk=6, dt=12, sw=5)
my_rotary.setup_rotary(min=10, max=300, scale=5, debounce=200, rotary_callback=rotary_callback)
my_rotary.setup_switch(debounce=200, long_press=True, sw_short_callback=sw_short, sw_long_callback=sw_long)
 
my_rotary.watch()
#enable pigpiod daemon (required to run pigpio things)
vim /etc/systemd/system/pigpiod.service
 
[Unit]
Description=Pigpio daemon
 
[Service]
Type=forking
#disallow port 8888 from outside
ExecStart=/usr/bin/pigpiod -l
 
[Install]
WantedBy=multi-user.target
 
systemctl enable pigpiod.service
systemctl start pigpiod.service
service pigpiod restart
#finally run the script
python3.7 /opt/gpio/rotaryEncoder.py #do not use Python2 because it will fail

Version #1
Erstellt: 2026-06-07 22:59:50 CEST von Mario Voigt
Zuletzt aktualisiert: 2026-06-07 23:00:51 CEST von Mario Voigt