-
I tried the code from the official Espruino WS2812 example: http://www.espruino.com/WS2811 replacing the calls to SPI by esp.neopixelWrite(), but I get the error
>esp.neopixelWrite(pin, arr); Uncaught Error: Data must be an array. at line 1 col 27 esp.neopixelWrite(pin, arr); ^
It would be nice if neopixelWrite would also take an Uint8ClampedArray or Uint8Array.
-
Hi,
I was surprised to see that the SPI approach actually worked for you, so I tried it too. The timing diagram with a logic analyzer shows, that it is barely working. The gap between the individual 4 bits is about 5,5 µs, which is on the margin of latching the sent data into the LEDs. The gap after the first byte is about 11 µs which explains the first dummy byte you had to send.
In your code you specify mosi:D15 which is of no use and a bit misleading, as MOSI in the ESP8255 is hardwired to pin GPIO13. But as already said it is not evaluated anyways.
Further, I saw no difference in the timings whether using the setTimeout call or not. Both produce the same output for me.
Finally, I verified that esp.neopixelWrite() still works fine.
-
As it is, I'm not sure we ever reached consensus on whether or not to include NeoPixel support in native Espruino (ESP8266 specific or otherwise).
I think in comment #32 (http://forum.espruino.com/comments/12608810/) Gordon already gave his blessing:
"I think realistically adding a software library specifically for neopixels is probably the best way to go for now :(" -
-
I think I had to call
pinMode(pin, 'output')
additionally, before neopixelWrite() did anything. (I am using GPIO2 on an ESP-01 board.)
As for the test:
- Before the pulses start, there is a 100 µs high pulse followed by a 100 µs low pause, which should not be there.
- The data bit pulses are a bit long, especially those for 0. I measured 550 ns, which gets recognized by standard WS2812 LEDs as a 1, so I always get three white LEDs, as every pulse is interpreted as 1.
I have repeatedly pointed to this really excellent article which describes the needed timing: http://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
Or, maybe just use the timings from the manuka/adafruit code, where you have taken the rest of the code from. I am going to add two screenshots...
- Before the pulses start, there is a 100 µs high pulse followed by a 100 µs low pause, which should not be there.
-
I just did some testing (see https://github.com/espruino/Espruino/issues/606#issuecomment-153983011), and currently it seems not to be possible to drive WS2812 LEDs.
-
But the start and stopbits... don't they interfere with the desired bit stream? Also, the idle state for a NeoPixel data line is a low voltage, while the idle state for a serial line is a high voltage.
With major trickery it seems to be doable (see e.g. http://wp.josh.com/2014/09/03/inside-neouart-tricking-a-serial-port-into-being-a-signal-generator/), but it's probably not the way to go.
-
-
-
So maybe the dedicated WS2812 driving code should just be included as well in the Espruino build for ESP8266? These are all valid points:
- Non-availability of HSPI on ESP-01 boards (soldering wires to a QFN package is practically not viable)
- Wasting 4 pins where only 1 is needed
- Drive more than one LED strip
- The increase in binary size is really small
- Non-availability of HSPI on ESP-01 boards (soldering wires to a QFN package is practically not viable)
-
-
Take a look here: https://github.com/nodemcu/nodemcu-devkit-v1.0/blob/master/Documents/NODEMCU-DEVKIT-V1.0-INSTRUCTION-EN.pdf
The SPI on the left side (orange SDIO pins) is used to talk to the flash. The HSPI on the right side (bright green) can be used freely.
I further tried the example as is (just replaced SPI2 by SPI1), and it roughly works (neglecting the first-byte delay problem), but it runs VERY slow: The LEDs are updated only every 120 ms.
Calling require("ESP8266").logDebug(false); improved it a bit but still 108 ms. Is it really supposed to run that slow?