If you want to power the raspberry pi through the GPIO pins this is totally possible! Here is a diagram of the pinout of the raspberry pi. (you can easily find them by googling raspberry PI pinout.)
The 2 5V power pins are directly hooked up to the 5V power planes, which means you can also use them to power the device. Conveniently there also is a ground pin right next to the most right 5V ping (pin 4 Power, pin 6 ground.)
You can connect 5 volt up to those pins and your device should power up CHECK THE POLARITY it's better to double check than to waste a board.
In my case I used the following pins do drive my relays (I am only using green pins).
|Pin #||Channel #|
For this project I am using rasbian, which can be downloaded here: https://www.raspberrypi.org/downloads/raspbian/ Their zip download is pretty slow, but I recommend going that route.
After installation is done I connected it up to wifi (mouse and keyboard no CLI at this point), after this is done you can make the IP static so you can always reach the PI on the same IP address after startup. For this change the config file using:
sudo nano /etc/dhcpcd.conf in the file add the following lines (with your information):
also be sure to turn on SSH access so you can remotely control the PI, also set the pi to start in CLI mode instead of GUI, this will decrease load.
Finally set a password you can remember if you need to change something down the road, since this project is running on your local network (behind NAT) and not outside of that this doensn't have to be overly complicated.
sudo passwd pi
and then enter your new password.
Now when you are on a windows computer you can use a program like Putty to connect to your raspberry pi. Simply type in the IP of the raspberry PI then (hit yes for the key) once prompted to log in, use pi as your username and enter the password you set earlier. Now install Apache and then PHP by typing:
sudo apt-get update
sudo apt-get install apache2 -y
sudo apt-get install php5 libapache2-mod-php5 -y
There are 2 major things we need to write. if you do it the same way I did it. the Front end (the webpage people get to see when they go to your page) and the script that turns on and off the lights.
This is also where the security people are going to cringe.
First to the the Directory where the webserver runs:
Remove the default page (after going there once to make sure it works.) http://addressofyourpi/
Edit a new file called index.php
sudo nano index.php
Here you can write a fancy page that will display when you want to turn on and off the lights. It is important to put the PHP and input tags in here to make this work.
PHP; You can add this in the end of the file, you will have to do this for every channel CHANGE THE NUMBER:
$my_file = '1aan.stat';
$my_file = '1uit.stat';
Once you have saved this file you should see your page but nothing happens when you click a button, so it seems. but when you now press a button a file is created on the webserver.
Now we can create a python script to check if a file exists and then based on that turn a light on or off
Edit a new file called check.py, at the beginning add the following:
import RPi.GPIO as GPIO
lamp1 = 11
lamp2 = 13
lamp3 = 15
lamp4 = 12
lamp5 = 16
lamp6 = 18
lamp7 = 32
lamp8 = 29
Then create a loop, I will now include a screenshot of a sample so you can't just copy paste all of this, you gotta learn too ;)
it's really important to get the indents right, else python will complain about this.
Now we have to make a launcher script.
I made a file called init.sh with the following content:
sudo python check.py
Don't forget to make it executable using
chmod 755 /var/www/html/init.sh and then add the script to the startup of the machine
sudo crontab -e
and add the line:
@reboot sh /var/www/html/init.sh