ESP8266 and WS2812(B)

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
kvaruni
Posts: 2
Joined: Sun Jun 12, 2016 2:08 pm

ESP8266 and WS2812(B)

Post by kvaruni » Sun Jun 12, 2016 2:21 pm

I'm a bit late to the party, being one of the backers on the ESP8266 Kickstarter but only now having some time to start toying with it.

What I am *trying* to do is to wire up my ESP8266 (running 1.8.1 from latest Kickstarter email) to use it with my WS2812B strip. I had this strip wired up to an Espruino before, but would now like to use it with the ESP to conveniently access it over Wi-Fi. First things first, I used a simple LED to figure out which port is which on my board (a NodeMCU ESP12-E). Pin 5 maps to the D1 pin, so there we go. I plugged the ESP into a breadboard, gave the WS2812 its own 5v supply and plugged the data pin into D1 (aka pin 5). All fine, but now the messy stuff begins.

(1) I would like the ESP8266 board to connect to my Wi-Fi, rather than present itself as a Wi-Fi network. I probably overlooked it in the manual, but how can you do that?

(2) I tried to use the WS2812, but I'm not having the best of luck. When creating an SPI with baudrate=3200000, phase=1, mosi=Pin(5), I don't seem to be able to control the strip (this setup is known to work on the Espruino, and I assume SPI.MASTER is set as MASTER is unknown in SPI). I also tried sck=Pin(5), but I get fairly similar results. Now, I know the WS2812 need a reasonably well formatted value to work, so maybe something is already going awry there. Maybe the baudrate is wrong, where I tried 6400000 and 8000000 as well to no avail. Sometimes, very rarely, I seem to be influencing the first LED. But it could really just be a fluke or something I can't really reproduce. Any help there?

profra
Posts: 39
Joined: Sat Jan 03, 2015 12:23 am

Re: ESP8266 and WS2812(B)

Post by profra » Sun Jun 12, 2016 4:50 pm

@kvaruni Espruino Pico is another story...see: http://micropython.org/resources/docs/e ... xel-driver

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP8266 and WS2812(B)

Post by Roberthh » Sun Jun 12, 2016 4:53 pm

For question (1), see http://docs.micropython.org/en/latest/e ... ckref.html, section Network.

kvaruni
Posts: 2
Joined: Sun Jun 12, 2016 2:08 pm

Re: ESP8266 and WS2812(B)

Post by kvaruni » Sun Jun 12, 2016 5:25 pm

Thanks for the answer on (1), I knew I was overlooking it somehow.

@profra: do you mean that I can drive the WS2812 as NeoPixels? Would make some sense. I gave it a go, but results seem to be similar. Sporadically it works (haphazardly I can sometimes turn the first LED to red), but it doesn't seem to work consistently at all. I can't really make much sense of the low-level driving based on the one-liner and the lack of further documentation on the esp library. In particular, I have no idea what the format should be for grb_buf (object with buffer protocol?) and is800khz is not recognised (simply a Boolean? integer?). Regardless, thanks for the suggestion, one step forward ;) .

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: ESP8266 and WS2812(B)

Post by deshipu » Mon Jun 13, 2016 8:08 am

kvaruni wrote: (2) I tried to use the WS2812, but I'm not having the best of luck. When creating an SPI with baudrate=3200000, phase=1, mosi=Pin(5), I don't seem to be able to control the strip (this setup is known to work on the Espruino, and I assume SPI.MASTER is set as MASTER is unknown in SPI). I also tried sck=Pin(5), but I get fairly similar results. Now, I know the WS2812 need a reasonably well formatted value to work, so maybe something is already going awry there. Maybe the baudrate is wrong, where I tried 6400000 and 8000000 as well to no avail. Sometimes, very rarely, I seem to be influencing the first LED. But it could really just be a fluke or something I can't really reproduce. Any help there?
The current SPI on Micropython for ESP8266 is a very slow software implementation. Even if you pass it large baud rates, such as 6400000 or 800000 it won't actually get to that speed, simply because the software has a lot of other things to do in the mean time (like keeping the WiFi working). Since WS2812's protocol relies on timing of the signals, this won't work.

You can use the "neopixel" module to drive short strips of LEDs: http://micropython.org/resources/docs/e ... xel-driver however this is also software-based and will become unreliable as the number of LEDs and refresh rate grow.

Funnily enough, ESP8266 has hardware SPI, but it's not used by Micropython. I wrote a module that exposes it to the python code, but it's not merged yet. You can try to compile and try it, I'd appreciate any testing that can be done, as it would speed up merging: http://forum.micropython.org/viewtopic.php?f=16&t=2000

rudydevolder
Posts: 3
Joined: Mon May 05, 2014 9:11 am

Re: ESP8266 and WS2812(B)

Post by rudydevolder » Thu Jun 23, 2016 6:50 pm

Hi, I am certainly interested in testing the hw version of the SPI bus because I also have problems with the WS2801 leds I am testing. Some of the Leds display every few seconds a totally wrong color on whatever speed of the SPI bus, but when I double the working frequency of the Esp8266 to 160mhz the problem seems almost gone. And it seems always the same leds changing in the same wrong color.
Clearly a bug in the software SPI because on 160 MHz the problem almost disappeared.
So I will surely test your solution but the coming month I am outside the country.

Post Reply