With wiring like this:
and my Raspberry Pi Pico attached on /dev/ttyACM1 (yours will likely be on /dev/ttyACM0), I installed the encoder library like this (don't type the $):Then I ran the following code, which I think is practically identical to the OPs:It ran without problems, printing a new value every time I turned the encoder.
If you don't have mpremote installed, you can get it with (again, don't type the $s):
(CLK - GPIO 0; DT - GPIO 1; GND - GND; + - 3.3 V; SW not connected)and my Raspberry Pi Pico attached on /dev/ttyACM1 (yours will likely be on /dev/ttyACM0), I installed the encoder library like this (don't type the $):
Code:
$ mpremote connect /dev/ttyACM1 mip install github:miketeachman/micropython-rotaryInstall github:miketeachman/micropython-rotaryInstalling github:miketeachman/micropython-rotary/package.json to /libInstalling: /lib/rotary.pyInstalling: /lib/rotary_irq_esp.py Installing: /lib/rotary_irq_pyb.py Installing: /lib/rotary_irq_rp2.py Done
Code:
# https://github.com/miketeachman/micropython-rotary# MIT License (MIT)# Copyright (c) 2021 Mike Teachman# https://opensource.org/licenses/MIT# example for MicroPython rotary encoder - rp2from rotary_irq_rp2 import RotaryIRQimport timer = RotaryIRQ( pin_num_clk=0, pin_num_dt=1, min_val=0, max_val=5, reverse=False, range_mode=RotaryIRQ.RANGE_WRAP, pull_up=True,)val_old = r.value()while True: val_new = r.value() if val_old != val_new: val_old = val_new print("result =", val_new) time.sleep_ms(50)
If you don't have mpremote installed, you can get it with (again, don't type the $s):
Code:
$ sudo apt install pipx$ pipx ensurepath$ pipx install mpremote
Statistics: Posted by scruss — Thu Mar 21, 2024 11:43 pm