tinue / apa102-pi Goto Github PK
View Code? Open in Web Editor NEWPure Python library to drive APA102 LED stripes; Use with Raspberry Pi.
License: GNU General Public License v2.0
Pure Python library to drive APA102 LED stripes; Use with Raspberry Pi.
License: GNU General Public License v2.0
Is there a way I can make all the LEDs turn a specific colour, for example red.
I'm currently using this library to drive another project, and I would love to be able to use it as an installable Python module via pip
instead of hard-forking it into that project (thanks for being GPL!). With the APA102-containing ReSpeaker 4-mic on the market this might be very helpful for other projects based on that device as well!
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 !!
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 .
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)
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.
Hi. Thanks for putting together such an awesome library! What is the acceptable range for global_brightness
? Is it 0-255?
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.
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!
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
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)
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!
Great work. I've replicated the setup and now experimenting. A couple of issues:
Thanks again
Justin
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!!!
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.
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
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.
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?
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.
`
if self.use_ce:
print("Use software chip enable")
if self.use_bitbang:
print("Use bitbang SPI")
else:
print("Use hardware SPI")
`
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.
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.
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
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?
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?
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 :)
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:
self.clockStartFrame()
. The leds didn't clear for me without this.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.if (currentCycle > self.numCycles): break
, however I didn't check it.If you'd like I can create a pull request tonight.
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!
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:
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
https://github.com/tinue/APA102_Pi/blob/master/apa102.py#L123
i have to swap green and blue here?!
hint: u can precalculate the endFrame in the constructor, so u don't need a loop there
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.
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.