├── LICENSE
├── README.md
├── gui
├── _config.yml
├── android-chrome-192x192.png
├── android-chrome-512x512.png
├── apple-touch-icon-precomposed.png
├── apple-touch-icon.png
├── browserconfig.xml
├── color.txt
├── config.php
├── css
│ ├── animate.min.css
│ ├── bootstrap-toggle.min.css
│ ├── bootstrap.min.css
│ ├── style.css
│ └── wheelcolorpicker.modified.css
├── favicon-16x16.png
├── favicon-32x32.png
├── favicon.ico
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ ├── glyphicons-halflings-regular.woff
│ └── glyphicons-halflings-regular.woff2
├── functions.php
├── index.php
├── js
│ ├── bootbox.min.js
│ ├── bootstrap-notify.min.js
│ ├── bootstrap-toggle.min.js
│ ├── bootstrap.min.js
│ ├── functions.js
│ ├── html5shiv.min.js
│ ├── jquery-1.12.4.min.js
│ ├── jquery.wheelcolorpicker.modified.js
│ └── respond.min.js
├── manifest.json
├── mstile-150x150.png
├── python
│ ├── colorpicker.py
│ ├── config.py
│ ├── dotstar.c
│ ├── dotstar.so
│ ├── functions.py
│ ├── io.py
│ ├── motor.py
│ ├── motor_down.py
│ ├── motor_up.py
│ ├── preset.py
│ ├── reboot.py
│ ├── request_reboot.py
│ └── strip.py
├── safari-pinned-tab.svg
└── submit.php
├── img
├── Installation-example.jpg
├── example-wiring-diagram-v2.png
├── iphone6-mockup.jpg
├── pcb-animated.gif
├── pcb-black-transfer.png
├── rainbow-rgb-led-soffit-lighting.jpg
└── responsive-showcase-mockup.jpg
└── pcb
├── gerbers.zip
└── pcb-black-transfer.pdf
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Dan Jones
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |  [](https://github.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller/graphs/commit-activity) 
2 |
3 |
4 | # Raspberry Pi Relay & APA102 LED Controller
5 |
6 | 
7 |
8 | Raspberry Pi Relay & APA102 LED controller allows control & switching of APA102 addressable LED strips (and LED driver) using a web GUI. Motor controller functionality is also built-in to control hard-wired home automation type blind / projector screen motors. Ideal for use in home cinema applications. Unlike regular "dumb" RGB strips, addressable strips have independently controlled LEDs, allowing for the creation of light effects & sequences.
9 |
10 | 
11 |
12 | ## Features
13 |
14 | * APA102 LED control
15 | * 2x changeover relay control
16 | * 2x mains AC input detection
17 | * Motorised blind / projector screen control
18 | * 2x TTL inputs for external buttons
19 |
20 | ## Motivation
21 |
22 | This project was created for use in my own home cinema build. I wanted a single-room home automation solution that would offer addressable RGB control, with the ability to directly switch a mains AC powered LED driver. Additional relay channels where added to the prototype to allow other circuits to be switched using the controller, such as spotlights. The motorised blind control relays were added into the design during my home cinema build.
23 |
24 | Home cinema build log: https://www.avforums.com/threads/ongoing-plasmadans-living-room-cinema-office-build.1992617/
25 |
26 | ## Responsive Web GUI
27 |
28 | 
29 |
30 | The GUI includes controls for the changeover relay channels, motorised blind / projector screen, a full RGB color picker for the APA102 LEDs and a preset control to cycle built-in light modes / effects. There is also the ability to reboot the Raspberry Pi directly from the GUI, making development & testing easier for your application.
31 |
32 | Built on bootstrap 3; the GUI is fully responsive and adapts to any screen size / orientation.
33 |
34 | ## App Features
35 |
36 | As well as support for mobile devices, the GUI includes modern manifest data to allow it to work more like a native app. This means when you save the GUI to the home-screen it will load & function without an address-bar, just like an app.
37 |
38 | ## Chrome Extension
39 |
40 | The specially created Chrome extension makes the web GUI even easier to use on desktop, allowing for GUI control without the need to leave the current web page. The Chrome extension also provides the ability to map keyboard shortcuts to each function of the web GUI, including toggle on / off, LED preset & blind control.
41 |
42 | https://chrome.google.com/webstore/detail/apa102-led-controller/jnmjhaaahpdapgcddlgaldjhapmoapje
43 |
44 | ## Prerequisites
45 |
46 | Raspberry Pi with Raspberry Pi OS:
47 | https://www.raspberrypi.org/downloads/raspberry-pi-os/
48 |
49 | I recommend a clean install before proceeding.
50 |
51 | ## Dependencies
52 |
53 | APA102 LEDs require the Python port of the Adafruit DotStar library to function. This is included in this repo for completeness.
54 |
55 | https://github.com/adafruit/Adafruit_DotStar_Pi
56 |
57 | ## Build Your Own!
58 |
59 | 
60 |
61 | The hardware for this controller is quite simple, all the components are readily available. If you decide to build one for yourself, I have provided the necessary Gerber files for the PCB. These can either be sent to a PCB manufacturer like [PCBway](http://www.pcbway.com/setinvite.aspx?inviteid=19024), or you can etch the board yourself (see included transfer pdf). The PCB design is single-sided to make it easier to re-create yourself. The PCB was designed to fit into a small case ([CAMDENBOSS 7200-269C](http://camdenboss.com/enclosures/heavy-duty-enclosures/polycarbonate-clear-lid-cases#7200-series-grey-clear200x120x75)). If you require additional inputs / outputs, or want to make any other changes; you may want to create your own PCB instead.
62 |
63 | 
64 |
65 | Parts list: https://goo.gl/5SdG7h
66 |
67 | ## Raspberry Pi Compatibility
68 |
69 | * All except the original Model B (rev. 1) - Although with some changes it can be made to work.
70 |
71 | The PCB design uses a 26-way header (same as the Raspberry Pi model B). A 26-way to 40-way ribbon cable will be needed to work with Raspberry Pi B+ and above.
72 |
73 | ## Wiring
74 |
75 | 
76 |
77 | The controller is designed to work with 4-wire type addressable LED strips; such as APA102 (AKA Adafruit DotStars) or WS2801. Everything else on the controller is pretty-much universal in terms of wiring options. I have provided an example wiring diagram:
78 |
79 | 
80 |
81 | In this example, the LED driver and halogen lighting circuits are linked to the changeover relay channels. This allows for standard 2-way / intermediate (3-way if you're outside the UK) light switches to be used in conjunction with the controller. This means that if the controller went offline for whatever reason, your lights will still work!
82 |
83 | Notice in the example that the switched-line is looped back into the AC detect circuits. This is to allow the Raspberry Pi to sense when the lights / LED driver are powered, regardless of relay / switch positions. If you don't require 2-way control you can disable this in the config.
84 |
85 | # Installation
86 |
87 | Tip: For headless setup, SSH can be enabled by placing a file named 'ssh' (no extension) onto the boot partition of the SD card.
88 |
89 | Update your Raspberry Pi to ensure all the latest packages are installed.
90 |
91 | ```
92 | sudo apt update
93 | sudo apt upgrade
94 | ```
95 |
96 | ## Install Apache & PHP
97 |
98 | ```
99 | sudo apt install apache2 php libapache2-mod-php -y
100 | ```
101 |
102 | Test the webserver is working. Navigate to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on the network. Use the snippet below to get the Pi's IP address in command line.
103 |
104 | ```
105 | hostname -I
106 | ```
107 |
108 | ## Install WiringPi
109 |
110 | ```
111 | sudo apt install wiringpi python-pip -y
112 | sudo pip install wiringpi
113 | ```
114 |
115 | ## Enable SPI
116 |
117 | Needed for RGB LEDs to work.
118 |
119 | ```
120 | sudo raspi-config
121 | ```
122 |
123 | Scroll to "Advanced Options", "SPI", set to enabled.
124 |
125 | ## Install GUI
126 |
127 | You need to clone the web GUI files from the `/gui` subdirectory, to do that we need to install subversion.
128 |
129 | ```
130 | sudo apt install subversion -y
131 | ```
132 |
133 | Empty default Apache files and install GUI.
134 |
135 | ```
136 | sudo rm -rf /var/www/html/*
137 | sudo svn checkout https://github.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller/trunk/gui /var/www/html
138 | ```
139 |
140 | ### Permissions
141 |
142 | Be sure to set file permissions to 755 in the web directory.
143 |
144 | ```
145 | sudo chmod -R 755 /var/www
146 | ```
147 |
148 | Before proceeding, make sure the required scripts run correctly without issue.
149 |
150 | ```
151 | python python/preset.py
152 | ```
153 |
154 | You should see "Preset Button Control Loaded!". Do the same test for motor.py if you require it.
155 |
156 | ```
157 | python python/motor.py
158 | ```
159 |
160 | You should see "Motor Button Control Loaded!".
161 |
162 | Assuming no issues, set these scripts to run automatically at startup.
163 |
164 | Edit rc.local:
165 |
166 | ```
167 | sudo nano /etc/rc.local
168 | ```
169 |
170 | Add before exit 0
171 |
172 | ```
173 | python /var/www/html/python/motor.py &
174 | python /var/www/html/python/preset.py &
175 | ```
176 |
177 | The scripts are independent from each other to allow you to just use what you need.
178 |
179 | ## Optional: Install vsftpd for Easier File Editing
180 |
181 | ```
182 | sudo apt install vsftpd -y
183 | ```
184 |
185 | Change user for vsftpd.
186 |
187 | ```
188 | sudo chown -R pi /var/www
189 | ```
190 |
191 | Edit vsftpd.conf.
192 |
193 | ```
194 | sudo nano /etc/vsftpd.conf
195 | ```
196 |
197 | Uncomment the following line:
198 |
199 | ```
200 | write_enable=YES
201 | ```
202 |
203 | Add the following line:
204 |
205 | ```
206 | force_dot_files=YES
207 | ```
208 |
209 | Save and exit nano, then restart vsftpd.
210 |
211 | ```
212 | sudo service vsftpd restart
213 | ```
214 |
215 | You should now be able to login via FTP.
216 |
217 | ## Config
218 |
219 | There are lots of user customisable options in the config file :```/python/config.py```
220 |
221 | You can customise everything from the GPIO channels used, the layout & language of the web GUI, lighting transition effects, preset modes, button timing and a whole lot more. Get familiar with the config file.
222 |
223 | ## Automation
224 |
225 | To automate blind control actions there are 2 scripts included:
226 |
227 | ```
228 | /python/motor_up.py
229 | /python/motor_down.py
230 | ```
231 |
232 | These scripts simulate a button press for up & down actions. You can use crontab to automatically trigger these scripts at a time of your choosing.
233 |
234 | Run crontab with the -e flag to edit the cron table:
235 |
236 | ```
237 | crontab -e
238 | ```
239 |
240 | The first time you run crontab you'll be prompted to select an editor; if you are not sure which one to use, choose nano by pressing Enter.
241 |
242 | Add your scheduled tasks. For help see here: https://www.raspberrypi.org/documentation/linux/usage/cron.md
243 |
244 | For example, to schedule the blind to open at 7AM and close again at 6:30PM every day you would enter the following:
245 |
246 | ```
247 | 0 7 * * * python /var/www/html/python/motor_up.py
248 | 30 18 * * * python /var/www/html/python/motor_down.py
249 | ```
250 |
251 | ## License
252 |
253 | MIT © Dan Jones - [PlasmaDan.com](https://plasmadan.com)
254 |
--------------------------------------------------------------------------------
/gui/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/gui/android-chrome-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller/f494003e680ca22862e67e3e6af6135cbd2c9c73/gui/android-chrome-192x192.png
--------------------------------------------------------------------------------
/gui/android-chrome-512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller/f494003e680ca22862e67e3e6af6135cbd2c9c73/gui/android-chrome-512x512.png
--------------------------------------------------------------------------------
/gui/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller/f494003e680ca22862e67e3e6af6135cbd2c9c73/gui/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/gui/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller/f494003e680ca22862e67e3e6af6135cbd2c9c73/gui/apple-touch-icon.png
--------------------------------------------------------------------------------
/gui/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 |