0

Neopixels and PMW RGB leds in same sketch
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Neopixels and PMW RGB leds in same sketch

by Ritchiemac on Sun Jun 06, 2021 8:48 pm

I'm trying to marry 2 sketches and I'm running into problems. Both sketches work well independently and compile and upload successfully when combined, but the neopixel library dominates the pins. The pins assigned for the sinewave PWM modulations cease to function correctly. I'm using a Mega board. I've tried using the analog pins for the PWM functions but they run very rough and clunky.

I see that there was a library fix for servo motors and neopixels operating together. Any ideas?

Ritchiemac
 
Posts: 1
Joined: Sun Jun 06, 2021 8:25 pm

Re: Neopixels and PMW RGB leds in same sketch

by blnkjns on Mon Jun 07, 2021 12:51 am

It is wise to look into the MEGA technical information to see how the timers behave. PWM and NeoPixels both depend on timers, and PWM is often done on 2 pins with a single timer. So if you know the PWM pairs, just try the other pairs and see what happens.

blnkjns
 
Posts: 663
Joined: Fri Oct 02, 2020 3:33 am

Re: Neopixels and PMW RGB leds in same sketch

by adafruit_support_mike on Mon Jun 07, 2021 4:15 am

NeoPixel updates are timing-critical.. the difference between a 1 and a 0 is about 150 nanoseconds, and a gap of 50 microseconds tells the the strip that the current update is done. Because of that, the NeoPixel library disables interrupts during an update.

That includes the timer-based interrupts that generate PWM output.

You'll have to interleave the two operations in your code, so the RGB LEDs only update between NeoPixel updates.

For that, you'll need to use code that approximates a real-time operating system. Bill wrote a good series of tutorials on how to do that here:

https://learn.adafruit.com/multi-taskin ... ino-part-1
https://learn.adafruit.com/multi-taskin ... ino-part-2
https://learn.adafruit.com/multi-taskin ... ino-part-3

adafruit_support_mike
 
Posts: 63074
Joined: Thu Feb 11, 2010 2:51 pm

Re: Neopixels and PMW RGB leds in same sketch

by Richmac on Tue Jun 08, 2021 1:38 am

Thanks Mike and Binkjns,
So it's a timing thing. I'll check out Bill's references and see if I can produce a fix. I appreciate the guidance.
Thanks Again

Richmac
 
Posts: 1
Joined: Tue Jun 08, 2021 1:22 am

Please be positive and constructive with your questions and comments.