question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NeoPixel only working on GPIO18

See original GitHub issue

Hi, I’m developing an application using a Raspberry Pi CM4 in which I need to use a 12 led RGB WS2812B ring, and more specifically I have to create an animation where all of the 12 leds fade from minimum brightness to max and vice versa. I noticed that if I control the leds using GPIO18 it works fine, but if I try using a different pin, like GPIO10 or GPIO21, it has strange behaviours. For instance, all the leds become white and even if I send a different colour they keep staying white, or if I dimmer them from min to max, while the transition, different leds blink with different colours, completely at a random.

Here’s reported a snippet from the code I’m using.

import time
import board
import neopixel

pixel_pin = board.D21

num_pixels = 12

ORDER = neopixel.GRB

pixels = neopixel.NeoPixel(
    pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER
)

try:
    while True:
        for i in range(1, 255):
            pixels.fill((i, 0, 0))
            pixels.show()
            time.sleep(0.005)
        
        for i in range(254, 2, -1):
            pixels.fill((i, 0, 0))
            pixels.show()
            time.sleep(0.005)
        
except KeyboardInterrupt:
    print('Keyboard interrupt')
    pixels.fill(0)
    pixels.show()
    pixels.deinit()

As said before, during the transition I’m actually facing leds changing colours and blinking completely at a random. This happens only if I use a GPIO that is not GPIO18. If I use GPIO18 for controlling the led ring everything works fine. I even tested the same code with two different OS (Raspberry OS and Manjaro ARM) but I have more or less the same behaviour.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
makermelissacommented, Jul 30, 2021

Last I checked, the raspberry pi only has 2 channels of hardware controlled PWM; channel0 is connected to GPIO18 & GPIO19, and channel1 is connected to GPIO12 & GPIO13 - these channels might also be tied to the analog 3.5mm audio output connector.

I think this issue is more related to the hardware limitation rather than a software limitation. The pigpio lib is unique in that it boasts hardware timed PWM, but I’m not familiar enough with it’s source to definitively say why it would cause “strange behavior”. My guess is that pigpiod is trying to use a PWM channel while your app is also trying to use the same channel.

I think when I was looking into a similar issue a while back, this is the conclusion I came to as well. It’s not shareable and they’re essentially quantum entangled and modifying one modifies the other.

0reactions
makermelissacommented, Sep 10, 2021

Closing because this is really a hardware limitation and nothing to do here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GPIO18 PMW0 suddenly broken? - Raspberry Pi Forums
Hi, im currently working on an LED-Matrix Project using SK6812 LEDs. Surprisingly it all worked first try in my temporary setup :D
Read more >
NeoPixels on Raspberry Pi - Adafruit Learning System
Wiring NeoPixels to work with a Raspberry Pi is quite simple. The only issue to deal with is converting the Pi's GPIO from...
Read more >
Neopixel - no output, example? - General - Node-RED Forum
I am trying to get a neopixel cirkel running with node red. ... gpio 18 Can somebody help me with a working example...
Read more >
Raspberry Pi 3 WS2812B LED strip not working - Reddit
I've connected the strip to 5v 10A power supply, wired it to GPIO18, wired the ground of strip and Raspberry together. However, when...
Read more >
Using Neopixels with the Raspberry Pi | The Pi Hut
working neopixels. Note: The Raspberry Pi can only power a few Neopixels. For small projects like wearables this is fine.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found