Skip to content

Encoder not working as expected #46

@alessandrv

Description

@alessandrv

Hello, love your libraries for micropython. I've been testing the encoder only mode for micro-gui but had a lot of issues with getting my encoders to work.
I also tried using your encoder library from another repo to test printing the deltas to see if I was getting the right values and it looked like that, so I added a print for the delta also in the ugui.py file on the encoder callback and saw that the callback was not getting called for every dent I was turning (encoder set as 1) but a lot less of that, while the other encoder class of yours has the division ratio at 1 and register every dent perfectly.

Here's my hardware setup:

from machine import Pin, SoftI2C, freq
import gc
from ssd1306 import SSD1306_I2C as SSD
# Create and export an SSD instance
scl_pin = Pin(4)
sda_pin = Pin(0)

# Create an I2C object using the specified pins
i2c = SoftI2C(scl=scl_pin, sda=sda_pin)
gc.collect()  # Precaution before instantiating framebuf
ssd = SSD(128, 64, i2c)

gc.collect()
from gui.core.ugui import Display, quiet
# quiet()
# Create and export a Display instance
# Define control buttons
enc_clk = Pin(32, Pin.IN, Pin.PULL_UP)
enc_dt = Pin(33, Pin.IN, Pin.PULL_UP)
enc_btn = Pin(27, Pin.IN, Pin.PULL_UP)


display = Display(ssd, nxt=enc_clk, sel=enc_btn, prev=enc_dt, incr=False, encoder=1)

And here the simple script that uses the encoder class just to check the delta

def cb(pos, delta):
    print(pos, delta)
    

def prova():
    print('Running encoder test. Press ctrl-c to teminate.')
    enc = Encoder(px, py, v=0, vmin=None, vmax=None, callback=cb)
    
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()

prova()

I the encoder behaved randomly in both cases I would think it's my encoder issue but doesn't look like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions