PWM with a Raspberry Pi is tricky. There is an official meathod of doing this, but I’ve found that when driving multiple channels (like 3 for an RGB LED) it doesn’t work to well and is noticeably shaky when transitioning to new PWM cycles.
Looking for alternatives, I found pi-blaster. From their github:
This project enables PWM on the GPIO pins you request of a Raspberry Pi. The technique used is extremely efficient: does not use the CPU and gives very stable pulses.
It was pretty simple to create a utility to drive my RGB LEDs with. My code can be found here.
To install pi-blaster for use with this code, you’ll need to download and install like so.
Make sure you are in the same directory as LEDFuns.py
1 2 3 4 5 6 |
git clone https://github.com/sarfata/pi-blaster.git cd pi-blaster sudo apt-get install autoconf ./autogen.sh ./configure make |
The pi-blaster directory should be within the same directory as the LEDFuns.py file.
Thanks for reading! More on this project soon.