tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
587 stars 180 forks source link

ws2812: 12V-driven WS2811 LEDs flicker #588

Closed diamondburned closed 11 months ago

diamondburned commented 11 months ago

PR https://github.com/tinygo-org/drivers/pull/313 apparently adds support for WS2811 driven at 5V, but does 12V change this?

I'm currently writing a test program similar to the one in the example and flashing it onto an ESP32, but the LEDs just flicker:

https://github.com/tinygo-org/drivers/assets/8463786/4d8562e8-f1d1-473f-8bf5-cd2431175cae


Reproducing code ```go package main import ( "image/color" "machine" "time" "tinygo.org/x/drivers/ws2812" ) const numLEDs = 50 var colors [numLEDs]color.RGBA func main() { machine.GPIO1.Configure(machine.PinConfig{Mode: machine.PinOutput}) led := ws2812.New(machine.GPIO1) var state bool for { for i := range colors { if state { colors[i] = color.RGBA{255, 0, 0, 255} } else { colors[i] = color.RGBA{0, 0, 0, 255} } } led.WriteColors(colors[:]) state = !state time.Sleep(time.Second) } } ```
Build command ``` sudo tinygo flash -target=esp32-coreboard-v2 -port=/dev/ttyUSB0 ```
Product information - ESP32: https://www.amazon.com/gp/product/B0B9G74NNM - WS2811 LEDs: https://www.amazon.com/gp/product/B01AG923EU
aykevl commented 11 months ago

Hmm, it's really hard to say what exactly goes wrong here. This could be so many issues.

As a first step, can you try disabling interrupts?

import "runtime/interrupt"

...

state := interrupt.Disable()
led.WriteColors(colors[:])
interrupt.Restore(state)

Then, there could be many reasons for this particular issue, like:

  1. Insufficient power (60mA * 50 LEDs = 3A of power needed!). Are you sure you provide the LEDs with enough power, using a thick wire? (No breadboard wires etc).
  2. Have you connected the ground of the power source and of the ESP32? It's hard to see from the video, but I don't think I see a ground wire.
  3. Is it a reasonably short data wire? Standard breadboard wires should be fine, more than a meter of wire can be problematic.

(Also thanks for the very detailed issue report!)

diamondburned commented 11 months ago

Have you connected the ground of the power source and of the ESP32? It's hard to see from the video, but I don't think I see a ground wire.

This ended up being the problem... Sorry for wasting your time...

aykevl commented 11 months ago

Good to hear, happy to help :)