Instructables

Simple and intuitive web interface for your Raspberry Pi

Featured
Picture of Simple and intuitive web interface for your Raspberry Pi
P1040971.JPG
P1040976.JPG
P1040977.JPG
P1040978.JPG
     The Raspberry Pi is an amazing 35 dollars mini-computer. It allows you to do everything you could do with a regular Linux computer (Connecting to the internet, watching videos, launching applications, ...) but also to interact with the world surrounding it, just like an Arduino. That's why I qualify it as a mix between a computer and a micro-controller.
     That's also why I chose it for this project. I'm going to show you how to control LEDs with your Raspberry Pi. Firstly directly from the Raspberry Pi itself, then from any device in your house like your Smartphone or your tablet.
 
Here is a very good example of what you can achieve after reading this Instructable: http://www.instructables.com/id/Web-Controlled-8-Channel-Powerstrip/. Thanks to Rleddington for his amazing project.

 
Remove these adsRemove these ads by Signing Up

Step 1: The electronic part

Simple.JPG
P1040967.JPG
P1040968.JPG
raspberry-pi-rev2-gpio-pinout.jpg
     The electronic part is nothing special, it's only 8 LEDs with their protecting resistor. The only hard part is to connect the LEDs to the good pin on the Raspberry Pi. Indeed, I'll be using later a library called Wiring Pi made by Gordon Henderson (You can visit his website at: http://wiringpi.com/) and the pin's numbers used in this library aren't the same than the ones on the Raspberry Pi. See this page for matches: http://wiringpi.com/pins/ (just be careful about your Raspberry Pi revision, the pinout isn't exactly the same). I'll be using Wiring pins 0 to 7.
     Concerning the resistors, they should be 270Ω but since I don't have this precise value, I'm using 560Ω resistors (LEDs are just less bright).
     Finally, I've made two schematics to make it simpler. The first one (with the complete Raspberry Pi) is showing you the real pins as they are shown on the board. The second one is a simplified version, it's showing you only the useful pins and their matches in the Wiring Pi library (GPIO Wiring number/Actual number on the board).
1-40 of 122Next »
Mickey4D2 days ago

The solution for zqsd control (oklm for me)

https://docs.google.com/document/d/1K6IOQwCZwZ90rc...

Mickey4D3 days ago

Hi, it work really well !

But i have a problem, i want to build a drone with raspberry pi and your project and i want to use letters like zqsd instead of use the mouse and click i don't know how to remove the security.

thank you in advance !

hxc5 days ago
thx...it work...
temp_-1906717386.jpg
TheFreeElectron (author)  hxc5 days ago
Glad to know that. Enjoy your raspberry pi
hxc7 days ago
hey....i download ur projeck web file..
index.php
gpio.php
script.js
data

all this file place at /var/www ? or only index.php
TheFreeElectron (author)  hxc7 days ago
Hi hxc,
All of them should be placed in your /var/www folder.
thx...i will try...
but i cant move file "data" to /var/www
"mv data /var/www"
access denied

sorry...this my 1st time using raspberry pi..
TheFreeElectron (author)  hxc6 days ago

no problem, I also had these troubles at the beginning. The issue you're having is probably coming from the rights of access used by the Linux os. You need to own the www directory if you want to transfer data into it. Did you followed the commands given in step 3? If yes check who's owning the www directory with ls -l.

If you did all of this, you should be able to transfer the data folder. If not try to Google your problem.

TheFreeElectron

i made it..thx
now need to setup hardware...
temp_-1115055010.jpg
TheFreeElectron (author)  hxc6 days ago

ok, no problem. Don't give up and have fun with the raspberry pi. Don't hesitate to ask if you have any other problem.

if i transfer using filezilla...
where i can find file "/var/www"?
in what folder?
IveaghC10 days ago

Thank you for the great instructable.

If I open the web page in two browsers the second browser successfully syncs with the i/o states set by the first. However any further changes by either browser are not reflected in the other. Is there a simple solution to scan and update the i/o states in code? This would allow dual control, keeping the current states in sync on both browsers

TheFreeElectron (author)  IveaghC10 days ago
Hi IveaghC,
In fact this code isn't made for dual control. However I see two solutions. The first would be to find a way to transform your browser into a kind of server waiting for data coming from the Rpi but I doubt that it is possible, you should try to Google it. The second solution would be to add a new js function that would ask for the pins' status every half second as example. In addition you'd need to create a new php page that reads and sends the pins' status everytime you ask for it.

I hope that I helped,
TheFreeElectron
hitac29 days ago

Hi,

I have 8 relay module connected directly into GPIO's. Problem is that relay is pulled when GPIO is 'low'. When Raspberry is booted, GPIO's are 'high' or something else, all relays are off. Once I refresh interface web page, all GPIO's are pulled down, which activates all relays on board, this is not very good and can be dangerous too depending what relay is controlling.

I am still learning the code, but is there a easy way to invert GPIO's by code. So, that after booting it is like now, no relays activated and after refreshing page, GPIO's are at 'high' instead 'low'. Thanks in advance.

-juha

TheFreeElectron (author)  hitac29 days ago

Hi Juha,

Basically the interface web page is doing nothing else than reading the GPIO's status, not modifying it. However, it is possible that when the mode is set to "out" for the first time, it may pull them down, I don't really know. A quick look to the reference of the library or testing by typing the commands directly in the terminal would be interesting. If it is the problem, a solution to that would be to remove the line 15 of index.php and 10 of gpio.php then to create a batch script (executed when booting) which would set the mode of each GPIO to out then the status to "high". The GPIOs would be "low" for only a very small amount of time.

Also, with the help of a message, I recently corrected an error in index.php. Try downloading the updated version.

I do not see anything else I could say about your problem, you should take a look at the project linked in the first step which is also using a relay module.

Hope I helped,

TheFreeElectron

dragons.n.s3 months ago

Hi TheFreeElectron,

its me again, i have finish this instructable and its woking perfectly, yet it still have problems; it only works in RPi's browser 'midori' it don't work in any other smartphones or any other PC's browsers. so plz help me with that

TheFreeElectron (author)  dragons.n.s3 months ago

Hi Dragon,

I'm glad to know that's it's "perfectly" working for you!

Concerning your problem, it's kind of weird. The fact that it is working only on the Rpi itself doesn't really makes sense. However I may see an option, sometimes my LAN network doesn't work, I can access the Internet but I can't access other computers of my network. Also if I type my computer's address (also used as a server with ip 192.168.1.24), it works. It's probably because the browser recognizes the address and then connects directly to the server without asking anything to the router. I usually turn off/on the router and it works again!

Else maybe that your server isn't configured to accept connection others than from localhost, you should search "put wamp/lamp server online" on google or something like that.

Finally, I see no other options, you should test your LAN network if none of everything over is working. See if this problem happens to other computers, if you can connect to them. Also, google is one of best friend if you still have troubles.

Hope I Helped,

TheFreeElectron

Hi TheFreeElectron,

thanks again!!!!!!!!!!!!!

TheFreeElectron (author)  dragons.n.s3 months ago

No problem, do not hesitate if you need something else.

hey, you know what! it finally works 100%. thank you for your help TheFreeElectron

dragons.n.s3 months ago

Hi TheFreeElectron,

its me again, i have finish this instructable and its woking perfectly, yet it still have problems; it only works in RPi's browser 'midori' it don't work in any other smartphones or any other PC's browsers. so plz help me with that

dragons.n.s3 months ago

Hi TheFreeElectron,

its me again, i have some doubts on the final step, about the three files index.php, gpio.php and the JavaScript file. should i place the files in the /var/www/ or i have to create a new directory in the /home/pi. and i have another doubt, can i simply access page by using the ip address. and one more thing I'm sorry if my English skills are bad, B'coz i'm from india

TheFreeElectron (author)  dragons.n.s3 months ago
Hi Dragon,

You have to place all of them in the /var/www directory. If you can, download the zip file and simply paste the content in /var/www.
After that, to access your Rpi, you need its local/LAN address. To get it, you can type the "ifconfig" command in the terminal or access your router's page, you usually need to type 192.168.1.1 in the URL bar. Once you have this LAN ip, simply type it in the URL bar and if you did everything well, you should have the home page with the buttons.

Hope I helped,
TheFreeElectron

Hi TheFreeElectron,

Thanks for the reply it helped me a lot. and thanks again!!!!!!!! =)

TheFreeElectron (author)  dragons.n.s3 months ago
No problem! ;)
TheFreeElectron (author)  dragons.n.s3 months ago
No problem! ;)
Hayaalsh5 months ago

Hello TheFreeElectron :)

Thank you for this amazing tutorial!
but I have a question. One of the members said that they
can control the LED lights from New-Zealand! However, I cannot control the pi
unless the pi and my Smartphone are connected to the same network.

Is there any way to control the pi
from any place in the world without the need of being connected to the same
network?

I hope you get what I mean.

Hayaalsh Hayaalsh5 months ago

please answer me :(

TheFreeElectron (author)  Hayaalsh4 months ago

Hi Hayaalsh,

Sorry for responding so late but I haven't been noticed of your comment. Maybe, the mail alert messed up or I just simply deleted unintentionally the message.

In fact, If you want to control your pi from all over the world, you need to connect to the wan ip of your box/router instead of the lan ip of yout pi, a lot of websites are giving you this ip. After that, you need to forward the http port (80) to your pi. It means that all the requests sent to your box/router won't be blocked anymore but instead, they'll be sent to your pi. Therefore you can access your home server from all over the world! There are plenty of tutorials on the web, search for "home web server", "port forwarding" or "making your pi accessible from the internet".

To answer the question of your other comment, the pi is in fact pretty much limited when it comes to powering something. These ports are rather meant to communicate with other boards. Thereby, to control something that is asking for more power you better be creating a separate second circuit which would be able to deal with more power, you can easily do this with relays or transistors. There's a link in the first step that will send you to another 'Ible in which you see how to control light bulbs or such things.

I hope I answered your questions and again, I'm really sorry.

TheFreeElectron

Thank you so much. That was very helpful!

I will try what you said and let you know what happens :)

stupidmachine made it!4 months ago

A really great instructable!

I made a little remote control car with a RPi, a USB Battery, a NiCd battery, an old RC car that didn't work anymore, a wi-fi dongle and transistors. Your tutorial helped me a lot. Now I can connect to my RPi's own wi-fi and control my car on a HTML page, with the arrow keys or with the accelerometer if I use a mobile device.

PS: Sorry for my english...

DSC_0005.JPG
TheFreeElectron (author)  stupidmachine4 months ago

Hi Stupidmachine,

Thank you for your feedback. Your project looks really interesting and amazing, why not writing an Instructable?

Why not, maybe when I've got a little spare time.

I've already done some kind of instructable because it's a project for school but it's in french so I'll have to translate it.

TheFreeElectron (author)  stupidmachine4 months ago

Don't worry, I'm french too (now it makes no sense to keep speaking in english but let's allow everybody to understand us ;) If you only need to translate, google traduction is one of your best friend (believe me) or you can even ask your english teacher. I'll be looking forward for your 'Ible and doubtless giving it a link in the first step!

Actually I'm from Switzerland.

I should be able to translate it but I just lack time these days... But I'll do it.

TheFreeElectron (author)  stupidmachine4 months ago

Excuse me, I couldn't know. Take your time and if I may ask, which grade are you in?

There's no need to apologize, it's not like it was bad to be french. ;)

I'm finishing the highschool this year and I'll be at the EPFL (école polytechnique fédérale de Lausanne) next year in microtechnology.

TheFreeElectron (author)  stupidmachine4 months ago

I'm also in last year of highschool but I won't be able to know where I'll be next year until the end of June (That's one drawback of being french ;). I just have a question, why did you do a project for school, is it something specific to your highschool/section or more generally to all Switzerland?

For the last year of highschool, we have to choose a specific option, and I choosed IT. We're in a small class and it's really fun. We learnt some web languages and we're now doing stuff with the RPi. We could freely choose a project to do with it and that's why I did that...

TheFreeElectron (author)  stupidmachine4 months ago

Ok, very well. In France, we have the choice between four "specialties" : Biology, Sciences and Physics, Maths and something called "ISN" (standing for "Informatique et Sciences du Numérique") which is probably the equivalent of your option. I personally chose Maths because the program was more interesting and it was better for the schools I'm aiming. It represents only 2 hours a week. It's also in rather small classes and it's also a lot of fun ( That's my opinion ;). We can stay in contact by e-mail if you want, you can send me your address by personal message.

1-40 of 122Next »