Neopixel RGBW

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
cefn
Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: Neopixel RGBW

Post by cefn » Thu Mar 28, 2019 5:50 pm

Assuming Microbit has full SPI support I speculate you could follow this implementation...

https://github.com/nickovs/ws2812-SPI/b ... /neoSPI.py

...since it just ships bytes out with the right timing.

Perhaps that amount of python is too much for the microbit. A lot of it is to support addressing the 'pixels' value as an array, and if you don't need this you could just pull out the timing and SPI parts.

JimHudd
Posts: 8
Joined: Mon Mar 25, 2019 3:09 pm

Re: Neopixel RGBW

Post by JimHudd » Thu Mar 28, 2019 7:24 pm

Thanks for this. I did have a quick look at this while seeing if there was anything else on Github. I need to improve my Python a bit to get my head around some of it but it does indeed look like a starting point. I'm also thinking the project I was going to do may be better done with an Arduino anyway and I'll just switch to using those. The Arduino IDE support seems to generally be better than for the MicroBit.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Neopixel RGBW

Post by rhubarbdog » Fri Mar 29, 2019 1:36 am

The only way you can interface these led with micropython on microbit it arm thumb2 assembly or
Possibly using the spi bus in a similar way
to this . The code is for the pyboard but isn't too difficult to translate. Notice the colours are specified in gbr not rgb.

JimHudd
Posts: 8
Joined: Mon Mar 25, 2019 3:09 pm

Re: Neopixel RGBW

Post by JimHudd » Fri Mar 29, 2019 8:05 am

There seems to be a couple of options. There's also the C/C++ library that underpins MicroPython and the blocks editer (and others) available for use so I'm going to look at using that. I've seen stuff about using the SPI bus (about which I currently know nothing!) and not relying on arrays for pixel buffers. I've a few things to read up on so exciting times ahead!

Jim.

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

Re: Neopixel RGBW

Post by Roberthh » Fri Mar 29, 2019 8:19 am

I made the small SPI script for the WS2812 that @rhubardog pointed at. It does not work well, at least on the ESP32 which I used for testing. The reason is, that the SPI driver does not send the bits in an single stream, but has some breaks between the bytes. If these breaks are too long, they are considered as resets. I did not test that on a MicroBit. The other drawback of this script is, that is uses a lot of memory for the transmission buffer, maybe too much for the MicroBit. The script was more intended as a trial. I made another one which uses the RMT module, and that one works well with solid timing. But that is for PyCom devices only, which have a RMT class (https://github.com/robert-hh/WS2812).

JimHudd
Posts: 8
Joined: Mon Mar 25, 2019 3:09 pm

Re: Neopixel RGBW

Post by JimHudd » Fri Mar 29, 2019 8:24 am

That's good to know, thanks for that. I have a feeling I migth be going right back to writing something pretty much from scratch that will send the data out to the NeoPixels. I'm stuggling to find a datasheet for the RGBW pixels at the moment, the only datasheets I can find are for the RGB pixels and I don't know if the same timings would apply. Still, it all very interesting to dig into!

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Neopixel RGBW

Post by rhubarbdog » Fri Mar 29, 2019 9:07 am

I tried that code on the pyboard and it worked ok. I may have added a `machine.disable_irq()` / `machine.enable_irq()` around the actual send. I'll give it a go on microbit later and post my results

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Neopixel RGBW

Post by rhubarbdog » Fri Mar 29, 2019 9:14 am

Just done some preparation and read the docs on the bus. Microbit spi only supports 8 bits that code requires 32 bits. I think it's a none starter.

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

Re: Neopixel RGBW

Post by Roberthh » Fri Mar 29, 2019 9:16 am

I tried with 8 bit too. It made no difference. It worked not better and not worse.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Neopixel RGBW

Post by rhubarbdog » Sat Mar 30, 2019 7:46 am

Well i think spi on microbit may be buggy.
I have destroyed the code @roberthh gave me and i can make my pyboard light the pixels.
I have a microbit version it does nothing. I don't have any spi devices to test my microbit. It's not the wiring as i can operate the pixel with neopixel.NeoPixel(pin15, 64)

Post Reply