Can't get my NeoPixels to turn on

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
misaalanshori
Posts: 26
Joined: Sat Jun 22, 2019 6:07 am

Can't get my NeoPixels to turn on

Post by misaalanshori » Wed Nov 20, 2019 3:16 pm

I have a WS2812 Neopixel stick with 8 leds, I connected the "DIN" to GPIO5, but i can't get it to light up at all. Im not sure if its my code, the led board, the esp board that is causing it
Heres the code:

Code: Select all

import machine, neopixel
pin = machine.Pin(5)
np = neopixel.NeoPixel(pin, 8)
np[0] = (255, 0, 0) # set to red, full brightness
np[1] = (0, 128, 0) # set to green, half brightness
np[2] = (0, 0, 64) 
np.write()
I copied it from the esp8266 docs but it didnt work, then i realised im on the wrong page and then i tried this:

Code: Select all

from machine import Pin
from neopixel import NeoPixel

pin = Pin(5, Pin.OUT)   # set GPIO0 to output to drive NeoPixels
np = NeoPixel(pin, 8)   # create NeoPixel driver on GPIO0 for 8 pixels
np[0] = (255, 255, 255) # set the first pixel to white
np.write()              # write data to all pixels
r, g, b = np[0]         # get first pixel colour
from the esp32 docs and it still didnt work
i also tried other pins with no luck (not all pins but a couple)


can someone help me find the source of the problem here? My board is a Heltec WiFI Kit 32 and this is the pin diagram and this is the led board: CJMCU-2812-8

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

Re: Can't get my NeoPixels to turn on

Post by Roberthh » Wed Nov 20, 2019 3:52 pm

It could be a matter of the logic levels. How do you power the stick? Can you reduce it's voltage to 4V?

misaalanshori
Posts: 26
Joined: Sat Jun 22, 2019 6:07 am

Re: Can't get my NeoPixels to turn on

Post by misaalanshori » Wed Nov 20, 2019 10:42 pm

I don't think I have anything that can output 4v, but a tutorial that I was following said that I should be able to just connect 5v to the led board directly and a GPIO pin to the DIN... maybe I should try to upload an Arduino example code to the board to make sure that the led board is not defective?

User avatar
jimmo
Posts: 1681
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Can't get my NeoPixels to turn on

Post by jimmo » Thu Nov 21, 2019 3:00 am

Because it's only a small number of LEDs, try powering hte stick from the 3.3V rail of the ESP32 board instead.

Although for correct functioning of NeoPixels, they really need 5V, and you need a 3.3->5V level shifter between the 3.3 IO on your microcontroller and the DIN of the first pixel.

misaalanshori
Posts: 26
Joined: Sat Jun 22, 2019 6:07 am

Re: Can't get my NeoPixels to turn on

Post by misaalanshori » Thu Nov 21, 2019 1:53 pm

so I found a neopixel Arduino library that works with an esp32 and it works first time, with 5v, on gpio pin 5... so it shouldn't be hardware related...
I still want to get this to work with micropython so what other troubleshooting steps should I do next?

OutoftheBOTS_
Posts: 780
Joined: Mon Nov 20, 2017 10:18 am

Re: Can't get my NeoPixels to turn on

Post by OutoftheBOTS_ » Thu Nov 21, 2019 9:31 pm

I have found timing problems to be a common cause for NeoPixel problems.

misaalanshori
Posts: 26
Joined: Sat Jun 22, 2019 6:07 am

Re: Can't get my NeoPixels to turn on

Post by misaalanshori » Thu Nov 21, 2019 11:00 pm

How do I fix the timing problems? do i have to change the cpu frequency?

OutoftheBOTS_
Posts: 780
Joined: Mon Nov 20, 2017 10:18 am

Re: Can't get my NeoPixels to turn on

Post by OutoftheBOTS_ » Fri Nov 22, 2019 10:24 am

I have only played with timing on Lobo fork for ESP32 https://github.com/loboris/MicroPython_ ... ngstimings not sure what low level setting for Neopixels are available on main line MP.

What I found is although they are called NeoPixels there is a number of different ICs used on these addressable RGB LEDs and many of these different ICs have slightly different timing requirements. I found that I could use standard timing with standard code on a LED strip but then a different LED strip needed the timing changed to work even though I brought both strips from same Chinese dealer with same product name just at a different time. It seems when they made these RGB LEDs they just use which ever IC was most available at the time.

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

Re: Can't get my NeoPixels to turn on

Post by Roberthh » Fri Nov 22, 2019 12:45 pm

I've tried a little bit with a WS2812 driver using SPI. It works more or less. You can change the timing slightly with the SPI baud rate.
https://github.com/robert-hh/WS2812/blo ... 812_spi.py

misaalanshori
Posts: 26
Joined: Sat Jun 22, 2019 6:07 am

Re: Can't get my NeoPixels to turn on

Post by misaalanshori » Sat Nov 23, 2019 2:06 am

So, I just erased my esp32 board (to test my led with arduino) and then flashed it with micropython again and now it works... Could it be caused by the cpu frequency? My boot file have machine.freq(240000000) on it and could that be the cause?

Post Reply