Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

APA102 Driver support #121

Open
Hokyjack opened this issue Jul 4, 2017 · 16 comments
Open

APA102 Driver support #121

Hokyjack opened this issue Jul 4, 2017 · 16 comments

Comments

@Hokyjack
Copy link

Hokyjack commented Jul 4, 2017

Hello, I have MicroPython v1.9.1-219-g3580284e installed at my ESP32 NodeMCU development board, but unfortunately I can't find APA102 library included altought it should be in ESP8266 1.9.1 microPython.

 from apa102 import APA102
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'apa102'

how should I add it so I can use it with ESP32?
and one more question - is this implementation of apa102 using real HSPI (hardware SPI) or it just bit-bangs the bits?

@dpgeorge
Copy link
Member

dpgeorge commented Jul 5, 2017

The APA102 driver for esp8266 is very specific to that chip (it uses inline assembler and has specific timing). So it's not straightforward to port it to the esp32. It's anyway just a bit-banging implementation.

It would be easier to write a new driver from scratch for the esp32, in Python, using the SPI peripheral (SCK and MOSI lines).

@Hokyjack
Copy link
Author

Hokyjack commented Jul 5, 2017

Oh, thanks for the answer, I'll try to write my own driver then

@mattytrentini
Copy link

Also see #159

@mattytrentini
Copy link

I'm just wondering why the APA102 implementation was implemented with bit-banging on the ESP8266? I've read the conversation on PR1941 but, while there was some solid, animated discussion and excellent collaboration, I'm not sure why an SPI implementation was chosen?

Was it perhaps that hardware SPI wasn't available at the time? Or that bit-banging produced faster updates that the 80MHz SPI limit? I'm sure I'm missing something obvious!

My understanding was that it should be possible to write a pure Python APA102 driver that just takes in a machine.SPI object. This will work across all ports and be optimised where hardware SPI is available...

@mattytrentini
Copy link

Oh, and @Hokyjack, are you still looking at creating an APA102 driver? If so, you should also be aware of the end-frame issue in the ESP8266 implementation, documented in PR3037: APA102 LED "n+1" is lighted on write().

@mcauser
Copy link
Contributor

mcauser commented Sep 5, 2017

Mention me (@mcauser) if you want me to test any code on my ESP32 (lolin32) and APA102 strip.

@dpgeorge
Copy link
Member

dpgeorge commented Sep 5, 2017

My understanding was that it should be possible to write a pure Python APA102 driver that just takes in a machine.SPI object.

Yes it should work, even at low SCK frequency. But note that the SPI will use up 3 pins on the MCU whereas the APA102 only needs 2.

@mattytrentini
Copy link

With the micropython-dotstar library we can probably close this ticket? @mcauser if you could test that library I'd really appreciate it!

Also posted on the forum, for reference.

@BEMNETADEFIS
Copy link

BEMNETADEFIS commented Jan 15, 2019 via email

@mattytrentini
Copy link

@BEMNETADEFIS the current design actually works for Linux right now. The gotcha is that it requires an object (spi) to handle the SPI comms - to do this it just requires two commands; write and deinit. It should be a simple matter to create a class that forwards these methods on to an underlying implementation.

Unfortunately, as I understand, SPI comms is non-standard in Linux right now. But if you have a way of sending SPI data in Python this library could use it with minimal fuss.

@RobertJBabb
Copy link

This is probably only of historical interest now, but I developed a MicroPython APA102/DotStar support library as well over the past few weeks: https://github.com/RobertJBabb/micropython_generic_apa102
The library supports the Adafruit DotStar API, the MicroPython ESP8266 APA102 API, and I added support for Matt's MicroPython SPI DotStar API after I saw his post. I focused on backward compatibilty instead of performance, so I expect that my class will be slower and consume more memory than Matt's. The repository also includes two test files that contain more compact examples of common DotStar demo code than I have seen elsewhere, perhaps that may be of interest to some.
I like Matt's implementation so I will probably use his library going forward.
As a newbie, what is the best way to coordinate development work with other MicroPython contributors?
I enjoyed writing this library but I would like to avoid duplicating effort in the future.

@dpgeorge
Copy link
Member

As a newbie, what is the best way to coordinate development work with other MicroPython contributors?

It's best to start by discussing on the https://forum.micropython.org

@BEMNETADEFIS
Copy link

BEMNETADEFIS commented Feb 3, 2019 via email

@mattytrentini
Copy link

@RobertJBabb As Damien mentioned, raising a topic in the forum is the best bet. Sorry I hadn't stumbled on your effort but I'll be sure to take a look at your implementation!

@BEMNETADEFIS To allow the APA102 driver to work on Linux you just need to come up with a Python class that can satisfy the SPI requirements of the APA102 driver. As mentioned, that means you just need a write and a deinit (and even the latter is not strictly necessary if you don't ever return the resources). Let me know if you need more assistance.

@BEMNETADEFIS
Copy link

BEMNETADEFIS commented Feb 8, 2019 via email

@BEMNETADEFIS
Copy link

BEMNETADEFIS commented Feb 8, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants