WS2812B LED strip and ESP8266 shows wrong colors

Posted on
  • Hi! I finally got Espruino running on my ESP8266 12-E NodeMCU, but I'm having some issues talking to my strip correctly. When I was controlling my strip using Arduino and C before, I hooked up the data pin to RX, which worked just fine. Now I'm (apparently) supposed to hook it up to D2, or any of the pins near it, but the colors are all wrong.

    When I do something like:

    require("neopixel").write(NodeMCU.D2, [255, 0, 0]);
    

    The first LED shines 70% yellow 30% green, if I do [0, 255, 0] it's 90% white 10% purple, and if I do [0, 0, 255] it's 80% white 20% blue (something like that).

    It's not red, green, or blue as it's supposed to be. Any clue why?

    Oh, and I also tried this:

    require("ESP8266").neopixelWrite(NodeMCU­.D2, [255,0,0]);
    

    but that yields the same result.


    EDIT: I found this code in another post, which actually works fine:

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

    BUT! If I simply comment out the setInterval() and just write colorLeds(255, 0, 0) they all shine with a purple hue. What on earth???

  • Turns out I have to run the code twice. The first time I run it, it doesn't make the colors just right, but the second time I run it, the colors are fine.

    Oh well.

  • Ahh, thanks for letting us know! More than likely it's the state of the pin at boot that is the issue. Probably just calling esp8266.neopixelWrite(NodeMCU.D2, [0,0,0]); at startup would be enough.

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

WS2812B LED strip and ESP8266 shows wrong colors

Posted by Avatar for MortenMoulder @MortenMoulder

Actions