I have been playing with the Neopixel library for Arduino and noticed that the show() method is turning off interrupts while updating the LED strip. The problem with turning off interrupts for extended time is that other interrupt-based functions will not execute while interrupts are turned off. Case in point is the millisecond counter which is incremented every millisecond based on a timer interrupt. If the interrupts are turned off for more than a millisecond then there is a chance for the system to miss a millisecond interrupt, and if turned off for more than two milliseconds it will definitely miss a millisecond interrupt. For a 800 kHz neopixel LED strip driven by a 16 MHz Arduino this means that if the strip is longer than 33 LEDs then it might loose a millisecond every time show() is called, and if it's longer than 66 LEDs then it will definitely loose a millisecond every time show() is called. The effect of this is that millis() will not reflect real time, it's running slow.
Turning off interrupts for extended time might also cause problems with serial communication (received characters while interrupts are disabled might get dropped).
Arduino Neopixel library and millis() warning
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mkarlsson
- Posts: 1
- Joined: Fri Aug 16, 2013 1:14 pm
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino Neopixel library and millis() warning
Thanks for the heads-up. Unfortunately, the neopixel protocol timing is not at all forgiving. Disabling interrupts for the duration is about the only way to do it reliably.
- Ori_Ben_Shabat
- Posts: 1
- Joined: Sat Aug 30, 2014 12:16 pm
Re: Arduino Neopixel library and millis() warning
Hey,
It's true ;) I've used 72 pixels and it feels kind of 20% slower.
Neo Pixels Are still cool though ^_-
It's true ;) I've used 72 pixels and it feels kind of 20% slower.
Neo Pixels Are still cool though ^_-
Please be positive and constructive with your questions and comments.