Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native SPI RGB LED component #5288

Merged
merged 34 commits into from
Sep 11, 2023
Merged

Native SPI RGB LED component #5288

merged 34 commits into from
Sep 11, 2023

Conversation

clydebarrow
Copy link
Contributor

@clydebarrow clydebarrow commented Aug 21, 2023

What does this implement/fix?

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

This new component supports the APA102 and similar SPI addressable RGB LEDs. While there is support for these LEDs in other components, these rely on external libraries supporting multiple different chip types and don't work with ESP-IDF.

This component supports only the SPI (two wire) LED interface and leverages the existing ESPHome spi component so works on both Arduino and ESP-IDF platforms, is lightweight and performant. It has only been tested on ESP32 but should work with any platform supported by ESPHome that implements SPI.

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#3147

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Example entry for config.yaml:

# Example config.yaml
    spi:
      mosi_pin: GPIO3
      clk_pin: GPIO9

    light:
      - platform: apa102
        num_leds: 30
        color_correct: [80%, 60%, 100%]
        id: rgb_led
        name: "RGB LED Strip"
        data_rate: 1MHz

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@jesserockz
Copy link
Member

This is kinda a duplicate of #5101 which does need work to use SPIDevice like this PR does, but implements a generic SPI led strip driver which would be preferred over having multiple specific ones like this PR implements. Perhaps somehow a merge of the two PRs is in order?

@clydebarrow
Copy link
Contributor Author

clydebarrow commented Aug 21, 2023

generic SPI led strip driver which would be preferred over having multiple specific ones like this PR implements

Well I don't have any of the other LEDs on hand to test with, however looking at the datasheet for the SK9822 and the HD107 it appears the code I already wrote will work with them, as they have the identical frame format and BGR order. So maybe all that's needed is a name change (maybe spi_rgb_led) and some extra documentation.

I don't want to make it some kind of umbrella component that tries to do too much. Keeping it simple makes keeping it working easy. IOW I would resist adding the one-wire LED protocol support which requires quite different code.

@clydebarrow
Copy link
Contributor Author

The APA107 is a 1-wire chip, so not SPI compatible. The HD108 is SPI but has 16 bit data, so that's a possibility to add, but I'd prefer to do that later when I have some to test with. They're new and more expensive so probably not widely in use yet.

So right now it seems the APA102, APA102C, HD107 and SK9822 will work with my code and they are the main SPI type RGB leds available.

@kbx81
Copy link
Member

kbx81 commented Aug 21, 2023

The APA107 is a 1-wire chip

FWIW, I think the APA107 is also a 2-wire interface with clock and data lines -- at least, everything I'm finding on it right now seems to indicate this. 😇

@clydebarrow
Copy link
Contributor Author

I found two conflicting datasheets for APA107. Maybe there are two different chips from different manufacturers.

https://www.rose-lighting.com/wp-content/uploads/sites/53/2019/10/apa107-LED.pdf

https://www.superlightingled.com/PDF/APA107.pdf

@clydebarrow
Copy link
Contributor Author

Anyway, the 2 wire APA107 should work just fine with this component. I renamed it to spi_rgb_led and updated the docs to reflect the fact it works with chips other than APA102.

@clydebarrow clydebarrow changed the title APA102 RGB LED component Native SPI RGB LED component Aug 22, 2023
@jesserockz
Copy link
Member

jesserockz commented Sep 5, 2023

spi_led_strip would be better to match esp32_rmt_led_strip and rp2040_pio_led_strip

@kbx81 kbx81 mentioned this pull request Sep 11, 2023
11 tasks
@kbx81 kbx81 merged commit d264865 into esphome:dev Sep 11, 2023
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2023
@clydebarrow clydebarrow deleted the apa102 branch October 21, 2024 23:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants