Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3576

MicroPython • Rotary Encoder

$
0
0
Hi everyone

Im am new here an currently seeking some help. I am trying to code a reliable read out for a rotary Encoder. up until now I was trying to do it on my own, but I didnt get that far. I saw another thread with similar issues and tryed to solve it with the posts there but I have an error wich is not mentioned. The other Thread is locked so I started this new one. Im also fairly new to MicroPython so my knowledge is pretty llimitted.

as for the Code:

Code:

import timefrom rotary_irq_pico import RotaryIRQr = RotaryIRQ(pin_num_clk=0,               pin_num_dt=1,               min_val=0,               max_val=100,               reverse=False,               range_mode=RotaryIRQ.RANGE_WRAP,              pull_up=True)[code]

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)[/color][/code]

is the Code wich is used in the Rasperry Pi Pico

ande the rotary Librairy:

Code:

from machine import Pinfrom rotary import Rotaryfrom sys import platformclass RotaryIRQ(Rotary):         def __init__(self, pin_num_clk, pin_num_dt, min_val=0, max_val=10, reverse=False, range_mode=Rotary.RANGE_UNBOUNDED, pull_up=False):                 super().__init__(min_val, max_val, reverse, range_mode, pull_up)                if pull_up == True:            self._pin_clk = Pin(pin_num_clk, Pin.IN, Pin.PULL_UP)            self._pin_dt = Pin(pin_num_dt, Pin.IN, Pin.PULL_UP)        else:            self._pin_clk = Pin(pin_num_clk, Pin.IN)            self._pin_dt = Pin(pin_num_dt, Pin.IN)        self._enable_clk_irq(self._process_rotary_pins)                self._enable_dt_irq(self._process_rotary_pins)               def _enable_clk_irq(self, callback=None):        self._pin_clk.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=callback)            def _enable_dt_irq(self, callback=None):        self._pin_dt.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=callback)            def _disable_clk_irq(self):        self._pin_clk.irq(handler=None)            def _disable_dt_irq(self):        self._pin_dt.irq(handler=None)             def _hal_get_clk_value(self):        return self._pin_clk.value()            def _hal_get_dt_value(self):        return self._pin_dt.value()           def _hal_enable_irq(self):        self._enable_clk_irq(self._process_rotary_pins)                self._enable_dt_irq(self._process_rotary_pins)       def _hal_disable_irq(self):         self._disable_clk_irq()        self._disable_dt_irq()         def _hal_close(self):        self._hal_disable_irq()
and the Error in Question looks as follows:

Code:

MPY: soft rebootTraceback (most recent call last):  File "<stdin>", line 2, in <module>ImportError: no module named 'rotary_irq_pico'

Also maybe important to mention my rotary Encoder is without any pcb pcb or somehting else its just a bare rotary encode.

Im sorry if the Format is really bad :)

Thank you for the help for those who wish to help me

Statistics: Posted by Quadropol — Tue Mar 19, 2024 6:35 pm — Replies 1 — Views 17



Viewing all articles
Browse latest Browse all 3576

Trending Articles