ws2811 hue very slow

Posted on
  • Hello.
    I'm using example code to ws2811, and it's very slow. This example
    He're is a video https://youtu.be/nvfhA3Y54ss

    It's working ok when using <10 LEDs, but when I try to use more (I have 97 of them) it's very slow as in video. I've tried using Arduino for it and it worked perfectly. Same was for MicroPython. Is there some kind of setting I'm missing? I've even tried running only "for" loop that was counting to 10 000, and It took like 2 or 3 seconds. I've tried this same in MicroPython and it worked instantly.

  • You used this code?

    var arr = new Uint8ClampedArray(100*3);
    var pos = 0;
    function getPattern() {
      pos++;
      for (var i=0;i<arr.length;i+=3)
        arr.set(E.HSBtoRGB((i+pos)*0.01,1,1,1),i­);
    }
    

    Espruino isn't as fast as something like MicroPython by an order of magnitude - it's just a side-effect of it trying to be very efficient with memory (which admittedly is less of an issue on ESP32). The ESP32 port also hasn't had any real speed optimisation done at all either.

    However for 100 LEDs I'm extremely surprised that it's that slow - even one of the 64MHz ARM Espruino boards should be doing significantly better than that.

  • This code is a little bit smoother I think, but it's about this same speed. I think looping through all objects in array is so slow, because I've commented out all other things, and it's still slow. I'm not even using neopixel library with this.

    function getPattern() {
      pos++;
      for (var i=0;i<arr.length;i+=3);
      console.log('a');
        //arr.set(E.HSBtoRGB((i+pos)*0.01,1,1,1)­,i);
    }
    
    

    I've done this

    arr.set(E.HSBtoRGB((0+pos)*0.01,1,1,1),0­);
    arr.set(E.HSBtoRGB((3+pos)*0.01,1,1,1),3­);
    arr.set(E.HSBtoRGB((6+pos)*0.01,1,1,1),6­);
    arr.set(E.HSBtoRGB((9+pos)*0.01,1,1,1),9­);
    [...] 97 times
    

    And it's still slow.

  • Fri 2019.04.12

    In my tests, sending to the Web IDE using console.log('a'); will add ~100msec each iteration, bogging down the sequencing. Have you tried without those lines? Don't forget the commented lines as those also are being parsed, adding unnecessary delay.

  • @sebafudi, since you just shift the pattern through the string, did you consider to just chop off the the falling off tuple(s) and calculate and append only the new ones?

  • @sebafudi, have you tried the examples at:

    http://www.espruino.com/Individually+Add­ressable+LEDs

    to gain additional insight?


    @allObjects, Isn't what you are describing, the example that Gordon has outlined in #2 above?

    http://www.espruino.com/WS2811

    I think sebafudi hard coded each line with the offset just to test compare.

  • @Robin, I don't think so because it is calculating the values for each array element every time, even though it would need only to shift and only to calculate for the few new ones when also considering the modulus in the color sequence generation formula.

  • @Robin I wasn't using console.log in main code, and it was slow, so I don't think that's it.

    console.log('a');
    

    was just for test.

    @allObjects
    This code was just to test espruino and esp32 with my LEDs. In final code, LED pattern will be streamed from outside through web, so shifting entire array will be useless.

  • Sun 2019.04.14

    @sebafudi if you are still experiencing a delay as shown in the video, then I suggest we start with the basics.

    Please post the results of process.env

    Please post the entire code block as it is right now, as it appears some edits have been made to the tutorial examples.

    What was the run time result of coding the example @Gordon provided in #2 above?

    Does the second full example at:

    https://www.espruino.com/WS2811

    (with embedded Math.sin() and onTimer() function) sequence rapidly?

    re: 'I've tried using Arduino for it and it worked perfectly.'

    Would you please post a video of that which 'worked perfectly' and the corresponding Arduino source code, so that we may see what visual effect that is desired?

  • sending to the Web IDE using console.log('a'); will add ~100msec each iteration,

    This definitely isn't the case by the way - if you don't fill the output buffer then it's pretty fast. Obviously if you fill the buffer then you're limited by the time it takes to send that data over USB/Bluetooth/Serial/etc.

    Also, which firmware version are you using? If it's a firmware build that has been done without the RELEASE flag set then it'll have asserts all over it and will be an order of magnitude slower.

    Just to add some actual stats to this:

    var arr = new Uint8ClampedArray(100*3);
    var pos = 0;
    function getPattern() {
      pos++;
      for (var i=0;i<arr.length;i+=3)
        arr.set(E.HSBtoRGB((i+pos)*0.01,1,1,1),i­);
    }
    t=getTime();getPattern();print(getTime()­-t)
    // prints 0.12677001953 on an MDBT42Q
    // prints 0.08190917968 on an Espruino WiFi
    

    So official Espruino boards would appear to be 'fast enough', if not as fast as Arduino/Micropython.

  • My experience was that the ESP8266 (the one I do a lot of LED control with) was that this was very slow indeed. That's why I have only 10 pingpong lights on each of my strings....

    I would very much like to see some speed optimizations for the ESP8266 and ESP32 boards - they are... painfully slow.

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

ws2811 hue very slow

Posted by Avatar for sebafudi @sebafudi

Actions