Pycom LoPy4 & WS2812 LEDs

I cannot get the WS2812/Neopixel code working. It does turn on some of the LEDs but in a quite random way. Even with something very simple like

data = [(0,255,255)] * numLed

chain.show(data)

  • whatever I set for RGB it shows green.



    If i change the code I end up with random blue and white LEDs.

    I checked the number of LEDs so not sure what else to check.

Hi Ed,

Are you using a logic level shifter as shown in the Tutorial? This sounds like your LEDs arenā€™t getting a strong enough data signal.

Thanks for the quick reply.

I was just using 3.3V from the Pycom Expansion Board.

I did read that I could limit the code to a few LEDs to test the logic out.

If that is the case, would the following work - or do you have to define the full number (i.e. 59) of LEDs for the code to work ?

numLed = 2 #59 LEDs on the strip

chain = WS2812( ledNumber=numLed, brightness=10, dataPin=ā€˜P11ā€™ )

data = [(255,0,0)] * 2

chain.show(data)

The above actually lights up 5 LEDs - 3xblue, 1xwhite, 1 green !

Regards

Eddy

I am now using a separate 4.5v battery supply, and have a 330 Ohm resistor on the signal Pin.
I am running very basic code - as below, but the results are just random illumination of the LEDs (and more than 4)- it changes every time I press Run.

numLed = 4
chain = WS2812( ledNumber=4, brightness=10, dataPin=ā€˜P11ā€™ )
data = [
(255, 0, 0), # red
(0, 255, 0), # green
(0, 0, 255), # blue
(85, 85, 85) # white
]
chain.show(data)

1 Like

Hi Ed,

Are you using a logic level shifter?

1 Like

I wasnā€™t initially as I had read I could drive it with 3v3 (it would be dimmer).
Now I have purchased a Level Shifter and wired up as per your diagram, but still getting random results.
Or rather now I just see 58 out of the 59 LEDs illuminated (1st one not), some light blue, the rest white. The latest simpler code is

numLed = 59 #59 LEDs
chain = WS2812( ledNumber=numLed, brightness=10, dataPin=ā€˜P11ā€™ )
data = [(255, 0, 0)] * numLed
chain.show(data)

The only difference is that I did not connect Lopy VIN to the 4.5V battery supply as I have the Lopy connected via USB.

Hi Ed,

Could you please provide a photo of your setup (as clear as possible),

and perhaps a diagram of how you have everything connected? Are you using a Lopy4 or a Lopy?

Stephen,

Thanks again for your help with this.

I am using a Lopy4 on a Pycom/Makr Expansion Board 3.1

I have attached 2 photos - let me know if you need to see any close-ups.

The diagram is exactly as you have here:

https://core-electronics.com.au/tutorials/WS2812_and_NeoPixel_with_Pycom.html

The only difference is that I did not use a +5V connection from the power supply to VIN on the Lopy4 - because I am powering it via USB whilst testing.

I checked the voltage output from the battery pack (show on the photo - 3 batteries so assuming 4.5V) but it was in fact around 3.7V.

So, I switched that for a 4-battery pack using NiMH - as suggested in this article:

https://learn.adafruit.com/adafruit-neopixel-uberguide/powering-neopixels

That was showing a more healthy 5V and the lights did look brighter.

However I still have the problem of random results whenever I run the simplest of code.

Out of interest - is there a neopixels.py library available ?

Thatā€™s where I started off, looking at examples on the Adafruit website and other example projects such as this one:

https://www.rototron.info/raspberry-pi-esp32-micropython-web-server-tutorial/

(my project is similar to this)

Allexamples I have read suggest that you can just ā€œimport neopixelsā€ - but I have not been able to find a neopixels.py library file,or rather one that you can just copy and it works. The Adafruit site talks about installing a whole ton of libraries, but whilst that may work on a PC, I donā€™t see how you can get that onto a LoPy4. The Adafruit site does say that their examples will run on MicroPython, but I always end up reading that I need CircuitPython.

My preference is for simplicity and the examples you posted seem very clear.

I just need to get them working !

Best regards

Eddy

Stephen,

I was looking at the specification for the AdaFruit LED strip we have , which is here:

https://www.adafruit.com/product/1138

It states that ā€œit will not work with the Basic Stamp, NETduino, any other interpreted/virtual machine microprocessor or any processor slower than 8 MHzā€

I looked at the Lopy4 Spec sheet but cannot find any reference to the processor speed

https://cdn.sparkfun.com/assets/e/b/2/9/0/lopy4-specsheet.pdf

Is the processor speed part of the problem ?

Eddy

Hi Ed,

There are no NeoPixel libraries for Pycom boards, thats why I created this tutorial. This definitely works with the LoPy4 and WiPy with the expansion 3.x board. I tested it with both setups when writing the code, and it worked as expected.

It sounds like your LED strip has a bad data input still. The key thing about driving NeoPixels is the difference between the data input and the power input (to the LED strip). You can control NeoPixels with 0.7 * Vin.

Can you verify that your level shifter is working properly? Iā€™m not sure what one you are using, but itā€™s different than the one Iā€™ve used in the tutorial. I see that there is an RX and TX on each side. If I was a betting man Iā€™d say you need to connect your blue data wire to RX0 for this to work.

Hopefully that sorts it out!

Stephen,

Thanks again.

Glad to hear you got it working with the same board; is the actual LED strip a factor ?

Is my Logic Shifter working properly ?

Hard to say as I am not sure how to test that.

My soldering skills are reasonable, but to be sure I soldered the pins to a 2nd Shifter and used that - but just the same.

Regarding the TX/RX - I am fairly sure the wiring is correct - mainly becuase it is the exactly same as you have.

Please see attached.

The only difference on the pins is that your HV and GND are the other way round.

From what I have read you have to connect TXI to TXO (or RXI to RXO if dropping down voltage).

One example reference: https://www.robotshop.com/community/blog/show/running-both-5v-and-3-3v-devices-on-i2c

I did take your advice and put the blue wire from TXI to RXO but the LEDs just donā€™t light up at all.

This is in line with what I would expect given the above - TXI (Low voltage signal in) has to be connected to TXO (High voltage signal out).

I will solder another Logic Shifter up just in case I have created 2 bad shifters, but if you have advice on how I can test this please let me know.

Eddy

Logic Shifter Connection as per Core Electronics.pdf (72.6 KB)

Itā€™s electronics, so it could be anything. Testing the data signal is more of a ā€œhalf splitā€ to look up/down the circuit.

Also worth noting that Iā€™m not sure about the wiring within your logic level converters, though I canā€™t see a common ground between the battery pack and the USB (LoPy4).

Itā€™s also not likely that 3 AA batteries in series will be enough to power a high density strip of RGB LEDs.

Iā€™ve moved this to a new topic, as the project/issue is related to parts/hardware/power that are not used in @Stephenā€™s tutorial.