Neopixels occasionally flickering white

Hi Liam,

To be honest, I haven’t had a chance to try just yet. I found the above link and thought to give that a try first as it’s a software change and has minimum impact on my set up. Can you elaborate more on what exactly you mean by PIO code and why I shouldn’t need to overclock?

EDIT: Seems like I only need to go up as high as 130000000 to fix the issue.

1 Like

Hi James,

The Pico by default will be running at 133MHz, which is just above the frequency listed above.
Would it be possible to send through the code that you used? Someone from the forum will be able to pick the part (in software) that might be causing issues)

1 Like

Hi Liam, here’s the guts of it. Note that it uses ulab (aka numpy) but that’s really just handy to convert my colours to bytes. The main workhorse is the machine.bitstream calls which was taken from the guts of several neopixel libraries.

import machine

from ulab import numpy as np


NEOPIXEL_TIMING = (400, 850, 800, 450)
NUM_PIXLES = 54


pin_18 = machine.Pin(18)
pin_18.init(pin_18.OUT)

pin_19 = machine.Pin(19)
pin_19.init(pin_19.OUT)

pin_21 = machine.Pin(21)
pin_21.init(pin_21.OUT)

pin_22 = machine.Pin(22)
pin_22.init(pin_22.OUT)


while True:

    colour = (255, 0, 0)

    array = np.array(colour * NUM_PIXLES)
    machine.bitstream(pin_18, 0, NEOPIXEL_TIMING, np.array(array, dtype=np.uint8).tobytes())

    array = np.array(colour * NUM_PIXLES)
    machine.bitstream(pin_19, 0, NEOPIXEL_TIMING, np.array(array, dtype=np.uint8).tobytes())

    array = np.array(colour * NUM_PIXLES)
    machine.bitstream(pin_21, 0, NEOPIXEL_TIMING, np.array(array, dtype=np.uint8).tobytes())

    array = np.array(colour * NUM_PIXLES)
    machine.bitstream(pin_22, 0, NEOPIXEL_TIMING, np.array(array, dtype=np.uint8).tobytes())

Apparently picos ship with the internal clock set to 125MHz, even though the chip is rated for 133. I’ve heard several different opinions on setting the clock speed to a value in this range - some say technically it’s not overclocking, some say that it is since the pico is more than just the RP2040, it’s still counted as overclocking.

1 Like

Hi James,

Thanks for posting your code!

I’d check out a dedicated library for driving Neopixels using the PIO.

You can use the GlowBit Libraries or the dedicated WS2812 Driver example.

Using one of the libraries above will abstract away the CPU in favour of a dedicated state machine which will keep the main CPU free

Using the GlowBit Libraries you code will change to something like this:

import glowbit

strip = glowbit.stick(brightness = 255, pin=18, sm=0, numLEDs = 54)
strip1 = glowbit.stick(brightness = 255, pin=19, sm=1)
strip2 = glowbit.stick(brightness = 255, pin=21, sm=2)
strip3 = glowbit.stick(brightness = 255, pin=22, sm=3)

strip .pixelsFill(strip .red())
strip .pixelsShow()
# ... for the rest of the LED strips

Let us know how you go!
Liam

1 Like

Thanks Liam, just having a look at these links now. If I understand correctly - you’re suggesting that using the PIO / state machine protocol should eliminate the problems from directly bit-banging the gpio pins?

1 Like

Hi James,

Yeah, I’ve run into that issue with poor timing/slow edges on other WS2812 projects.
Its all software so hopefully should be quicker to implement!

Liam

1 Like

Implemented via rp2 / glowbit libs and completely solved. Thanks heaps Liam, and thank you all for your time - works like a charm!

I suppose the gpio protocol I was using just wasn’t fast enough to keep up with the pixels?

3 Likes

Hi James,

Glad we got to the bottom of it and thanks for letting us know what solved it!

I’m not certain what the bitstream call is doing behind the scenes but definitely was related to something with timing.
If you’re keen to learn the machine class is open source and on GitHub!
Liam

2 Likes

Not to unearth this thread but there were further issues that came up from using neo pixels with Pio. From memory this link is what saved me should anyone else run into the same issue:

Tl;dr - most neopixel code includes the wrong timings, but the issues won’t show up for most builds. Clearly I crossed some sort of threshold and the timings were an issue for me.

2 Likes