#Purpose
- This program lets your Raspberry Pi control control RGB LEDs.
#Features
-
Color correction. Some RGB LED strips have imbalanced LEDs, and this program allows you compensate by reducing brightness on any color channel.
-
Simple file-based API. During continuous operation, simply put your desired target color into a CSV file containing RGB values ranging from 0-255, and the program will implement your target color. Change it as often as you like.
-
Transition options. You can fade from the current color to the target color directly, by fading to black and then fading to the target color, or by changing to the target color instantaneously. You can change these preferences on the fly.
-
Integration with openHAB via the
execbinding.
#HOWTO
##What You Need
-
Raspberry Pi (Rev B tested, but any revision should work.)
-
An RGB LED strip (I bought this one, but any 4-pin common-anode RGB LED strip will work. Deviations will work, but you'll need to come up with your own wiring diagram.)
-
A DC power supply (My strip is 12VDC, with a maximum current of 0.6A, and I have a 12VDC 8.5A power supply.)
-
Three MOSFETs (I used these N-channel MOSFETs. Deviations can work, but you'll need to come up with your own wiring diagram.)
-
Three free GPIO pins
-
At least 60% available CPU on your Pi
-
Basic Linux skills (package installing, file copying and editing, running commands)
##Hardware Setup
-
Wire up your MOSFETs and RGB LED strip as you see on the first diagram in this Adafruit tutorial for the Arduino, except that:
-
You have a Pi, not an Arduino, but the basic principle is the same.
-
You power the LED strip with your dedicated power supply, not any pin from the Pi.
-
You will run a ground wire from your Pi to the ground terminal of the power supply.
-
Pick three GPIO pins to control red, green, and blue. Read the pigpio documentation carefully before picking your pins. If you get this wrong, various bad things can happen.
-
##Software Setup
-
As shown here, download, build, and install
pigpioon your Raspberry Pi, then start thepigpiodaemon.-
Download, build, and install.
wget abyz.co.uk/rpi/pigpio/pigpio.zip unzip pigpio.zip cd PIGPIO make make install -
Start the pigpio daemon.
sudo pigpiod
-
-
Install, configure, and run Hugh.
-
Copy the Hugh directory tree to your Pi. Mine is in
/home/pi/hugh -
Edit
hugh_config.inito match the BCM-indexed GPIO pins that you chose above. -
Run Hugh from its directory:
cd /home/pi/hugh sudo python ./hugh.py -
Any edits to the files
hugh_config.iniorrgbwill be loaded and quickly implemented by Hugh.
-
##openHAB Integration (optional)
- My solution builds on this example for KNX and this example using MQTT.
###items
-
Add this
Coloritem to any of your *.itemsfiles, which gives you a color picker UI.Color HSB "Color Light" <slider> (Lights) -
Add a
Stringitem to any of your *.itemsfiles, as your interface to the Hugh software running on your Pi.-
If the Pi running Hugh is also your openHAB server, add this:
String RGB "RGB Value" { exec=">[*:echo %2$s > /home/pi/hugh/rgb]" }
-
Otherwise, add this entry:
String RGB "RGB Value" { exec=">[*:ssh pi@pi2 echo %2$s > /home/pi/hugh/rgb]" }
-
-
DON'T put
RGBitem into any groups or sitemaps. It's not something that users should directly interact with. -
Put the
HSBitem into any groups and sitemaps you prefer. The reference example assumes you want it in theLightsgroup. -
Edit the
RGBitem to match the device name, username, and target directory for Hugh's RGB file.
###rules
-
Add this rule to any of your *
.rulesfiles. This converts the HSB (hue, saturation, brightness) color to comma-separated RGB (red, green, blue) values, and puts them into theRGBStringitem, which in turn gives the RGB values to Hugh.rule "Set RGB Value from HSB" when Item HSB changed then var HSBType hsbValue = HSB.state as HSBType // scale the values to 256 levels var int red = Math::round(hsbValue.red.floatValue * 2.55) var int green = Math::round(hsbValue.green.floatValue * 2.55) var int blue = Math::round(hsbValue.blue.floatValue * 2.55) sendCommand(RGB, red+","+green+","+blue) postUpdate(RGB, red+","+green+","+blue) end
###SSH
-
If the Pi running Hugh is also your openHAB server, then you can skip this step. Otherwise:
-
As the
rootuser, generate an SSH keypair on your openHAB server with an empty passphrase. -
On the Pi, as a regular user (e.g.
pi), append the public key to~/.ssh/authorized_keysin the user account on the Pi (e.g./home/pi/.ssh/authorized_keys) to allow your openHAB server to automatically log in when it runssshvia theexecbinding in theRGBitem.
-
###usage
- openHAB will pick up on the
itemsandruleschanges. You should be able to interact with theHSBcolor picker in any openHAB UI and see the color reproduced by your RGB LEDs.