Introduction: Easiest RGB LED Strip With Raspberry Pi!
If you've looked into driving RGB LED strips from your raspberry pi, you may have found it to be more effort than you were willing to put in to it. Either you had to build a driver from scratch with transistors, or you needed to modify the circuitry of a mini amplifier to make sure it didn't blow up your Pi.
Well, now you don't have to - there's a plug and play solution, thanks to a fortuitous discovery about a particular model of RGB LED amplifier.
This is the kind you DON'T want: very cheap, highly tempting mini amplifiers, such as https://www.amazon.com/FAVOLCANO-Amplifier-Control...
They have a fatal flaw - the +12V input pin is connected to the +12V output pin. Connect it to your Pi and you'll blow up the Pi.
This is the kind you DO want: slightly more expensive and larger: https://www.amazon.com/TSSS-Repeater-Signal-Amplif... (Cost - $5.75!)
These ones do NOT connect the input and output 12V pins and are safe to drive directly from the +5V pin on the Pi and the GPIO output pins. (Though just to be sure in case there's ever a new design using the same packaging, check that for yourself with an Ohm meter)
Step 1: Connecting Is Trivial!
Connect the +5V pin of your Pi to the +12V input of the amp with a male-female jumper lead.
Connect 3 GPIO pins (GPIO 4,5,6 are a good choice) to the R, G & B inputs of the amp with three male-female jumper leads.
The amp will come with two short connectors for the LED strips. Use one to connect to your LED strip. They'll have color-coded wires - red, green and blue plus one other for the power line. (Black, in my case)
Step 2: Now Test It...
You will need the "pigpiod" system on your pi in order to take advantage of software PWM so that you can drive the LED strips at different intensities. "sudo apt-get install pigpiod" if it isn't already installed.
Go to https://www.raspberrypi.org/forums/viewtopic.php?f... to see how to configure your Pi so that pigpiod starts when you power up.
Here's a shell script that will let you set the LED strip to an arbitrary color:
#!/bin/bash if [[ "$1" == "on" ]] ; then pigs pwm 23 0 pwm 24 0 pwm 25 0 else if [[ "$1" == "off" ]] ; then pigs pwm 23 255 pwm 24 255 pwm 25 255 else # trying to compensate for eye's log response to brightness # tmpR=`echo 'scale=4; (e(l(2) * (((100 - '$1') * 8) / 100))-0.01)' | bc -l` # tmpG=`echo 'scale=4; (e(l(2) * (((100 - '$2') * 8) / 100))-0.01)' | bc -l` # tmpB=`echo 'scale=4; (e(l(2) * (((100 - '$3') * 8) / 100))-0.01)' | bc -l` # but simple linear seems to work better :-( tmpR=`echo 'scale=4; ((100-'$1')*255/100)' | bc -l` tmpG=`echo 'scale=4; ((100-'$2')*255/100)' | bc -l` tmpB=`echo 'scale=4; ((100-'$3')*255/100)' | bc -l` # convert to integer tmpR=`echo 'scale=0; ('$tmpR'/1)' | bc -l` tmpG=`echo 'scale=0; ('$tmpG'/1)' | bc -l` tmpB=`echo 'scale=0; ('$tmpB'/1)' | bc -l` # echo "RGB: "$tmpR $tmpG $tmpB pigs pwm 23 $tmpR pwm 24 $tmpG pwm 25 $tmpB fi fi
Call it "ledstrip" and use it like this: ledstrip 50 50 0
The 3 parameters are the values of R, G & B in a range of 0 to 100.
That's it. Easiest LED strip project ever!