Really simple Christmas tree lights

I bought a string of fairy lights back in September last year and I’ve finally gotten around to setting them up.

  1. Fairy Lights - Addressable RGB (5m) | Sparkfun PRT-16792 | Core Electronics Australia
  2. Raspberry Pi Pico (Without Headers) | Core Electronics Australia or Raspberry Pi Pico W (Wireless WiFi) | Core Electronics Australia
  3. 3 Jumper wires
  4. Micro USB cable
  5. USB Battery pack

One gotcha I got stuck on: there’s a yellow label on one end telling you which pins are which, in the version I’ve got that’s on the end with the data out pin, so use the other end. Also the other end didn’t have the red marked wire for the power is actually marked blue (see discussion 2)

Wire it up like this:

The fairy lights are neo pixel compatible so that’s the library I used.

The idea for the color changing is to divide a circle (360°) into 3 overlapping sections of 240°, one for each color of the RGB pixels, that way each 1/3rd of the circle has 2 colors active, as one increases the other decreases:

The code is

import neopixel  # Import the neopixel module for controlling the LEDs
from machine import Pin  # Import the Pin module for GPIO control

ws_pin = 0  # GPIO pin connected to the data line 
led_num = 100  # Number of LEDs in the string
np = neopixel.NeoPixel(Pin(ws_pin), led_num)

# turn the degrees into a value
def value(deg):
    deg_mod = deg % 360 # modulo 360 to limit the range
    if deg_mod < 120 : return deg_mod # less than 120, just the value (value increases)
    if deg_mod < 240 : return 240 - deg_mod # less than 240, subtract from 240 (value decreases)
    return 0 # in the off part of the cycle

np.fill((0,0,0))	# Turn everything off
np.write()			# update
while True:
    for i in range(0,360,4): # go 360 in steps of 4
            # move the previous colors up a pixel
            for pix in range(led_num - 1,0,-1): 
                np[pix] = np[pix-1] # set this value to the previous
            color = (value(i), value(i + 120), value(i + 240)) # red - not offset, green offset by 120, bluse offset by 240
            np[0] = color
            np.write() # update
            # if you want a slower cycle add a sleep here
    np[0] = (0,0,0)	# add a flicker because my wife liked it :)

Save that as on your pico and it’ll run automatically when it’s powered up.

The flicker “it’s not a bug it’s a feature” I did have a flicker causing bug at one point, but when I took it out my wife said she liked it. Another option would be to add a blank pixel randomly, or not, it’s only 20ish lines of code. I looked at some samples but they calculated the color of each pixel based on i + the pixel number, but this is (I think) simpler and clearer.

The end result:

Enhancements: I’ve considered adding a web UI on the pico-w and switching between various patterns and/or adding parameters, but I think this is certainly good enough for now.


Hi Doug,

How festive! This is such a cute maker spin on the normal led lights that go around the Christmas tree!
That graph put the colourWheel functions that you commonly see in Neopixel libraries into perspective - thanks!