User Tools

Site Tools


feathers2_apa102

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
feathers2_apa102 [2024/03/26 10:04]
sausage created
feathers2_apa102 [2024/04/04 21:34] (current)
sausage [Setting up an ESP32-S2 project]
Line 1: Line 1:
-====== ​FeatherS2 ​ESP32-S2 APA102 ======+====== ESP32-S2 ​and the APA102 ​RGB LED ======
  
 {{ ::​esp32s2:​feathers2.jpg?​direct&​400|}} {{ ::​esp32s2:​feathers2.jpg?​direct&​400|}}
Line 9: Line 9:
 Of course, when you receive a new board, the first thing you're going to want to do is flash the LED, right? It's in the constitution. And this one has an RGB LED. Sweet, three signals to the LED. That won't be hard. Of course, when you receive a new board, the first thing you're going to want to do is flash the LED, right? It's in the constitution. And this one has an RGB LED. Sweet, three signals to the LED. That won't be hard.
  
-But wait up, this is an APA-102 ​RGB LED. It has data and clock pins.+But wait up, this is an APA102 ​RGB LED. It has data and clock pins.
  
 So I jumped onto both the [[https://​unexpectedmaker.com|UnexpectedMaker]] and [[https://​feathers2.io|FeatherS2]] sites. Surprisingly and there is little guidance to using it, you're pretty much on your own. Thankfully there is a regular onboard blue LED provided for standard blinky. But we all want the colours right? So I jumped onto both the [[https://​unexpectedmaker.com|UnexpectedMaker]] and [[https://​feathers2.io|FeatherS2]] sites. Surprisingly and there is little guidance to using it, you're pretty much on your own. Thankfully there is a regular onboard blue LED provided for standard blinky. But we all want the colours right?
Line 17: Line 17:
 For this article it will be assumed that you have ''​esp-idf''​ [[https://​dl.espressif.com/​dl/​esp-idf/?​idf=4.4|installed and working]], and that you know what your COM port number currently is. I'll use COM7 as an example throughout the article. For this article it will be assumed that you have ''​esp-idf''​ [[https://​dl.espressif.com/​dl/​esp-idf/?​idf=4.4|installed and working]], and that you know what your COM port number currently is. I'll use COM7 as an example throughout the article.
  
-An ESP32-S2 based board with an APA-102 ​RGB LED or SK9822 LED. +An ESP32-S2 based board with an APA102 ​RGB LED or SK9822 LED. 
  
 You should be able to follow along with an equivalent ESP32-S2 board. You should be able to follow along with an equivalent ESP32-S2 board.
Line 24: Line 24:
  
  
-===== Setting up an ESP32 or ESP32-S2 project =====+===== Setting up an ESP32-S2 project =====
  
 In order that we can get the RGB LED working together, let's make a new project. In order that we can get the RGB LED working together, let's make a new project.
Line 38: Line 38:
 We now have a build folder where our firmware will be built. ​ We now have a build folder where our firmware will be built. ​
  
-We have to make two settings ​in our menuconfig to ensure ​our firmware does not crash:+We to make a change ​in our menuconfig to ensure ​we can get debug information through USB:
  
   idf.py menuconfig   idf.py menuconfig
Line 79: Line 79:
 </​code>​ </​code>​
  
-Of course this does nothing but it will show the bones of all that needs to occur in order to set the colour of the LED. First, the APA-102 ​will need to be initialised. This means setting it up for serial communication.+Of course this does nothing but it will show the bones of all that needs to occur in order to set the colour of the LED. First, the APA102 ​will need to be initialised. This means setting it up for serial communication.
  
 The second step is to send a sequence of bytes to change the colour. There does not need to be a loop to maintain the colour or any continued communication. Once the byte sequence is sent to the LED, it will remain that colour until it receives new information. The second step is to send a sequence of bytes to change the colour. There does not need to be a loop to maintain the colour or any continued communication. Once the byte sequence is sent to the LED, it will remain that colour until it receives new information.
Line 132: Line 132:
 </​code>​ </​code>​
  
-To explain the initApa102 function, we have a minimal SPI config ​and a minimal SPI bus configThe SPI bus is initialised with the SPI config along with which SPI host it is for. The SPI bus config and the SPI host is passed a new device. ******+To explain the initApa102 function, we have a minimal SPI Interface Config ​and a minimal SPI Bus ConfigThese configs are set to a SPI host device ​it is for. 
  
-Note the host is FSPI_HOST. This is the host that is controlling the LED. On ESP32 boards (non S2), this SPI is named HSPI_HOST.+Our host is ''​FSPI_HOST''​. This is one that is controlling the LED. On ESP32 boards (non S2), this SPI is named ''​HSPI_HOST''​.
  
 See: https://​github.com/​espressif/​esp-idf/​blob/​357a2776032299b8bc4044900a8f1d6950d7ce89/​components/​hal/​include/​hal/​spi_types.h#​L47-L57 See: https://​github.com/​espressif/​esp-idf/​blob/​357a2776032299b8bc4044900a8f1d6950d7ce89/​components/​hal/​include/​hal/​spi_types.h#​L47-L57
  
-Pin 21 needs to be turned on to supply the power to the APA-102.+Pin 21 needs to be turned on to supply the power to the APA102.
  
  
Line 192: Line 192:
 Next is construction of the rgbBits array. Using the datasheet, I've built the data sequence using a mixture of binary and hex notation to make it easy to compare against what the datasheet suggests. Next is construction of the rgbBits array. Using the datasheet, I've built the data sequence using a mixture of binary and hex notation to make it easy to compare against what the datasheet suggests.
  
-Then add the array to a SPI transaction and transmit to the APA-102 ​SPI device.+Then add the array to a SPI transaction and transmit to the APA102 ​SPI device.
  
-The APA-102 ​will respond to this data by lighting up!+The APA102 ​will respond to this data by lighting up!
  
  
 ===== Where to from here? ===== ===== Where to from here? =====
  
-You can achieve a number of effects, colour combinations and brightness levels. Feel free to check out my APA-102 ​fader code at: https://​github.com/​sausagejohnson/​apa102-fader-serial/​blob/​master/​main/​main.c+You can achieve a number of effects, colour combinations and brightness levels. Feel free to check out my APA102 ​fader code at: https://​github.com/​sausagejohnson/​apa102-fader-serial/​blob/​master/​main/​main.c
  
 The code takes two colours and smoothly fades back and forth between the two using a FreeRTOS task. This is easy to implement into a small library for your own projects. The code takes two colours and smoothly fades back and forth between the two using a FreeRTOS task. This is easy to implement into a small library for your own projects.
Line 208: Line 208:
 The LED won't come on? There are a number of things to re-check: The LED won't come on? There are a number of things to re-check:
  
-  - Ensure USB CDC is set in the menuconfig ​or the board firmware will fail.+  - Firmware may have crashed. ​Ensure USB CDC is set in the menuconfig.
   - Ensure RGB_DATA_PIN is set to mosi_io_num and RGB_CLK_PIN to sclk_io_num. Check it's not the wrong way around.   - Ensure RGB_DATA_PIN is set to mosi_io_num and RGB_CLK_PIN to sclk_io_num. Check it's not the wrong way around.
   - Ensure pin 21 is on to supply power.   - Ensure pin 21 is on to supply power.
   - FSPI_HOST must be chosen host.   - FSPI_HOST must be chosen host.
-  - The byte sequence sent to the APA-102 ​must be correct.+  - The byte sequence sent to the APA102 ​must be correct.
  
  
feathers2_apa102.1711447471.txt.gz ยท Last modified: 2024/03/26 10:04 by sausage