Arduino Neopixel library and millis() warning

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mkarlsson
 
Posts: 1
Joined: Fri Aug 16, 2013 1:14 pm

Arduino Neopixel library and millis() warning

Post by mkarlsson »

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).

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Neopixel library and millis() warning

Post by adafruit_support_bill »

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.

User avatar
Ori_Ben_Shabat
 
Posts: 1
Joined: Sat Aug 30, 2014 12:16 pm

Re: Arduino Neopixel library and millis() warning

Post by Ori_Ben_Shabat »

Hey,

It's true ;) I've used 72 pixels and it feels kind of 20% slower.
Neo Pixels Are still cool though ^_-

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”