Improve Neopixel Peformance?

Posted on
  • I've got a 24 Led ring which I'm able to control successfully from Puck.js. The FPS, however, is a little 'meh'. I am using setInterval at an interval of 1 milli (just to see if that speeds it up any) and it looks like it's running around 20-25-ish FPS. Also, I don't have anything logging to the console (I noticed that slowed things down some).

    Is there any way to either increase the speed at which the pixels refresh over SPI or is there a better method than setInterval to provide a little more FPS to the leds?


  • Actually, just ran a test, the framerate is dropping to 12fps when the code is executed - otherwise it runs at 33fps.

    //hacks to get TWEEN to work
    var window = {};
    window.setTimeout = setTimeout;
    var TWEEN = require("Tween");
    var neopixel = require("neopixel");
    //hacks to get TWEEN to work
    process.hrtime = null; =;
    var lastLoop = new Date();
    function animate(time) {
        var thisLoop = new Date();
        var fps = 1000 / (thisLoop - lastLoop);
        lastLoop = thisLoop;
    setInterval(animate, 1);
    function run() {
      var leds = 24;
      var arr = new Uint8ClampedArray(leds*3);
      var n = 0;
      var coords = { x: 0, y: 0 }; // Start at (0, 0)
      var tween = new TWEEN.Tween(coords)
          .to({ x: 255, y: 2000 }, 1000)
          .onUpdate(function() {
            var r = Math.round(coords.x);
            n = 0;
            for(var a = 0 ; a < arr.length ; a++) {
               arr[n++] = (Math.random() * 255) * 0.25; 
            neopixel.write(D30, arr);
  • Looks to me line 19 there is still a console.log.

    Why don't you push the frame rates into an array and dump that at the end or in a timeout that happens say once a minute?

  • Logging in Puck.js (when you're connected via Bluetooth) really slows things down (25ish FPS sounds about right) - so that would definitely be something to avoid doing often. When you're not connected it should be ok, but then there's not much point having them :)

    Neopixel writes should be pretty much as fast as they can get, however the actual JS code execution speed isn't huge, so that alone could be slowing things down for you.

    If you want to log speed I'd do:

    var frames = 0;
    var arr = new Uint8ClampedArray(leds*3);
    function animate() {
      neopixel.write(D30, arr);
    setInterval(animate, 1);
    setInterval(function() {
    }, 1000);

    So then you're only doing a print every second, which shouldn't affect the speed.

  • Sounds interesting - any references I could take a look at to wrap my head around this concept?

  • This is a problem with espruino for animations...

    Remember the pingpong light project? (Which worked - there are 8 strings around my room of 10 lights each.) On esp8266's running espruino.

    Why only 10 per string? Js execution speed on the esp8266 controllers. Not that the esp8266 is the fastest microcontroller in town, of course

  • any references I could take a look at to wrap my head around this concept?

    In the code above? Rather than printing for every frame, you just increment a counter. Then every second you print the value of that counter. If 30 frames were rendered in that second then it should print 30.

    If you're asking about the JS execution speed then might help though

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Improve Neopixel Peformance?

Posted by Avatar for user90787 @user90787