I have been experimenting with tri-state multiplexing with the Rp2040's PIO statemachine and have found good success.
The PIO code is quite interesting in that its quite different from how I might write it in c-code in a repeating ISR. I may write a blog about it in the future, but here is the code:
# Tri-state multiplexing with done with PIO statemachine # -scottiebabe 2022 import time from machine import Pin import rp2 # Ensure pin pull-ups and pull-downs are disabled # So pin is Hi-Z when set as input Pin(0,Pin.IN) Pin(1,Pin.IN) Pin(2,Pin.IN) @rp2.asm_pio(out_shiftdir=rp2.PIO.SHIFT_RIGHT,set_init=[rp2.PIO.OUT_LOW]*3,out_init=[rp2.PIO.OUT_LOW]*3) def charlie(): pull(noblock) mov(x,osr) # Set Pin0 & Pin1 as outputs in_(null,2) in_(osr,1) # output state of LED0 on Pin0 out(null,1) set(pindirs, 0b011) mov(pins, isr) [7] in_(null,1) in_(osr,1) # output state of LED1 on Pin1 in_(null,1) out(null,1) mov(pins, isr) [7] # Set Pin0 & Pin2 as outputs in_(null,2) in_(osr,1) # output state of LED2 on Pin0 out(null,1) set(pindirs, 0b101) mov(pins, isr) [7] in_(osr,1) # output state of LED3 on Pin2 in_(null,2) out(null,1) mov(pins, isr) [7] # Set Pin1 & Pin2 as outputs in_(null,1) in_(osr,1) # output state of LED4 on Pin1 in_(null,1) out(null,1) set(pins,0) set(pindirs, 0b110) mov(pins, isr) [7] in_(osr,1) # output state of LED5 on Pin2 in_(null,2) out(null,1) mov(pins, isr) [7] # Create the StateMachine with the charlie program, outputting on Pins 0-2. sm = rp2.StateMachine(0, charlie, freq=20000, set_base=Pin(0),out_base=Pin(0)) # Put bitmap into pio statemachine sm.put(0b101) # Start the StateMachine. sm.active(1) i = 0 while True: i += 1 sm.put(i % 64) time.sleep(0.1)
I would like to try and make my own fairly light strings with three wires and 6 LEDs, similar to these
What do you think the best way to solder the LEDs to wires would be?
I'm thinking maybe use a piece of perfboard to hold everything in place while soldering