jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.79k stars 623 forks source link

Support for DotStar/APA102/SK9822 LEDs? #406

Open clickworkorange opened 4 years ago

clickworkorange commented 4 years ago

I've been using this library on many projects over the last couple of years, and love its simplicity, flexibility, and lack of dependencies. But now I've been tasked with upgrading a design which uses two DotStar LED strips and was surprised to find that these are apparently not supported by this library?

Edit: For a giggle I tried https://github.com/tinue/apa102-pi, and well... yeah.

pip3 install apa102-pi
Collecting apa102-pi
  Downloading https://files.pythonhosted.org/packages/e0/85/56fa4dff6e9295c355a3f05a08f5537d38c9868edce185293668683585cb/apa102_pi-2.4.0-py3-none-any.whl
Collecting adafruit-circuitpython-bitbangio (from apa102-pi)
  Downloading https://www.piwheels.org/simple/adafruit-circuitpython-bitbangio/adafruit_circuitpython_bitbangio-1.1.1-py3-none-any.whl
Collecting adafruit-circuitpython-busdevice (from apa102-pi)
  Downloading https://www.piwheels.org/simple/adafruit-circuitpython-busdevice/adafruit_circuitpython_busdevice-4.3.1-py3-none-any.whl
Collecting Adafruit-Blinka (from adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://files.pythonhosted.org/packages/a2/d5/3449fb6750f6b09ea4da7b43000bc07282d359dc724e0c85861e760f9ecb/Adafruit-Blinka-5.1.0.tar.gz (105kB)
    100% |████████████████████████████████| 112kB 166kB/s 
Collecting Adafruit-PlatformDetect>=2.11.1 (from Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://files.pythonhosted.org/packages/4f/a7/c1ef0f336c4d302e1d1888db30eb46f393515fe36696d48e89d8ff2b484d/Adafruit-PlatformDetect-2.14.0.tar.gz
Collecting Adafruit-PureIO>=1.1.5 (from Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://www.piwheels.org/simple/adafruit-pureio/Adafruit_PureIO-1.1.5-py3-none-any.whl
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
Collecting pyftdi>=0.40.0 (from Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://files.pythonhosted.org/packages/80/9e/0893cd66e60946b881651012bbbb673a6bac1ceddf71d196fa17fb09dffa/pyftdi-0.51.2-py3-none-any.whl (150kB)
    100% |████████████████████████████████| 153kB 329kB/s 
Requirement already satisfied: rpi_ws281x>=4.0.0 in /usr/local/lib/python3.5/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
Collecting sysv_ipc; platform_system != "Windows" and platform_machine != "mips" (from Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://www.piwheels.org/simple/sysv-ipc/sysv_ipc-1.0.1-cp35-cp35m-linux_armv7l.whl (61kB)
    100% |████████████████████████████████| 71kB 123kB/s 
Collecting pyusb>=1.0.0 (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://www.piwheels.org/simple/pyusb/pyusb-1.0.2-py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 178kB/s 
Collecting aenum>=2.1.0; python_version == "3.5" (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
  Downloading https://files.pythonhosted.org/packages/14/5f/320aa3eb68773a147f9a804167087160ca230f530b03eee30ec33f0070c7/aenum-2.2.3-py3-none-any.whl (40kB)
    100% |████████████████████████████████| 40kB 13kB/s 
Requirement already satisfied: pyserial>=3.0 in /usr/local/lib/python3.5/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-bitbangio->apa102-pi)
Building wheels for collected packages: Adafruit-Blinka, Adafruit-PlatformDetect
  Running setup.py bdist_wheel for Adafruit-Blinka ... done
  Stored in directory: /root/.cache/pip/wheels/13/07/95/a0099e7fba65f4b2123ba46a8072cf90d0f3fa668843dd219b
  Running setup.py bdist_wheel for Adafruit-PlatformDetect ... done
  Stored in directory: /root/.cache/pip/wheels/34/d4/06/ec20c4ac373698e605133a0514bb0a2aef6851eaa692acafac
Successfully built Adafruit-Blinka Adafruit-PlatformDetect
Installing collected packages: Adafruit-PlatformDetect, Adafruit-PureIO, pyusb, aenum, pyftdi, sysv-ipc, Adafruit-Blinka, adafruit-circuitpython-bitbangio, adafruit-circuitpython-busdevice, apa102-pi
Successfully installed Adafruit-Blinka-5.1.0 Adafruit-PlatformDetect-2.14.0 Adafruit-PureIO-1.1.5 adafruit-circuitpython-bitbangio-1.1.1 adafruit-circuitpython-busdevice-4.3.1 aenum-2.2.3 apa102-pi-2.4.0 pyftdi-0.51.2 pyusb-1.0.2 sysv-ipc-1.0.1

All of this, just to send a few bytes over SPI. I won't repeat the stream of profanities it elicited here, but suffice to say: this is not remotely acceptable. So I'm re-opening this in the hope that there's a way to get rpi_ws281x to play nice with the DotStars.

Gadgetoid commented 4 years ago

This is out of scope for the WS2812 library- APA102s don't require any of the Pi-specific gymnastics to generate precise timing signals that WS281x LEDs do.

Running APA102 LEDs is so ridiculously trivial that you shouldn't need a library at all. A thin wrapper around Python's Spidev should suffice.

This is a bit-banged implementation of the APA102 protocol using RPi.GPIO that will run on any two pins: https://github.com/pimoroni/plasma/blob/devel/library/plasma/apa102.py

If you use SPI hardware it's even simpler.

Your experience with apa102-pi is typical of software built against Adafruit's Blinka compatibility shim- which aims to smooth the gap between Raspberry Pi (and other SBCs) and CircuitPython. It's good for certain use-cases, but minimal dependencies is not one of them.

Edit: Not one to stand behind an "it can't be done" answer, here's a new barebones Python library for driving APA102 pixels either via bit-banged GPIO or SPI: https://github.com/pimoroni/apa102-python