Dotstar (aka APA102) library

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.
Post Reply
User avatar
mattyt
Posts: 159
Joined: Mon Jan 23, 2017 6:39 am

Dotstar (aka APA102) library

Post by mattyt » Sun Jan 13, 2019 1:01 am

I've just published the MicroPython DotStar library.

It's a straightforward port of Adafruit's CircuitPython DotStar library. Which was originally a port of a MicroPython Neopixel library - it's come full circle!

Previously APA102 control was only supported via a port-specific module on the ESP8266. This library ought to work on all ports.

The only real change was to strip out the SPI comms from within the CircuitPython driver. Now an SPI object is required to create a DotStar object. (This is a better design anyway IMO)

Code: Select all

spi = SPI(sck=Pin(12), mosi=Pin(13), miso=Pin(18)) # Configure SPI - note: miso is unused
dotstar = DotStar(spi, 1) # Juse one DotStar
dotstar[0] = (128, 0, 0) # Red
Currently the software SPI driver requires all of sck, mosi and miso to be supplied, hence the configuration of miso (Pin 18 is unused). We could - should? - make those parameters optional as there are many SPI devices that only employ one-way comms. Note that hardware SPI may not need all parameters to be set (on the ESP32 with HW SPI you can drop miso).

This hasn't had a lot of testing - I only have DotStar 'strips' of length=1 ;) - so I'd appreciate any feedback!

The pins selected match those used in the TinyPICO in case you're wondering. :)

bill-e
Posts: 2
Joined: Tue Jan 15, 2019 1:38 am

Re: Dotstar (aka APA102) library

Post by bill-e » Tue Jan 15, 2019 1:52 am

I just tried it with 4 APA102 LED's and it appears to be working. Thanks for writing this. It's weird because I just started looking this morning, and it looks like you finished it on Saturday. Good timing! I'll try it with a string of 140 LED's next. I'm using a Huzzah32 board.

Thanks,

bill-e
Posts: 2
Joined: Tue Jan 15, 2019 1:38 am

Re: Dotstar (aka APA102) library

Post by bill-e » Wed Jan 16, 2019 2:45 am

I tried this with a strip of 136 LEDS and it works well. Any tips for making the LED's update more quickly? It takes about 5 seconds for all the LED's to change color in the 136 LED strip.

User avatar
mattyt
Posts: 159
Joined: Mon Jan 23, 2017 6:39 am

Re: Dotstar (aka APA102) library

Post by mattyt » Wed Jan 16, 2019 6:27 am

Thanks for testing this out! Really appreciate it.

First thing to try would be to use hardware SPI if you're not already. I'll need to check the Huzzah32 pinout but some ESP32 pins can support much higher SPI transfer rates; APA102's should be capable of 10's of MHz (the ESP32 can transfer SPI at a max of 40MHz with HW support).

That said the bottleneck may be elsewhere - configuring the buffer with the colour data for example. If this is the case we'll need to implement more of the module in C...

I'm at work at the moment so will need to look into this at a later stage but hopefully that gives you some clues!

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

Re: Dotstar (aka APA102) library

Post by OutoftheBOTS_ » Wed Jan 16, 2019 7:43 am

mattyt wrote:
Wed Jan 16, 2019 6:27 am
Thanks for testing this out! Really appreciate it.

First thing to try would be to use hardware SPI if you're not already. I'll need to check the Huzzah32 pinout but some ESP32 pins can support much higher SPI transfer rates; APA102's should be capable of 10's of MHz (the ESP32 can transfer SPI at a max of 40MHz with HW support).

That said the bottleneck may be elsewhere - configuring the buffer with the colour data for example. If this is the case we'll need to implement more of the module in C...

I'm at work at the moment so will need to look into this at a later stage but hopefully that gives you some clues!
I did originally write an APA102 library for the RPi using SPI all written in Python. I found that I could go as fast as 64Mhz before the LEDs didn't respond anymore. Theatricality you should be able to update strips very fast.

Also do be aware that most of the places that are selling APA102 are in fact not APA102 but the Chinese clone sk9822 which don't perform as well for both updates and saturation in colour. I have compared them side by side and the APA102 r far Superior here's a blog someone wrote about it https://cpldcpu.wordpress.com/2016/12/1 ... he-apa102/

Post Reply