Driving WS2811, WS2812 and other NeoPixel devices from ESP8266

Posted on
Page
of 4
First Prev
/ 4
  • Hmm, not sure what's up. When I use my full program it does work. See for comparison.
    https://gist.github.com/creationix/a7f16­1ffc53d6b6921bde387b830785c

  • Looks to me like your full program uses a UInt8Array and your short test doesn't...

  • @creationix your code is working on my ESP8266 with 1v85.tve_master_cee7141

    can you try a different pin ?

  • Has anyone gotten the NeoPixels function working recently. When I try and run it, the first neopixelWrite() works but ones after that seem to be ignored. This is the sample I am using:

    var esp8266 = require("ESP8266");
    pinMode(D2, "output");
    function colorLeds(red, green, blue) {
      var data = [];
      for (var i=0; i<2; i++) {
        data.push(green);
        data.push(red);
        data.push(blue);
      }
      esp8266.neopixelWrite(NodeMCU.D2, data);
    }
    
    setInterval(function() {
      console.log("Changing ...");
      colorLeds(Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), Math.floor(Math.random() * 256));
    }, 1000);
    
  • I have the neopixelWrite working (most of the time)
    Tests, about 2 weeks ago, ran with a 8 by 8 matrix, which is refreshed each 50 msecs with changing data. Handover of data works with an Uint8Array created by an Espruino Extension.
    "Most of the time" because sometimes I see a flash with wrong colors. But next refresh everything is fine again.
    Its tested with ESP8266-01 using D2.
    AFAIK, D2 is used for logging as serial1. This is recognized by WS2812 after reset mostly. First LED is green, at least in my environment.

  • I still can't get the latest builds to run my ws2812b Neopixels ... so I got out my signal viewer which is super high resolution and started looking at the signals. In my tests, I have just one Neopixel connected (again ... just for testing) and every second, change its color from red to green. This should be the byte sequence 0xff 0x00 0x00 (red) and then a second later 0x00 0xff 0x00 (green). The way that bits are sent to a Neopixel is that a "1" bit is high for longer than a "0" bit. This page gives a good reference ...

    https://cpldcpu.wordpress.com/2014/01/14­/light_ws2812-library-v2-0-part-i-unders­tanding-the-ws2812/

    The summary is that a "1" bit should be high for >= 625ns and a "0" bit should be high for less than 563ns.

    My logic trace shows that we are all over the place. See the attached diagrams:

    What I am seeing is that the "relative" durations of highs vs lows is working but the absolute values are out of whack.

    @JumJum ... I'm really interested to hear what you have and have not got working. What kind of NeoPixels are you using? Do you known if they are WS2812s or WS2812b's or something else?


    1 Attachment

    • 2016-09-17_22-42-58.jpg
  • @kolban, take a look to this
    I did not test with 1V87 yet, and due to vacation, it will take some time.

  • In an attempt to provide more information, I created a 70 second you tube video ... see here:

    https://www.youtube.com/watch?v=z8TJu-3P­xqA

    The Script I am using is as follows:

    E.setClock(80);
    var i = 0;
    var esp8266 = require("ESP8266");
    console.log(esp8266.getState());
    pinMode(D4, "output");
    function colorLeds(red, green, blue) {
      var data = [];
      for (var i=0; i<20; i++) {
        data.push(green);
        data.push(red);
        data.push(blue);
      }
      esp8266.neopixelWrite(NodeMCU.D4, data);
    }
    
    setInterval(function() {
      console.log("Changing ...!");
      i++;
      if ((i % 3) === 0) {
          colorLeds(255,0,0);
      } else if ((i%3) === 1) {
          colorLeds(0,255,0);
      } else {
          colorLeds(0,0, 255);
      }
    }, 1000);
    

    which alternates a string of 20 pixels between red, green and blue once a second. The Espruino build is the downloadable binaries for 1v87. The ESP8266 is a NodeMCU DevKit module.

    When I started capturing the video, all was working as expected. At about the 20 second mark, we can start to see the weirdness creep in ... this goes on until about 1:00 and then we seem to "resynch". There doesn't appear to be any patterns ... it can start generating ambiguity immediately or can be "correct" immediately ... the duration between weirdness and correctness also appears to be non deterministic. I have tried a variety of different pixels, power sources, pixel strings and pixel types.

    I'm very much open to the notion that I am doing something wrong in my setup ... but I'm hoping to hear experiences from other NeoPixel users ... how "stable" are your outputs? What are your configurations? etc etc.

  • I'm running the following code on a string of 8 neopixels. It walks a rainbow of colors. Not seeing any oddity.

    var array = [255,255,255, 255,0,0, 0,255,0, 0,0,255, 127,127,127, 0,255,255, 255,0,255, 255,255,0];
    function walk() {
      esp.neopixelWrite(D5,array);
      array.push(array.shift());
      array.push(array.shift());
      array.push(array.shift());
    }
    
    var esp = require("ESP8266");
    pinMode(D5,'output');
    
    setInterval(walk, 500);
    
  • I spent the bulk of the day trouble shooting my issue and think I found it ... here is the story and the then the conclusion. With so many variables in my story, I wasn't sure where to start. Was it timing with Espruino, interrupts in ESP8266, bad pixel strips, bad power, bad comprehension on my part .... so many possibilities.

    What I did was broke out an Arduino and used it to drive my NeoPixel strip through an Arduino sketch which was an implementation of my JavaScript sketch but this time in C. It worked fine and all the pixels lit properly. I watched it for a long period of time. My confidence in the NeoPixel strip was now high. I captured a low level timing through a logic analyzer and saved the results. Then I went back to the ESP8266 and Espruino using the same strip. Again, same issues as before. I captured the input timings into the NeoPixels and generated by Espruino/ESP8266 and compared them against my "reference set" which I took from the Arduino. Although not identical, they were within tolerance of what I have been reading from NeoPixel theory.

    Next I had an idea ... the output of one NeoPixel feeds into the input of the next. Now I decided to capture signals from the input to the first NeoPixel to the output of the next ... and ... Aha!! We got something. When the pixels started not showing correctly, I saw that the input to the first NeoPixel looked "good" but the output from the first NeoPixel was poor ... i.e. a lot of missing high signals on the DOUT line. What this was telling me was that the first NeoPixel was not forwarding its correct sequence of pulses.

    Now we get to cut to the chase ... I knew that powering a NeoPixel strand from the 5V output of ESP8266 wasn't going to fly so I was using an MB-102 as a power source for the NeoPixel strand. I was delivering 5V from the MB-102s to the NeoPixels with a common ground to the ESP8266 (NodeMCU dev kit). This had been my test environment. Knowing that the Arduino was a working test environment, I took the MB-102 out of the story and powered my NeoPixels from the 5V/GND of the Arduino ... i.e. I am using the Arduino ONLY as a source of power to the NeoPixels. I obviously continue to have a common ground ....

    and the result ... perfection. I have been running the strand for about 10 minutes now with it right in front of me and not a single glitch. What this is telling me is that power output of the MB-102 is not sufficient/clean enough to power the NeoPixel strand. I don't have nearly enough skills in electrical or electronics to know why ... tomorrow I'm going to start studying up on MB-102s ... and also see what I have in my box of bits for a power source that is neither MB-102 nor an Arduino ... but what I have now is an ESP8266 running Espruino driving a NeoPixel strand in exactly the fashion I had hoped for and that others had said they had achieved. I'd be really interested to hear from you what you are using to power your NeoPixels/ws2812s?

  • I'm glad you got it sorted out :-)

  • A single NeoPixel can 'eat up' up to 60mA, when full white light... (20mA per color...). When the load of all NeoPixel pulls, the power source may tank just enough so that the hardware logic in the NeoPixel just has not enough juice anymore to pass on a clean signal... Therefore, making sure that you source enough juice makes your day... your power consumption with full brightness - with 20 pixels - is between 400mA - 1 color, R xor G xor B - and 1200mA - all colors, R and G and B, white. With only one color on, you may run of a standard USB power - 500mA...

  • Just to add that NeoPixels are also a bit picky on voltages for the data signal.

    Basically if you power them from 5v and then give them 3.3v data the result can be a bit glitchy. As a result, for Espruino boards I usually recommend putting the the pin into pulldown mode and pulling it up to 5v with a resistor (to get a 5v data signal).

    ... or generally if you run them from 4.3v (5v with a diode's voltage drop) then 3.3v data is good enough.

  • Bump...
    Was there any solution on driving a WS2812 device with an esp8266 running espruino?

  • I know at various times, there has been a way to drive WS281x's from ESP8266 on Espruino, I think via a specific hackjob... Yah, here:

    http://www.espruino.com/Reference#l_ESP8­266_neopixelWrite

    But - you will probably need to level shift the signal up to 5v.

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

Driving WS2811, WS2812 and other NeoPixel devices from ESP8266

Posted by Avatar for Kolban @Kolban

Actions