Hi, I'm experiencing some timing issues that I'm pretty sure others have probably come

(Jason Kerestes) #1

Hi, I’m experiencing some timing issues that I’m pretty sure others have probably come across. I’m sure a work around could be created, but I’m hoping maybe someone has aready done something similar (on a haloween party deadline (Saturday evening)). I’m operating a small strip (7 leds WS2811) and two servos on an arduino. I didnt expect this problem or I would have probably gone with a multi core processor like the parallax propellor. Anyway I’m having the LED’s respond to music but the constant update of the LED is messing with my pwm signal generation to my servos. Any ideas? I can post the code if it would help

Thanks for your input and time

(Marc Miller) #2

Can you post the code to pastebin or gist? I would be interested in trying to understand what’s going on.

(Jason Kerestes) #3


(Jason Kerestes) #4

its not complete, but mostly done. From what I understand, the pwm generation is getting issues because of lost timing with the clock. I came across this page https://learn.adafruit.com/neopixels-and-servos/introducing-avr-peripherals but from a quick test i havent gotten that working yet with the fastLED library

(Jason Kerestes) #5

basically resulting in really bad servo shaking, removing the leds, but still running that portion of code - problem still exists , commenting out the fastled.show - servos are nice and smooth

(Dushyant Ahuja) #6

Ws2811 require interrupts to get the timing right for the LEDs and hence mess up the servos. I can think of two easy options -

  1. Use multiple arduinos - one for the LEDs and one for the servos with serial communication in between if required.
  2. Use APA102 or LPD8806 instead of Ws2811 - these LEDs have a separate clock line.
(Mark Kriegsman) #7

What folks are saying here is correct: use of any “three-wire” LED strips (eg WS2811/WS2812 Neopixels) on ATmega/ATtiny microcontrollers necessitates disabling interrupts, and that screws up all kinds of things, including PWM.

Solutions include:

  • switch to “four-wire” LEDs like APA102 or LPD8806, since they don’t require disabling interrupts
  • switch to a fast, robust ARM- based microcontroller like the Teensy3.x or the Arduino Due, on which FastLED has special handling of three-wire LEDs and interrupts, or
  • have two separate microcontrollers: one for driving LEDs and one for performing the other functions that require interrupts.

The amount of trouble and annoyance caused by the interaction of three-wire LEDs and interrupts cannot be overstated. As recently as this past Monday I was running into it (yet again) myself trying to do something as simple as reading characters from the serial port while animating LEDs. Depending on the timing, I was losing characters from the serial port because they were showing up while interrupts were disabled for the LEDs – and there’s no real work-around. (Aaaargh.)

(Jason Kerestes) #8

I was grudgingly tossing around the idea of the second arduino but have a minimal footprint available. This is for a pair of big angel wings for my wife with fiber optics connected to the leds. I hadn’t thought of the other types of LEDS with the built in clock. Thanks so much for all of your comments and time. Now hopefully I can get same day shipping from somewhere!

(Andrew Tuline) #9

Some Arduino’s such as the Nano have a very small footprint.

(Mark Kriegsman) #10

The DFRobot Beetle is tiny, easy to use, and under $10.

(Jason Kerestes) #11

Ya, unfortunately due to procrastination, I started this project on Monday with the deadline and expectation of finishing it by tomorrow. Time permitting, I would try the beetle or nano. Good excuse to pick one up for the next project though…

(Jason Kerestes) #12

I really appreciate everyone’s input. This is one of the nicer groups I’ve come across. Thank you!

(Philippe Charest) #13

Are you driving the servo pins from pwm pins… If so u it should not be an issue. Are u using the servo library I’d so drop it. Send me your code I’ll have a look at it.

(Philippe Charest) #14

Oops just saw your pastebin

(Philippe Charest) #15

Jason, the Arduino Servo Library uses the AVR timer1 (the millis timer) timer interrupts to generate the required PWM for the servo signal. Fastled will diasble this interup to genrate the timing signal for the leds. One way to fix your issue would be to not use the servo library at all and millis() function. Have a look at this site how to use Timer1 to generate PWM for servos without glitching with fastled.


(Jason Kerestes) #16

I’ll check it out now! Thanks so much! I had a pic16 laying around that
I’m setting up but this would be a bit better easier than soldering it all

(Jason Kerestes) #17

To those that offered suggestions, tips knowledge… Thanks! The wings turned out great. see a video of them here:

I ordered some arduino nanos but they didnt come in soon enough. I ended up reprinting the enclosure to make room for a second uno which I had on hand. Ultimately, I was in a bit of a time crunch but now that I have some more time I’ll work on getting everything to run on a single chip which will be good to learn.
Thanks again for your support!

(Mark Kriegsman) #18

They came out great! Everyone should check out the video!

(Philippe Charest) #19

Have we just been RickEdRoll

(Jason Kerestes) #20

haha, I had to, perfect excuse to play that song!