GithubHelp home page GithubHelp logo

tinue / apa102-pi Goto Github PK

View Code? Open in Web Editor NEW
199.0 23.0 71.0 4.58 MB

Pure Python library to drive APA102 LED stripes; Use with Raspberry Pi.

License: GNU General Public License v2.0

Python 100.00%
python raspberry-pi led-strips dotstar-leds apa102 spi

apa102-pi's Introduction

apa102-pi

Introduction

Apa102-pi is a pure Python library to drive APA102 and SK9822 type LED strands. It is supposed to work on a Raspberry Pi, and is not tested on any other platform.

Be advised that I consider this library to be "done", and don't plan to develop more functionality. I still monitor the Github page for issues or pull requests, and will release minor updates from time to time.

APA102 LEDs are typically 5050 type LEDs with an additional driver chip per LED. The driver chip takes care of receiving the desired colour via its input lines, and then holding this colour until a new command arrives.

Depending on the LEDs vendor, they might be called "APA102", "SK9822", "Superled", or "DotStar". They must not be confused with the three-wire WS2812 LEDs, also known as "NeoPixel".

The really nice part about the driver chip is this: Once it has received its own colour command, it forwards any further colour commands from its input to its output lines. This allows to easily chain multiple LEDs together. Colour command #1 lights the first LED, command #2 the next LED, and so forth. Sending for example 300 colour commands does light an entire 5 Meter, 60 LEDs per Meter strip.

Some APA102 pictures are available here

Purpose

The library takes care of the details on sending colour commands. It is supposed to be educational, and is therefore written in Python. The library is fast enough to produce nice colour effects on a 300 LED strand, even though it is running via the Python interpreter. However, if you need something really fast, e.g. to drive a small "display" based on APA102 LEDs with 15 frames per second, then you have to look elsewhere.

Prerequisites

  • A Raspberry Pi, running an up-to-date version of Raspbian / Raspberry Pi OS (32 or 64 bit edition). To date, Raspberry Pi OS, December 2023 (based on Debian bookworm) is out, and the library works fine with this release. It should run on all Raspberry Pi models, from Zero to 5. Note that I did not test older models in a long time, so there are no guarantees.
  • If hardware SPI is used: SPI enabled and active (raspi-config, Interface Options, SPI, <Yes>); The SPI must be free and unused.
  • For software SPI (bit bang mode): Two free GPIO pins
  • Three libraries from Adafruit: Adafruit-Blinka, adafruit-circuitpython-bitbangio, and adafruit-circuitpython-busdevice. These libraries will be installed automatically if you follow the steps in Use the APA102 project as a library.

For a permanent installation, a 10$ Raspberry Pi Zero W can be dedicated to the task of driving the LEDs. The connector to the LED stripe would be soldered directly to the correct ports on the board. For development purposes, a Raspberry Pi 4 Model B is a better choice due to its greater speed. Even the 1GB model is more than enough for this purpose.

Wiring

The Raspberry Pi is a 3.3 volt device, and the APA102 LEDs are 5 volt devices. Therefore, it is possible that the first LED driver chip does not properly detect the 3.3 volt SPI signal from the Raspberry Pi.
The first chip will amplify the signal to 5 volts before passing it on, so it is really only the first chip that must detect the 3.3 volt signal.
To avoid this risk, use a 74AHCT125 or 74AHC125 level shifter for both the clock and the MOSI signal. In my limited testing with four different stripes from various Chinese sources I had no issues without a level shifter, but your experience might be different.

Without a level shifter, the wiring is very simple:

  • LED ground to one of the Raspberry ground pins
  • LED Data to Raspberry SPI MOSI
  • LED Clock to Raspberry SPI SCLK

A note about "chip select": The Raspberry Pi's SPI0 bus has two hardware Chip Select pins: CE0 and CE1. They correspond to the devices /dev/spidev0.0 and /dev/spidev0.1. A typical SPI device has one Chip Select input line. So, on a stock Raspberry Pi one can connect two SPI devices: Both share SCLK, MOSI and MISO, and each one uses its own Chip Select. You might be wondering where the Chip Select input line is on an LED strip. Answer: There is none. You therefore can't disable the Strip from reading data on SCLK/MOSI, at least not without additional hardware. For example, you can wire the chip select GPIO of the Raspberry Pi to the level shifter "output-enable" pin.

The Adafruit library does not use or support the hardware chip select pins of the Raspberry Pi. Instead, any free GPIO pin can be used. Because this is multiplexed in software, it is very slow. The feature supports e.g. sensors, where you have a lot of them (more than two), and each sensor only sends or receives a limited amount of data.
The apa102-pi library attempts to use this software multiplexing if a CE value is passed on driver initialization. The strip will update a lot slower if this is used. It is still a bit faster than bitbang, though. Please note that I have not tested this feature, because I never assembled the hardware required for this.

The LED strip uses a lot of power (roughly 20mA per LED, i.e. 60mA for one bright white dot). If you try to power the LEDs from the Raspberry Pi 5V output, you will most likely immediately kill the Raspberry! Therefore, I recommend not to connect the power line of the LED with the Raspberry. To be on the safe side, use a separate USB power supply for the Raspberry, and a strong 5V supply for the LEDs. If you use a level shifter, power it from the 5V power supply as well.

Having said this, you can power the Raspberry from the same power supply as the LED stripes (instead of using an extra USB power supply). If you decide to do this, make sure to never plug a USB power supply to the Raspberry Pi, or you risk that the LEDs try to take power through the Raspberry.

All combined, this is my extremely low-tech wiring diagram:

Wiring Diagram

And here it is, the finished contraption running a "rainbow" program:

Raspberry Pi Zero driving APA102 LEDs

This is a Raspberry Pi Zero W with a Phat Beat amplifier on top. The amplifier's "VU meter" is simply a bunch of APA 102 LEDs; They show the "Rainbow" color scheme:

Raspberry Pi Zero W with Phat Beat

Plugged into the USB port is a WLAN stick (nowadays I use a Raspberry Pi Zero W, of course). This way I can reprogram the light show from my desk, even if the strips sit outside as a Christmas light. Compare this to an Arduino/WS2812 based installation: To reprogram one has to take the Arduino inside, or a laptop outside.

This is a Raspberry Pi 4 with a 3D RGB Xmas Tree from Pi Hut:

Raspberry Pi 4 with Xmas tree

Quick Raspberry Pi setup

Because the Raspberry Pi Zero runs headless, I recommend using the Raspberry Pi OS Lite image. This image only contains the bare minimum of packages, and some packages have be added manually.

I suggest to use the Raspberry Pi Imager for installation. This software allows to setup hostname, WiFi and enable SSH without further work. The Raspberry Pi will run headless from the start, and there is no need to ever connect a display or a keyboard.

After installation, ssh into the freshly setup Raspberry Pi and install additional packages. Also, enable SPI:

  • Update your installation (sudo apt update && sudo apt -y upgrade).
  • Install packages: sudo apt install -y python3-pip python3-venv python3-rpi.gpio
  • Activate SPI: sudo raspi-config; Go to "Interface Options"; Go to "SPI"; Enable SPI; While you are at it: Do change the default password! Exit the tool and reboot.

Use the APA102 project as a library

The library was originally built as an educational piece of software. It shows how the protocol for APA102 LEDs works. Most of this is explained in the form of comments in the source code. If you are interested in this, then follow up with the chapter after this one. If all you need is the library itself for your own projects, then this chapter is enough to get you started.

Install the library like this: sudo pip3 install apa102-pi. This will install the library, and its dependencies for all users.

Note: If you want to install the library into a virtual env, you must create the venv with the option --system-site-packages. This is necessary to get access to the shared RPi.GPIO library.

To verify the installation, download the test script from Github: curl https://raw.githubusercontent.com/tinue/apa102-pi/main/runcolorcycle.py -o runcolorcycle.py. To run, type python3 ./runcolorcycle.py.

Full installation into a Python virtual environment

To retrieve the full library including source code, and use a virtual env in the process, this is what you need to do:

  • Install the git client: sudo apt install -y git
  • Create a development directory and change into it: mkdir ~/Development && cd ~/Development
  • Get the APA102 Library and sample light programs: git clone https://github.com/tinue/apa102-pi.git && cd apa102-pi
  • Create the virtual environment: python3 -m venv --system-site-packages ./venv
  • Activate the virtual env: source venv/bin/activate
  • Install the dependencies: python -m pip install . (this will also install the library itself from the checked out source)
  • To remove the just installed library, and use the source code instead, do this: python -m pip uninstall apa102-pi
  • You might want to set the number of LEDs to match your strip: nano runcolorcycle.py; Update the number, Ctrl-X and "Yes" to save.
  • Run the sample lightshow: ./runcolorcycle.py.

Full installation using Ansible

If you know Ansible, you can use the role apa102_install from directory AnsiblePlaybook. This role installs everything that is outlined in the chapter above automatically. Once the role has executed, you can ssh into the Raspberry Pi, activate the venv and run the sample program.

Troubleshooting

Strip remains dark

The number one reason for this problem is that MOSI and SCLK are swapped. You can't rely on the colors of the wires, they seem to change with every batch of APA102 strips that are produced. To resolve, swap the two data wires and try again.
If it still does not work, then you might need a level shifter. Before you do this, you can try to lower the supply voltage for the strip. According to the APA102 data sheets, a "one" signal is detected as a percentage of the supply voltage: The lower the supply voltage, the higher the chance that 3.3 Volts is still detected as a "one".

Flicker

Sometimes the end of large stripes flickers. It seems that there is a correlation amongst three variables:

  • SPI bus speed
  • Overall brightness of the strip
  • Length of the strip

It turns out that you can only have two out of three: On a long, bright strip you will have to lower the bus speed significantly.
Check the apa102.py driver: Default is 8MHz (BUS_SPEED_HZ = 8000000). You may have to go as low as 1.5MHz, i.e. BUS_SPEED_HZ = 1500000. This means that all light programs with lots of updates and zero wait (e.g. rainbow) will run much slower.

Brightness

There is a default global brightness value in the driver itself (apa102.py, line 90). Of this parameter, the LED controller chip interprets only the first 5 bits, snd ignores the rest. Therefore, everything >= 31 is 100% brightness. The value is set to 1/8th of the maximum (i.e. 8), and can be changed either by patching apa102.py, or by setting the value from your application. Check sample.py to see how this is done.

Release history

  • 1.0.0 (2015-04-13): Initial version
  • 1.1.0 (2015-12-04): Add documentation
  • 1.1.1 (2015-12-11): Rewrote the examples, driver itself is unchanged
  • 1.2.0 (2015-12-17): Fixes for reported problems; Update all of the color samples; Decouple number of steps from number of LEDs
  • 1.3.0 (2016-03-25): Merged changes from @kapacuk: Allow stripes with different color coding than RGB
  • 1.3.1 (2016-03-27): Merged 'rotate' method from @kapacuk; Fixed errors from previous merge
  • 1.3.2 (2016-12-25): Fixed error related to 'rotate'; Removed annoying messages on console; Added a debug method
  • 1.3.3 (2017-04-14): Merged pull request #19 from @DurandA; Cleanup; Update README.MD, No functional changes
  • 1.4.0 (2017-04-16): Update code to better comply with the Python style guide (PEP 8); Merged pull request from @jmb
  • 1.4.1 (2017-08-26): Tested with Raspbian Stretch; Update Readme.
  • 2.0.0 (2017-11-05): Exchanged the SPI library to Adafruit_Python_GPIO. This allows to support devices that do not use hardware SPI, for example the Pimoroni Blinkt! or the Phat Beat.
  • 2.0.1 (2018-01-19): Tiny release: Added a sample
  • 2.0.2 (2018-05-25): No change in the driver; Slight restructuring of the templates and schemes to allow easier change of the SPI pins; Additional sample specific to the the Pimoroni Blinkt!
  • 2.1.0 (2018-06-08): Make the library installable
  • 2.1.1 (2019-03-15): Enable Chip Select (thanks @grandinquisitor); Simplify installation (thanks @nielstron)
  • 2.2.0 (2019-03-16): First version that is available on PyPi (pip 3 install); Renamed package for compliancy with PEP 8.
  • 2.2.1 (2019-09-20): Nothing new, just a re-test of the library with Raspbian Buster
  • 2.3.0 (2019-11-24): Untested fix for SK9822 type LEDs; Fix name space; Update readme. Note: The namespace fix breaks compatibility with the previous version, hence the minor upgrade in the version number.
  • 2.4.0 (2020-05-28): SPI: Switch from the deprecated Adafruit_GPIO to the Adafruit CircuitPython libraries; Re-test with Raspberry Pi OS 2020-05-27.
  • 2.4.1 (2020-12-04): Remove global brightness parameter from the constructor; Re-test with Raspberry Pi OS 2020-12-02 (kernel 5.4) and latest Adafruit libraries. Fix default global brightness: The "conservative" value of 31 was actually 100%, because this is a 5 bit value. Also changing the branch names in Github to reflect current standards.
  • 2.5.0 (2021-12-27): Add methods get_pixel and get_pixel_rgb, support to use all hardware SPI buses on RPI 4 (by explicit choice between hardware spi and bitbanging), thanks @KAN-PC046! Test with Raspberry Pi OS bullseye and Python 3.9. Add instructions on using a virtual env. Note: The interface changes, so the minor version is getting increased.
  • 2.5.1 (2023-01-14): Really tiny release: One bugfix (thanks @leewillis77); Use logging instead of writing to console to reduce output.
  • 2.5.2 (2024-01-26): Change in packaging to allow installation via Ansible; no change in the library. Also, re-test with Pi 5 and latest Raspberry Pi OS.

apa102-pi's People

Contributors

duranda avatar grandinquisitor avatar jackylemur avatar jan-ferdinand avatar jmb avatar nielstron avatar rubenmomoa avatar tibbon avatar tinue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apa102-pi's Issues

User hardware SPI

I just can't get it to work

My Raspi 3 B v1.2 says

use hardware SPI

when I try to run the .py script

I did enable SPI in the config

pi@ledstripe:~ $ python3 ./runcolorcycle.py
Three Seconds of white light
Use hardware SPI
Go twice around the clock
Use hardware SPI
One strandtest of red, green and blue each
Use hardware SPI
One slow trip through the rainbow
Use hardware SPI
Five quick trips through the rainbow
Use hardware SPI
Finished the test

Rainbow corruption?

Hello,
I'm not a python expert, so me trying to follow the code isn't going exceptionally well after 3 days.

Is there a chance that the rainbow function sends corrupted data to LEDs beyond 255? I have 4 reels of 150 LEDs. All the other functions work well, but that slow trip through the rainbow... the end gets all flickery. I've put in the 3.3V to 5V signal converter, and I have 5V at the junction between every reel.

I've put debug statements in the rainbow colorscheme to print out the values being set, but I just can't seem to understand them other than led_index_rounded_wrapped never gets above 255.

Thanks much!

Constant lights

This isn't really an issue but I could not find a way to message you! Sorry!

I was wondering if there is a way to have my LED strip constantly illuminated or for example have a constant rainbow cycle going. I have created a webserver to control the strip but now I need to figure out the Dotstar side of the programming and I am a little confused. I just need it to have a constant color across the whole strip and a cycle infinitely looping.

Any help is greatly appreciated, thanks!!!

LED remaining dark

Hello everyone,

I am currently unable to control my LEDs even though it should work just fine as I double checked the wiring, energy supply and code.
While debugging Ive encountered something strange. I was trying to run "sample.py" (only changed led count so it fits with my strip) and while debugging I realized that when inside "strip.show()" there should be data that is send but there simply is none. I theorized that the problem could lie within the MOSI or SCLK Pins (10 and 11) but that doesnt seem to be the problem either unless im missing something. When going to line 355 in apa102.py to the "send_to_spi" method it is said to output data to the chosen SPI device. Im not sure if it is supposed to skip everything and end up in "else" but I feel like there is something wrong here. If anyone has any ideas please feel free to share them thank you.

Trying to modify the code as a northern lights show.

Hello, and first of all i ask apologize to the creator of this, that i am representing this as an issue, but i am really trying to get some help with this code and library, to modify or rewrite as a northern light show, so please for any idea, advice or hint would be very much appreciated.
Thank you in advance.

A level shifter is not needed

Just wanted to let you know, a 4.5V regulator is build in the APA102.
So if you skip the 74AHCT125/74AHC125, the first LED will act as one.

Love your library, thank you for your work.

python 3.8 vs. 3.5

Whats the fastest way to install it with python 3.5? I don't want to install python 3.8.
Which one is the last version that supports 3.5 and the dependencies are also 3.5?

SPI closed?

I have tried this wired up to a logic converter and directly interfacing the MOSI and CLOCK pins to the LEDs on a Raspberry Pi 3 -- If I try the Adafruit libraries it runs, but nothing happens. If I try running your program I get the following error message and then it shuts down.

I have enabled SPI through raspi-config and by manually loading with sudo modprobe spi_bcm2835 (which runs without errors) -- I tested the SPI with a C program and it is sending and receiving signals...

Any ideas?

Shutdown not implemented Strip cleared SPI closed

Should I make a pull request for features I have added?

I have been using the APA102_Pi library for a project and have added some new capabilities to it, and I have more features that I plan adding as I have motivation.

I am not sure which of my changes would be beneficial to create pull requests for. Here is a link to the branch with the changes. Let me know what you think about it and what I should make pull requests for.

I have a web interface that I use to send JSON messages to the Pis with the strips. I am working on cleaning it up and will probably post to GitHub if there is interest.

connecting APA102 LED and BSS138 level shifter

I am having trouble getting my APA102 LED to work with a BSS138 level shifter. The APA102 LED has four wires (5V, GND, DI, and CI) and the BSS138 level shifter has ten wires (Hv, B1, B2, B3, B4, GND, LV, A1, A2, A3, A4). I am using a Raspberry Pi 4 as my controller.

I have followed the following steps to connect my APA102 LED and BSS138 level shifter:

  1. Vcc (5V) from APA102 LED is connected to Hv on BSS138 level shifter.
  2. GND from APA102 LED is connected to GND on BSS138 level shifter on the HV side.
  3. DI from APA102 LED is connected to B1 on BSS138 level shifter.
  4. CI from APA102 LED is connected to B2 on BSS138 level shifter.
  5. 3V from Raspberry Pi 4 is connected to LV on BSS138 level shifter.
  6. GND from Raspberry Pi 4 is connected to GND on BSS138 level shifter on the LV side.
  7. GPIO 20 from Raspberry Pi 4 is connected to A1 on BSS138 level shifter.
  8. GPIO 21 from Raspberry Pi 4 is connected to A2 on BSS138 level shifter.

I have also tried using the following code to control the LED:

from apa102_pi.driver import apa102
import signal
import sys
import time
import random

strip = apa102.APA102(num_led=5, order='rgb')

# Define a function to handle `Ctrl+C` signal
def signal_handler(sig, frame):
    strip.clear_strip()
    strip.cleanup()
    sys.exit(0)

# Register the `Ctrl+C` signal handler
signal.signal(signal.SIGINT, signal_handler)

def all_led():
    strip.set_pixel_rgb(0,  0x0000FF)
    strip.set_pixel_rgb(1,  0xFF0000)  # Red
    strip.set_pixel_rgb(2, 0x00FF00)  # Green
    strip.set_pixel_rgb(3, 0x00FF00)  # Green
    strip.set_pixel_rgb(4, 0x0000FF)  # Blue
    strip.set_pixel_rgb(5,  0x0000FF)
    strip.show()

def blink_all():
    for i in range(5):
        color = random.randint(0, 0xFFFFFF)
        strip.clear_strip()
        for j in range(5):
            if i == j:
                strip.set_pixel_rgb(j, color)
            else:
                strip.set_pixel_rgb(j, 0x000000)
        strip.show()
        time.sleep(0.5)

try:
    while True:
        all_led()
        time.sleep(1)
        blink_all()

except KeyboardInterrupt:
    # Turn off the LEDs and cleanup the GPIO pins when
        strip.clear_strip()
        strip.cleanup()

Note: Led works fine without using bss138 level shifter.
Can anyone provide some guidance?
Thank you for your help

LED Colour

Is there a way I can make all the LEDs turn a specific colour, for example red.

Bit Banging Not Working

Hi

I'm having problems driving APA102 LED using the second SPI port (GPIO20 (pin 38) & GPIO21 (pin 40)) on a Raspberry Pi 4 v1.4 using Bullseye OS 64 bit. Second SPI port activated in config.txt as dtoverlay=spi1-1cs.

I used to be able to use the second SPI port on previous versions of Raspian (not used APA102 in quite a while now), but now I can't.

I changed the mosi and sclk to use the second SPI port, but it ignores the bit banging and uses the first SPI port (GPIO10 & GPIO11) instead.

strip = apa102.APA102(num_led=5, mosi=20, sclk=21, order='rgb') # Initialize the library and the strip
strip.set_global_brightness(2)
strip.clear_strip()

Does anyone else have this problem?

Lee

Change GPIO Output

Hey i am new to this.
is it possible to change the GPIO output?
Because in addition to dotstars i have hyperion running and hyperion is using these pins.
Adafruits Raspberry Library is doing it like this:

import time
from dotstar import Adafruit_DotStar

numpixels = 64 # Number of LEDs in strip

Here's how to control the strip from any two GPIO pins:
datapin = 23
clockpin = 24
strip = Adafruit_DotStar(numpixels, datapin, clockpin)

Could you explain how to change it in your code?

feature or bug print statements

When starting the driver in def init the type of interface is always printed. It would be nicer if you could add an debug flag or something like that to suppress the printing.

`

Debug

    if self.use_ce:
        print("Use software chip enable")
    if self.use_bitbang:
        print("Use bitbang SPI")
    else:
        print("Use hardware SPI")

`

global_brightness range

Hi. Thanks for putting together such an awesome library! What is the acceptable range for global_brightness? Is it 0-255?

Running sample with a single LED

Firstly, thank you so much for building this library!

I have an APA102 LED that I soldered to a breakout board and wired to a breadboard following the diagram provided in your repo. I'd like to be able to set the color and brightness of just this one LED, but haven't been able to so far.

I thought maybe there was an issue with my soldering, but I soldered and tested 3 different LEDs. For each one, if I execute python3 runcolorcycle.py I can see the single led lighting and changing very dimly so I don't think it's an issue with my soldering.

Ideally I'd like to be able to execute python3 sample.py and the LED turn on for the duration of time.sleep(), but that has also been ineffective. I have a feeling there's something conceptually I'm missing in order to get this to work.

Here's how I modified the code of sample.py

#!/usr/bin/env python3
"""Ultra simple sample on how to use the library"""
from driver import apa102
import time


# Initialize the library and the strip
strip = apa102.APA102(num_led=1, global_brightness=10, mosi=10, sclk=11, order="bgr")

# Turn off all pixels (sometimes a few light up when the strip gets power)
strip.clear_strip()

# Prepare a few individual pixels
strip.set_pixel_rgb(0, 0xFF0000)

# Copy the buffer to the Strip (i.e. show the prepared pixels)
strip.show()

# Wait a few Seconds, to check the result
time.sleep(5)

# Clear the strip and shut down
strip.clear_strip()
strip.cleanup()

Am I making any sort of mistake here? I can provide a wiring diagram for my LED (which includes a level shifter for the data and clock lines).

Thanks again!

RaspberryPI setup

Great work. I've replicated the setup and now experimenting. A couple of issues:

  1. The Raspian comes pre installed with Python2 and 3. This code and SPIDEV is for Python2 which is the default runtime.
  2. More of a SPIDEV issue is that aprt from the black list, the boot/config file also requires modification before SPI becomes available.
  3. Could do with a wiring diagram, in particular for the shared ground and the PIN's on the GPIO for newbies such as myself.

Thanks again

Justin

spi.max_speed_hz should be parameterized

This library works very well on the C.H.I.P. but I had to reduce the spi speed to 500 KHz. Would you accept a pull request which add max_speed_hz=8000000 to the APA102 constructor?

Side node: snake_case is recommended for variables and function names; see PEP 8.

Power the Pi from same power supply as LEDs, but through USB Port?

Hi,

I am currently ordering stuff to recreate your build, in form of a 16x16 LED matrix. I want to power the LEDs and the Pi from the same power supply. I also will use the same logic level power converter as you do. Could you help me? I wonder if it is hazardous for the Pi to be powered via a cut-off micro-USB cable that is attached to the same power supply as the LEDs. Of course, VCC on the level converter would still get its 5 volts from the supply - NOT from the 5V Pi-pin.

I have yet to find an instruction that does this setup. All I can find either power the Pi over its 5v pin (which is said to be unsafe because there are not protective circuits), or by a separate power supply.

I want both: safety by the USB circuits AND only one shared power supply. Yet I do not want to kill the Pi.

Best regards, you have done great work there!

package installation location

When installed via pip:

pip install apa102-pi

the installed libraries end up in the top-level packages driver and colorschemes instead of apa102:

$ ls lib/python3.7/site-packages/driver 
apa102.py  colorcycletemplate.py  __init__.py  __pycache__

These should probably be in an apa102 package to avoid namespace conflicts.

Software SPI (Bit Bang) informations

Hi,
Can you please provide more informations in your setup section about how to activate Software SPI mode?
I've also seen in the driver module that mosi and sclk are hard codded. Can you explain how to change it in order to use the Software SPI instead of the Hardware SPI?
Thanks a lot for the job you've made, and thank you for your reply.
Regards.
Edit : I've seen in #3 that you had issues with Software SPI. In my project, there is only one LED to manage. Can you think that there will be disturbances?

All LEDs just turn white

Hey,

tested your library to get my dotstar leds working but they're just turning all white as soon as I start you program or any other way of setting the color (e.g. strandtest.py). They are RGB LEDs and working because if I connect them to my pi sometimes they are randomly red, green, blue or white.
Do you guys have any idea why they're turning white? I'm using a 3.3V to 5V converter.
PS: I'm using a RPi2 and 240 LEDs

Thanks for your help

Raspberry pi 3 apa102 ambilight

Open this img

Will this work?
I do know the grapper, av converter and splitter they are right. And connect led strip to pi.

Extra parts:
12v to 5v 3a: https://www.ebay.de/itm/263062629260 (Extra question does it have to come from at power supply that has 12v 3a? Or is it ok with 12v 1.2a?)
Usb Hub: https://www.ebay.de/itm/302471693929
Hdmi Splitter: https://www.amazon.de/gp/product/B019MRGGJU/ref=ox_sc_act_title_1?smid=A2YXN6MAL2SF51&psc=1
Av Converter: https://www.amazon.de/gp/product/B01EIY768C/ref=ox_sc_act_title_3?smid=AGJ2TI2R2YFK8&psc=1
Grabber: https://www.amazon.de/gp/product/B0013BXFLG/ref=ox_sc_act_title_4?smid=A3JWKAKR8XB7XF&psc=1
Strips APA102: https://www.ebay.de/itm/222180982345?var=521020771678 (1m x2)

Any recommendations please tell, and im running on budget.
(Sorry if English is bad at some points)

Use hardware SPI in Rasberry Pi 3 model B

Hey everyone,

I am using Raspberry pi 3 model B and below I am showing my output while running program.

pi@raspberrypi:~ $ python3 ./runcolorcycle.py
Three Seconds of white light
Use hardware SPI
Go twice around the clock
Use hardware SPI
One strandtest of red, green and blue each
Use hardware SPI
One slow trip through the rainbow
Use hardware SPI
Five quick trips through the rainbow
Use hardware SPI
Finished the test

I am getting this output but in my led nothing is happening. I have tried changing the pins green and yellow I am not getting any results. Can you please help me where I am wrong?

Thanks in advance.

control each led

hello,
I have 7 x 5 meter Led strips which I want to control with the help of Raspberry Pi 3.
I have mounted the led strips on my window frames. I want to control the upper row from the window alone, the lower row as well as the inner row from the window.
My question is how can I drive a single led?
For example, I want to make Led number 12 glow red, Led number 24 white and Led number 40 green.
How can I number the Leds and enter them in a Tabe?

Thank you in advance

Using Aurora to control APA102

Hi. I want to use Aurora to control the LED Strip instead of manually change the colour. As you see HERE, there are two tutorial on how to do it. I already follows the 2nd guide which he use LPD8806, but it didnt work on my APA102 (obviously).

The 1st guide is using python aurora_neopixel_pi.py instead of java to run the SPI right? can u help me change the code to match with APA102 instead of NeoPixel which is PWM driven? I'm so bad at programming, and eagerly want to learn, but dont know where to start.

[Q] SK9822 support

Hello.

Does the library supports also SK9822 LED strips?
They are better then APA102, but has a slightly different communication.

Also does anyone tested strip with 600LEDs? We plan to use 20m * 30LED strip controlled by Raspberry.

Thank you :)

Small bugs in the code

Hi,

I'm starting a simple Raspberry + APA102 project myself. And found your code, it's a really nice starting point for me, tnx for that.
I played a bit with it last night, and found 2 small bugs in your code:

  1. In the clearstrip method (https://github.com/tinue/APA102_Pi/blob/master/apa102.py#L102) you forgot to send the clock startframe self.clockStartFrame(). The leds didn't clear for me without this.
  2. In the paint loop (https://github.com/tinue/APA102_Pi/blob/master/colorcycletemplate.py#L65) you increment the counter before checking, so you should do a check only on greater than. not equal: if (currentStep > self.numLEDs): I guess this isn't really noticable on a led strip. However I'm working with single leds (making a ledmatrix myself) and when I tested the code with 1 led the update method didn't work.
  3. The same issue is with the check on the cycles (https://github.com/tinue/APA102_Pi/blob/master/colorcycletemplate.py#L69): if (currentCycle > self.numCycles): break, however I didn't check it.

If you'd like I can create a pull request tonight.

Not Fast enough

Thank you for your library , it makes things easy for us , but i have a problem i would be grateful if you could help me to solve it , I am building a POV Display project , My motor is turning 25 spin per second (1500 RPM) , there is 64 LEDs of HD107S (same to APA102 but have much higher addressing frequency "30 Mhz" ) , the problem is the speed of scaning is not fast enough, therefore I see lines and not dots , even I tried to turn the frequency up To 24 MHz ,It seems that the best result i can reach is at 8 Mhz , after that all frequency give same results , What wrong ?!! it seems that the library stuck at ~ 8 Mhz !!

Untitled - Copy
24_frqs_From_video4

Testing the Dotstar library give better result , but i didn't find how to change frequency yet , it will be easy for me working with your library because the frequency is easy to change , i hope you find solution to the problem .

Dotstar VS Apa102-pi lib

Apa102-pi loop :

while 1:
if GPIO.input(15) == GPIO.HIGH:
strip.set_pixel_rgb(30, 0x00000F)
strip.show()
strip.set_pixel_rgb(30, 0x000000)
strip.show()

Dotstar loop :

while 1:
if GPIO.input(15) == GPIO.HIGH:
pixels[30] = (10, 0, 0)
pixels[30] = (0, 0, 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.