Raspberry Pi Pico
LED Shim
The LED Shim is a no-solder board that is designed to push fit onto a Raspberry Pi GPIO header. It uses the same LED driver as the Scroll Pack, Scroll HAT HD, 11x7 LED Matrix. Instead of single colour LEDs, you have RGB LEDs and you work a little harder in the code to target the red, green and blue parts of each pixel on the grid. The trick with all of the IS31FL3731 boards is to find out how the LEDs map to the 144 pixels that the driver chip supports. Once you do that, you can get somewhere.
I mounted this on my Pico to HAT adapter board.
Here is my library for the LED Shim. I saved it as ledshim.py
from time import sleep_ms _f = 0 _b = bytearray(145) class LEDSHIM: def __init__(self, i2c): self.i2c = i2c self._w(253, 11) sleep_ms(100) self._w(10, 0) sleep_ms(100) self._w(10, 1) sleep_ms(100) self._w(0, 0) self._w(6, 0) for bank in [1,0]: self._w(253, bank) self._w([0] + [255] * 17) self.clear() self.show() def _w(self, *args): if len(args) == 1: args = args[0] self.i2c.writeto(117, bytes(args)) def clear(self): global _b del _b _b = bytearray(145) def fill(self, v): global _b del _b _b = bytearray([v]*145) def show(self): global _f _f = not _f self._w(253, _f) _b[0] = 36 self._w(_b) self._w(253, 11) self._w(1, _f) def set_pixel(self,n,r,g,b): global _b tbl = [118,69,85, 117,68,101, 116,84,100, 115,83,99, 114,82,98, 113,81,97, 112,80,96, 134,21,37, 133,20,36, 132,19,35, 131,18,34, 130,17,50, 129,33,49, 128,32,48, 127,47,63, 121,41,57, 122,25,58, 123,26,42, 124,27,43, 125,28,44, 126,29,45, 15,95,111, 8,89,105, 9,90,106, 10,91,107, 11,92,108, 12,76,109, 13,77,93] x = n * 3 _b[tbl[x]+1]=r _b[tbl[x+1]+1]=g _b[tbl[x+2]+1]=b def fill(self, r,g,b): for x in range(28): self.set_pixel(x,r,g,b)
Test code for this was as follows,
from machine import Pin, I2C from ledshim import LEDSHIM from time import sleep import math 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 mc(h): hsv = hsv_to_rgb(h,1,0.5) r,g,b = hsv return (math.floor(r*255),math.floor(g*255),math.floor(b*255)) i2c=I2C(1,sda=Pin(2), scl=Pin(3)) display = LEDSHIM(i2c) display.fill(255,0,0) display.show() sleep(1) display.fill(0,255,0) display.show() sleep(1) display.fill(0,0,255) display.show() sleep(1) display.fill(0,0,0) display.show() sleep(1) # rainbow for i in range(28): r, g, b = mc(i/28) display.set_pixel(i, r, g, b) display.show() sleep(1) display.fill(0,0,0) display.show() sleep(1) # rainbow pattern leds = [i for i in range(28)] while True: for i in range(28): r, g, b = mc(i/28) display.set_pixel(leds[i], r, g, b) display.show() sleep(0.2) leds = leds[1:] + leds[:1]
I used a HSV to RGB conversion function and messed around rotating a list of the LEDs to make the rainbow pattern move around a little.