Wednesday, July 16, 2014

Looking for how to build Python program games for Raspberry

I am thinking of Python Program games for Raspberry Pi. Searching google a lot for this nowdays. But looks like a bit of logical thinking required for a building games . But still found PYGAME looks easy to build some simple games http://pygame.org/wiki/tutorials
 
Pygame is a set of Python modules designed for writing games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. Pygame is highly portable and runs on nearly every platform and operating system.
 
Looking to set up a game somehow with my logical skills and that interface with external joystick connected to Raspberry Pi...

Sunday, July 13, 2014

Raspberry Pi + Relay Board to turn on 220v bulb from python Web page

To play with 220V , we should be a little careful and need to take all precautions with testers to check to 220v supply. This experiment we need to have Raspberry Pi ( already we have) and Relay Board which actually drive the switch and break the ciruit based on the 7th Pin voltage in GPIO pin.
 
Programs which we are gointo use same the Pyhon program we used to blink the LED from Flask python webpage
 
 
Only difference we used the Raspberry Pi GPIO pins 5v(2nd pin),Ground(6th pin), 7th pin to drive the relay a shown in the pictures.
 
 
 
 
 

Thursday, July 10, 2014

Raspberry Pi Flask python web page to control the LED

I was searching for how to control the LED from python web page program. I reached in Flask microframework. http://flask.pocoo.org/


Flask is lightweight web application framework written in python and its very much suited for Raspberry Pi board.  Controlling the LED connectioned to GPIO pin 7 is easy ,through the python program written importing Flask.


Steps to control LED connected to Raspberry Pi through WebPage

Step1: install Flask in Raspberry Pi.Follow below steps

apt -get install python-pip
pip install Flask



Step2. Connect the LED to the GPIO pin 7 through 470ohm resister

Step3: Writing Programs in Python Flask

First you need to create a python program which actually rendor the html templates stored in the 'templates' directory.

1.Create a folder called 'pythonsites' in your home directory  and you can write gpio.py in that folder as below. Refer the Flask site for example programs 


route() decorator is used to bind a function to a URL. refer http://flask.pocoo.org/docs/quickstart/#routing
3 functions we have written which are  light_on, light_off  & light_blink

We are going to keep 3 links in the html template ,those are Turn On, Turn Off, LED blink

2.Once you have written this program ,should create a folder called 'templates' and keep our html template.

folder path -
pi@raspberrypi ~/naveen/pythonsites/templates $

html page shows in the browser create as light.html



Web page using Flask:

Run gio.py program using python

sudo python gio.py

connect with port to raspberry as follows ,depends on your raspberrypi IP address.
 http://192.168.1.10:5000/