Anybody know an efficient way to read data off of SerialUSB and blast it

Anybody know an efficient way to read data off of SerialUSB and blast it out to WS2812s using an Arduino Due/FastLED?

If I send serial data to it while it’s running fastLED.show() I get strange artifacts (only the first section of strand gets data). I suspects interrupts are messing up the WS2812 timing, but the arduino stdlib is such a bowl of spaghetti that I was unable to actually figure out how SerialUSB.readBytes() is implemented, so I could be totally wrong.

My reading of the SAM3X features, it should be possible to do the receives via DMA and not mess up program execution while the host computer is sending data (atmel advertises it as kicking ass at bus translation, and 900kb/sec isn’t exactly that), but setting up all the USB and DMA control registers to do the right thing is… not an adventure I want to embark upon until I’ve made absolutely sure nobody else has done it before and that doing so will actually solve my problem.

Currently I’ve got it working by using software flow control (the 'duino sends a byte back to the host PC when it’s done with show(), then the host PC waits for that before sending a frame of data), but I want it faster, and in theory that should be possible.

Code: https://github.com/sazamore/SynapticAquarium/blob/master/serial_controller/serial_controller.ino

If I move the SerialUSB.write() at the end to before the FastLED.show(), I get much better framerates (my PC measures like 3.3MB/sec throughput), but artifacts. As is, it runs really slow, but works (like 800kB/sec)

Could you tell us more on how you are measure the bandwidth. Became in the source code you provided the serial port is initialised at 9600 baud witch is equal to 1,17kB/s including the stop bit!

900 kbits/sec is very similar to the benchmark I measured with Arduino Due a couple years ago.
http://www.pjrc.com/teensy/benchmark_usb_serial_receive.html

FWIW, you’re absolutely right, Due’s USB receive speed in theory should be incredibly fast, since the USB is running at 480 Mbit/sec. In practice, software design and optimization matters greatly!

I did some experimentation and it appears that baud rate I pass to serialUSB.begin doesn’t make any difference at all (I had an echo program and ran it with both sides opening the port at various bauds and they had no effect on throughput whatsoever, I suspect because it’s USB and there’s no actual UART).

The rate is measured by the host application, check out run.py in the same repo if you’re really curious. It also includes some simulation time and other crap that makes it pretty inaccurate (it’s actually the bandwidth of the whole program, not just the arduino), but the system is bottlenecked by serial.write() on the python side, which takes >90% of the wallclock runtime with my flow control, and ~70% without. I don’t think the actual data rates are important, they’re definitely way too slow.

Also worth noting is that when I run it the fast way, it does actually receive all the data correctly, the checksums all match up, it just doesn’t display right