Showing posts with label raspberry pi. Show all posts
Showing posts with label raspberry pi. Show all posts

Monday, July 21, 2014

PyGame in Raspberry using Mouse and Keyboard

I was actually trying to write a simple program which reads the input from keyboard and mouse to Pygame python program. when I searched , found its easy and within a few lines of code in Python we can able to control the movements of an image object in python.

The function image.load can load the image to the screen.
image.get.rect() get the rectangle coordinates of the image position. 

Event 'pg.key.get_pressed' reads the key press events and 'ÍF' clause checks which key has been given as inputs in the below program.

The same mouse click event also capturing inside the while loop which runs till the variable 'running' is true.

Based on the key inputs the rectangle image object position coordinates were changed to make movements to the image.

Raspberry Pi Pygame to control Image movements through External Keyboard or mouse







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.
 
 
 
 
 

Monday, June 30, 2014

Raspberry Pi LED blink program with Python

Today the experiment with Raspberry Pi was to explore the GPIO. But actually I didn't have anything(even connecting wires) , because its long time since I do something with breadboard. Even I was not sure how much I remember on breadboard schema.

Raspberry Pi GPIO




But within 3 hours of effort ( buying all these connecting wires & resisters & jumpers ), happily now the LED is blinking with Raspberry Pi and Python.

 How to  Blink LED with Raspberry Pi 7th GPIN using Python Program

1. login to Raspberry ssh  ssh pi@192.168.1.10  ( hope you have set a static ip address ) other wise you need to use HDMI cable connect to monitor

2.Write Python program to control GPIN 7

Program to On the 7th PIN :

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.output(7,True)


Program to Blink  LED connected to the 7th Pin

if you don't have Rpi GPIO module , it is required to get and install using apt-get install command. Those libraries should be imported before we use specific opcodes. As you indentation is important in python especially for loop logic.

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
while(1) :
        GPIO.output(7,True)
        time.sleep(1)
        GPIO.output(7,False)
        time.sleep(1)


Setting Up Raspberry Pi board and Circuit to LED.
  
before starting it recommended to test the LED with connecting the 3.3 V GPIO pin(1) and  GPIO Ground pin(6) through 270ohm to see its up or not . Once its tested , you can move the 3.3V connecting jumper wire to Pin7 in Raspberry so that the python program can control the Pin 7 and make the value 0 and 1 to blink the LED.







Saturday, June 28, 2014

How to host web pages in Raspberry Pi

Web Hosting in Raspberry Pi

Its easy to host web pages in your running Raspberry Pi.

1. Install Apache2

use the following link for the details - http://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

sudo apt-get install apache2 -y

2.Once you install start  the apache server

follow link - http://httpd.apache.org/docs/2.2/stopping.html

3. once you type your raspberrypi ip address in address bar in your computer , it will load the default of Apache. you can test apache installation that way.

In order to change default apache root directory ,edit file 'default' file in the directory below

/etc/apache2/sites-avaiable

edit the following and save the file.

DocumentRoot 'your project library'

'Your project library'
>
 
You can browse the Raspberry project folder html, by giving pi ipaddress/first.html from your computer.


Friday, June 27, 2014

Raspberry Pi connecting with Laptop and Android phone

Connect raspberry pi with your laptop.

1. Raspberry pi should be up and running
2. Connect LAN Cable to the router
3. Set up a static IP address to the Pi.
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 

4. Install Putty software in your laptop. For Ubuntu linux machines use Synaptic Package manager for download and install Puttysoftware.




Android - connection with Raspberry Pi

1.Install VNCSERVER on your Pi


sudo apt-get update
sudo apt-get install tightvncserver

2. Install  androidvnc in your android phone

http://raspi.tv/2012/install-and-use-tightvnc-remote-desktop-on-raspberry-pi-through-windows-android-or-ios

3. In Raspberry Pi board run vncserver command

4. Configure AndroidVNC in phone with following and connect

NickName:Pi
address: static ip address of Raspberry Pi
Port: 5901