apa102 lib for esp32

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.
barbsbou
Posts: 10
Joined: Wed May 13, 2020 1:50 pm

apa102 lib for esp32

Post by barbsbou » Wed May 13, 2020 3:34 pm

Hi everybody;

Firstly let us to introduce me, I am a computer scientist but really not a electrics engineer... so pretty sure that I have dumb questions, sorry about that!

Anyway I am really excited to play with my LoLin D32 (esp32) with micropython V1.12 and my apa102 led strip. But I can see that it is possible with the lib apa102 for esp8266 but we cannot find into my esp32.

I found NeoPixel lib but if I well understand it is for other led strip, with 3 pins, whereas the apa102 need 4 pins.

Thank you for your help!

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

Re: apa102 lib for esp32

Post by OutoftheBOTS_ » Wed May 13, 2020 8:35 pm

You can write your own driver super easy.

Just make an byte array with the data for all the LEDs (4 bytes per LED). Then open an SPI and first send the start bit then all the LED data then end bit to the SPI.

Connection are as follows:
connect a 5v power supply that is capable of suppling enough amps for how ever many LEDs you have to the LED Vcc pin.
Connect a common ground from both the power supply and the ESP32 to the LED GND pin.
Connect the MOSI (master out slave in) from the ESP32 to the LED DIN (data in) pin.
Connect the CLK (clock pin) from ESP32 to the LED CLK (clock pin) pin.

Look at the APA102 data sheet for the exact protocol needed but it goes something like this
Capture.JPG
Capture.JPG (54.31 KiB) Viewed 6874 times

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

Re: apa102 lib for esp32

Post by mattyt » Thu May 14, 2020 4:55 am

...or you can use my micropython-dotstar library. :)

barbsbou
Posts: 10
Joined: Wed May 13, 2020 1:50 pm

Re: apa102 lib for esp32

Post by barbsbou » Thu May 14, 2020 7:59 am

Oh!!!!

Firstly thank you for your reply!!
I really want to try to write my own driver, but since I am a real noob with electronics and I would like to finish my first projects, I think that I will use the mattyt's lib.
@OutoftheBOTS_ how can we find the description that you provide about apa102, if one day I would like to try my own driver for another device?

@mattyt before to post my message I found your lib but since I saw dotstart but I did not see micropython, I misunderstood because I believe that it was for arduino!! :oops:
Could I ask some help if I have any issue to use your lib in the your initial post (viewtopic.php?f=15&t=5810&p=33509)??


In fact, I bought different led strip, some that I will use with you lib, and other with NeoPixel which are include in micropython.
Do you think to have a wrapper lib could be nice? I mean to have one lib, which call either NeoPixel either the mattyt's lib depending of the led strip that you use? Thus independently that your type of led stripe we will use always this wrapper with the same manner. What do you think?

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

Re: apa102 lib for esp32

Post by OutoftheBOTS_ » Thu May 14, 2020 9:01 am

barbsbou wrote:
Thu May 14, 2020 7:59 am
Firstly thank you for your reply!!
I really want to try to write my own driver, but since I am a real noob with electronics and I would like to finish my first projects, I think that I will use the mattyt's lib.
@OutoftheBOTS_ how can we find the description that you provide about apa102, if one day I would like to try my own driver for another device?
Google APA102 datasheet this technique works for any hardware you trying to write a driver for just google the name of the hardware followed by the word datasheet :)

After your finished playing with Matty's driver and you want to write your own driver, APA102 are a pretty easy piece of hardware to be writing your first driver for, most other hardware are much more complex.

barbsbou
Posts: 10
Joined: Wed May 13, 2020 1:50 pm

Re: apa102 lib for esp32

Post by barbsbou » Thu May 14, 2020 12:45 pm

OutoftheBOTS_ wrote:
Thu May 14, 2020 9:01 am
Google APA102 datasheet this technique works for any hardware you trying to write a driver for just google the name of the hardware followed by the word datasheet
Indeed, datasheet is a keyword that I should use more often!! :D

thank you for your advice!! ;-)

barbsbou
Posts: 10
Joined: Wed May 13, 2020 1:50 pm

Re: apa102 lib for esp32

Post by barbsbou » Fri May 15, 2020 8:25 am

Hi;

Yesterday I played with the mattyt's lib and I couldn't to switch on the strip led. So I continue to search any solution or what is the problem (firstly I look on the interface between the chair and the keyboard... :D ). And found this post
viewtopic.php?f=15&t=7276

It was a problem a frequency. So I am asking if it could be the same... ???
What do you think about it??

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

Re: apa102 lib for esp32

Post by OutoftheBOTS_ » Fri May 15, 2020 9:31 am

The post you linked was for Neopixels not APA102 which are different. Neopixels are what is known as 1 wire communication where the data is sent out over 1 data line so the timing has to be perfect. APA102 use 2 lines synchronous communications where there is a data line and a clock line, the clock line is used to synchronize each bit of data being transmitted so timing doesn't matter as long as it isn't too fast.

My first bet would be to check the wiring is correct.

You your going to be running anymore than just a few LEDs then you will need a seperate power supply as the board wouldn't be able to supply enough current to run larger amounts of LEDs

wiring should be

5v power supply to Vcc pin on LEDs
common ground from both power supply and board to GND pin of LEDs
Board SPI MOSI pin to the DIN pin on LEDs
Board SPI CLK pin to CLK pin on LEDs

barbsbou
Posts: 10
Joined: Wed May 13, 2020 1:50 pm

Re: apa102 lib for esp32

Post by barbsbou » Fri May 15, 2020 9:50 am

Thank you for your fast reply!!

It is was I checked in the first time...but all look like correct.

I used the 5V and GND of an arduino
and the same pins that the example of mattyt that are 12 and 13
I wanted only switch on only the 10th first led because I know that I have not a really good power

Code: Select all

from micropython_dotstar import DotStar
from machine import SPI, Pin

nb_leds   = 10

clock_pin = 12 # green wire on my strip
data_pin  = 13 # yellow wire on my strip
empty_pin = 18 # nothing is connected 


spi = SPI(sck=Pin(clock_pin), mosi=Pin(data_pin), miso=Pin(empty_pin)) # Configure SPI
LED = DotStar(spi, nb_leds) # define my array of leds




LED[0] = (128, 0, 0) # Red
LED[1] = (128, 0, 0, 0.5) # Red, half brightness
LED.fill((0,0,128)) # Blue


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

Re: apa102 lib for esp32

Post by OutoftheBOTS_ » Fri May 15, 2020 8:22 pm

If your only going to be running 10 LEDs you can probably run them from the ESP32 5v pin but wouldn't run larger amounts (Ardunio power supply isn't any better than ESP32).

Do you also have a common ground to both the power supply and the ESP32???

Post Reply