MicroPython or Circuit for Pico RGB Rotary Breakout

Hi,

Has anyone got the rgb breakout rotary encoder working with micropython or circuitpython on a rpi pico?

(RGB Encoder Breakout – Pimoroni)

I’m having trouble trying to port the ioe example code to pico.

I saw this list as to what’s supported in the Pimoroni Micro Python uf2 file
I see RGB Encoder Breakout in the list. And it appears to be the one you have.

I do believe this is the Micro Python Pico stuff.
pimoroni-pico/micropython/examples at main · pimoroni/pimoroni-pico · GitHub

pimoroni-pico/micropython/examples/breakout_encoder at main · pimoroni/pimoroni-pico · GitHub

Many thanks, my google-fu was weak

I initially had circuit python on the pico and it detected the encoder breakout board on pins 11 & 12 during an i2c scan.

I flashed the pimoroni micropython, and loaded the demo from the examples linked above

from pimoroni_i2c import PimoroniI2C
from breakout_encoder import BreakoutEncoder

PINS_BREAKOUT_GARDEN = {"sda": 11, "scl": 12}
#PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}

steps_per_rev = 24

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
enc = BreakoutEncoder(i2c)

enc.set_brightness(1.0)
# enc.set_direction(BreakoutEncoder.DIRECTION_CCW)     # Uncomment this to flip the direction


# From CPython Lib/colorsys.py
def hsv_to_rgb(h, s, v):
    if s == 0.0:
        return v, v, v
    i = int(h * 6.0)
    f = (h * 6.0) - i
    p = v * (1.0 - s)
    q = v * (1.0 - s * f)
    t = v * (1.0 - s * (1.0 - f))
    i = i % 6
    if i == 0:
        return v, t, p
    if i == 1:
        return q, v, p
    if i == 2:
        return p, v, t
    if i == 3:
        return p, q, v
    if i == 4:
        return t, p, v
    if i == 5:
        return v, p, q


def count_changed(count):
    print("Count: ", count, sep="")
    h = ((count % steps_per_rev) * 360.0) / steps_per_rev     # Convert the count to a colour hue
    r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)]  # rainbow magic
    enc.set_led(r, g, b)


count = 0

count_changed(count)
enc.clear_interrupt_flag()

while True:
    if enc.get_interrupt_flag():
        count = enc.read()
        enc.clear_interrupt_flag()

        while count < 0:
            count += steps_per_rev

        count_changed(count)

However, I get a “ValueError: bad SDA pin”.
If I try GP pin numbering (8, 9) I get “breakout not found” instead, which indicates the board is being detected on 11 & 12. Is it my soldering skills?

A simple reset fixed it - not my day today

Stuff happens. The links to that stuff could be better IMHO. If you look hard enough you will find it though. I went to the Pico Breakout Garden shop page where it lists all the breakouts, a link to Pimorni’s Micro Python stuff is there if you scroll down far enough.