serialport / node-serialport

Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
https://serialport.io
MIT License
5.81k stars 1.01k forks source link

Buffer/baud rate limitations? #1689

Closed Tmp2k closed 5 years ago

Tmp2k commented 6 years ago

I'm trying to write an RGB LED matrix controller to run in Node v8.12 on a RasPi using UART on the GPIO pins to talk to an Arduino and I keep experiencing "strangeness".

To keep things simple, I'm using the Glediator protocol. I can run Glediator on the RasPi and everything works fine. It's set to 1000000 baud and it's currently controlling 253 RGB LEDs. With the addition of the "start of frame" byte, this is 760 bytes. In future, I hope to control 1,000 LEDs.

Gladiator runs in Java and works perfectly, however, I can't get anything in Node to work. As soon as I start sending multiple frames, the data seems to randomly corrupt. If I reduce the number of LEDs to around 50, it appears to run smoothly. And when it does corrupt the corruption only seems to occur after the first 50 LEDs' worth of data. I've tried sending just 26 LEDs at a time (1 row) and flushing the buffer but it still corrupts at the same point?

I'm using the raspi-serial wrapper package for simplicity.

I've tried lots of different ways of sending the data using node but I'm wondering if anyone could help with some experience. The hardware and OS are not the issue as the Java based Glediator works fine. So it must be my code, this package or the Node stack that's at fault.

Does anyone know of any buffer,baud,bandwidth or latency limitations with Node or this package?

Can anyone suggest how to stream a 760 byte buffer, repeatedly, as fast as possible but executing some user-code to modify the buffer between each transmission.

Thanks!

HipsterBrown commented 6 years ago

@TmpR Can you post information about the OS on the Pi and Node.js version you're using? Some example code can also help with debugging.

Is this the matrix controller you're using? http://www.solderlab.de/index.php/hardware/matrix-controller-board

There is a relevant note in the node-pixel package about running multiple strips -> https://www.npmjs.com/package/node-pixel#a-note-on-multiple-strips

Tmp2k commented 6 years ago

The OS is the latest Rasbian installed via NOOBS. Node v8.12.

The controller is an Arduino Pro Mini, but will be replacing with a Mega (more memory). The firmware on it is about 3 lines of code, that reads the byte stream and uses FastLED to control the WS2812b/NeoPixel LEDs. This works with the Glediator software.

There are limits with the number of pixels, mainly memory on the Arduino, but according to Glediator you can run up to 1024 pixels on an Arduino Mega. They recommend 1000000 baud for 1024 pixels, so I'm starting with this baud so it's one less thing to change when I scale up from 253 to 1012 pixels.

1012 pixels @ 25fps = about 600kbps so about 60% utilisation of 1000000 baud if my understanding is correct.

HipsterBrown commented 6 years ago

The controller is an Arduino Pro Mini, but will be replacing with a Mega (more memory)

Then you could probably use node-pixel via the backpack setup -> https://github.com/ajfisher/node-pixel/blob/HEAD/docs/installation.md#i2c-backpack

reconbot commented 6 years ago

You'll hit a CPU limit with nodejs and that will speak to available bandwidth. It's not impossible you're hitting that, but you should test and let us know. Performance hasn't been a goal of this package in the past it's not bad.

raspi-serial uses serialport ^6.2.0, 6.2.1 fixed a memory leak

Get some stats and we can help debug. Code also helps.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week no further activity occurs. Feel free continue the discussion or ask for a never-stale label to keep it open. If this is a support issue, consider sharing it on stack overflow to get more eyes on your problem.