Impress Your Friends & Family at Christmas: Control Decorative Lighting Using Webbrowsers
Working video demo of "Decorative Lighting Controller" using LED sequence:
This project permits you control over a sequence of Christmas Lights, for instance a string or sequence of LEDs. You will use a Raspberry Pi to implement control. Alter the blinking sequence opening the webpage DIY taught in this lab manual. Once loaded a web browser, by you can enter the sequence of blinks for desired duration in seconds. For example: 120 blinks in 60 seconds, or 20 blinks in 8 seconds.
By doing this project, you and your student will learn about physical computing with the PiFace Digital. It is a interfacing and breakout board for the Raspberry Pi. It finds use in computers that help implement decisions on physical objects, like lights. Raspberry PiFace Digital allows all this to happen through computer-dependent convenient architectures of communication:
- Internet Networking
- Many Sensor Networking
- High Speed Decision Making
- Visual User Interfaces
The Raspberry Pi was chosen as the embedded computer for this application since is:
- Consumes low power
- Can Network
- Visually Show on Screen
- Supported by Online Help Community
- Compatible to Execute All Programming Languages
Its architecture of a computer and not microcontroller endows it boadest applicability in embedded computing applications.An advantage of the Raspberry Pi is that it is capable of interfacing with the PiFace breakout board. The PiFace is what allows the Raspberry Pi to "talk" to the real world. Through software running on the Raspberry Pi, input pins can be read and output pins can be switched on and off. It even has relays for controlling high current loads. All the software included in this project is written in Python. This language was chosen because it is friendly and less obscure syntax with high usability. Python has libraries that handle the HTTP requests as well as libraries that allow easy control of the PiFace.
The project begins with an simple HTTP server written in Python running on the Raspberry Pi. Once connected to a network, a user loads it's web page pointing their browser to xxx.xxx.xxx.xxx:9000 where xxx.xxx.xxx.xxx is the IP address of the Raspberry Pi. The user is then presented with a screen where they enter the blinking sequence, in ones and zeros as well as how long each element of the sequence lasts. Once the user clicks "Submit" a POST request is sent to the HTTP server on the Raspberry Pi. A separate thread runs switching on and off the lights as directed by the information sent from the web browser.
This project is useful for controlling large displays of Christmas lights. As IPv4 has 32 bit long addresses, a network could handle and many as 232 (4294967296) Raspberry Pi based controllers.
Once the student completes this lab, they will have learned about computer networking, web development and physical computing. They will learn about computer networking by assigning a static IP address to the Raspberry Pi and they will learn about web development when working with the user interface for the controller. This project provides an example of physical computing as the student controls real world events with software and computer hardware.
|Raspberry Pi that is able to access a Local Area Network (LAN)||1|
|PiFace breakout board for Raspberry Pi||1|
|100 Ω resistors||3|
|Jumper wires||about 8|
|(Optional) AA Battery holder *||1|
|Raspberry Pi power supply||1|
* If holder is not there, just serially connect the batteries in base to tip repetition. Solder the jumpire wires. This will give you 6 times the power of each AA battery, which is 6 * 1.5 V = 9.0 V to power the circuit.
- Raspbian Linux ‐ to run on Raspberry Pi.
- Python 2.7 ‐ to run our programs, comes with Raspbian.
- PiFace software
- Web browser on computer connected to LAN — to control the lights.
Ability to control the Raspberry Pi, either a computer with an SSH connection or a monitor and keyboard.
Setup the PiFace.
Carefully connect the PiFace to the Raspberry Pi, by connecting the Pi's male GPIO header to the PiFace's female GPIO header.
Setup the SPI kernel module on the Raspberry Pi
In a terminal on the Raspberry Pi, type: cd /etc/modprobe.d
Then type: sudo nano raspi-blacklist.conf
Comment out the line "blacklist spi-bcm2708" by changing it to "#blacklist spi-bcm2708"
Press Ctrl+O to save the file.
Reboot the Raspberry Pi.
Under /dev you should see spidev0.0 and spidev0.1
Make the sequence of Christmas Lights according to schematic in Figure 1.Figure 2 shows you one possible way of wiring together the circuit on a breadboard.
Install Python libraries on the Raspberry Pi
Download the following file: https://github.com/thomasmacpherson/piface/archive/master.zip
Extract the .zip file and enter the pifacedigitalio-master directory.
Run the following command: sudo python setup.py install. This will install the pifacedigitalio python library. Install any dependencies if they are needed along the way.
To see if this worked, open a python shell by typing "python" in the command line. Run the following commands.
import pifacedigitalio as pfio
LED 2 should now be ON
LED 2 should now be OFF
Setup the networking
On the Raspberry Pi go to /etc/network and edit interfaces as root.
Delete the line iface eth0 inet dhcp and add the following lines:
iface eth0 inet static
We have just given the Raspberry Pi a static IP address of192.168.1.5
Connect the Raspberry Pi to your computer with an Ethernet cable and run the following command on your computer: sudo ifconfig eth0 192.168.1.4
We have just given the Ethernet interface on our computer the IP address 192.168.1.4
On the computer open a terminal and type ping 192.168.1.5 . If information returns, everything is working.
Setup the HTTP server on the Raspberry Pi
Copy the directory RPi_sequence to the Raspberry Pi
Open the file webserver.py and modify the variable index_file_path to point to the file index.html (absolute reference)
On the Raspberry Pi's console, in the Rpi_sequence directory type the following command: python webserver.py . The HTTP server is now up and running.
Test the server by pointing the browser on your computer to http://192.168.1.5:9000 and verify that LED 0 on the Raspberry Pi blinks according to the sequence.
Build the Christmas lights by following the schematic.
Connect the Christmas lights to the PiFace. The two wires should be inserted into the two terminals that are closest to the GPIO header on the terminal block that is closest to the GPIO header. Order of insertion does not matter.
Make the HTTP server start automatically on boot.
On the Raspberry Pi, enter the command crontab -e and add the following line:
Save the crontab and reboot
Areas for improvement:
This lab teaches students the basics of physical computing, computer networking and web development. With more advanced knowledge in these areas the student can make modifications such as:
Making the user have to type a password in order to access the control page.
Port forwarding so that the control interface can be accessed anywhere that there is an Internet connection.
Give more precise control to the LEDs on the Christmas lights so that individual LEDs and be switched on and off.
To have a deepened knowledge in Electronics, Networking and Software Uses in Entertainment, you should first gain a "knowledge scaffold and learning directions" of powerful math, science, computer technologies and engineering. Address gaps in your foundation or gain new expertise as a student or teacher from free schools:
Once you feel confident, please Search with keywords "Animatronics", "Entertainment Technologies", "Controls in Lighting, Show, Stage", at UOIT Library or Open Textbooks and Open Encyclopediae:
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.