I have an issue with dropping bytes read from a serial port on a Mega while using the FastLED lib.
Here’s the hardware setup: About 1400 WS2811 LEDs in two strings, using the multiple array example.
The serial port issue: I’m sending 7 bytes to the serial port to get some sensor data to the Mega. It seems to drop 3 of the middle bytes fairly (but not perfectly) consistently. I’ve tried different baud rates, sending fewer updates per sec, all with similar data dropped.
To confirm I have good data on the Serial port, I wrote a sketch with nothing but the serial receiver in it, and it works flawlessly.
Something is just hammering the reads on the serial port data (as far as I can tell). Any ideas welcome.
If you are using ws2811/neopixel style LEDs FastLED has to disable interrupts while writing out led data, and there really isn’t any way around that.
Your options include:
- switching to 4 wire leds like dotstars/apa102 which doesn’t need interrupts disabled to write out data
- a platform like the teensy3.1 where some interrupt handling can happen while writing out led data
- change your data protocol to be an explicit request/response setup so you only ask for and read data while led data is not being written out.
Actually my code already works like that so I’m surprised it’s an issue. The
FastLED.show(); function must be a blocking function, no? I’m reading serial before I start updating the arrays - just a lot of writes to the array. So that should be OK with Serial, no?
OK - I see that the issue is when the data is SENT as the serial buffer is being updated in the background, and if the .show function starts with the buffer half read, bam, there goes the data. So I see how call and response can solve that, I’ll give it a try.
And while I’m writing, thanks for all your work on this fabulous library. It’s a stunning feat of technical accomplishment, and knowledge of low-level computer science. You’ve made lots of people happy with LED displays.