Wednesday, July 30, 2014

Ordered a DHT11 to connect with Raspberry Pi

Today I have ordered DHT11 in ebay.Just need to do some experiment with GPIO pins on Raspberry Pi in input mode.




DHT11 Temperature and Humidity Sensor features a calibrated digital signal output with the temperature and humidity sensor complex. Its technology ensures the high reliability and excellent long-term stability. A high-performance 8-bit microcontroller is connected. This sensor includes a resistive element and a sense of wet NTC temperature measuring devices. It has excellent quality, fast response, anti-interference ability and high cost performance advantages

DHT11 timing diagram:
DHT11 connection Diagram:

Waiting for it to come.................................

Tuesday, July 29, 2014

Object Game in Raspberry Pi using Pygame

It is easy to build falling balls in Pygame and try to use the sleep function to delay the balls.



Video in youtube:


Monday, July 28, 2014

Remote Desktop to Raspberry Pi from Windows 7

How to log in as Remote Desktop to Raspberry Pi from Windows 7 PC

In order to remote log in RaspberryPi , we have to install xrdp. Following steps can be used for install the software .

Install the xrdp software in  Raspberry Pi

sudo apt-get install xrdp

in order to know the status of xrdp , we can use the following command

/etc/init.d/xrdp status

For starting , use the below command

/etc/init.d/xrdp start

For stoping , /etc/init.d/xrdp stop

make sure your xrdp running in Raspberry Pi

In windows 7 PC, we will be getting the 'Remote Desktop Connection' from the start menu.

Enter the IP address of your raspberry pi in the computer field, and connect.




Saturday, July 26, 2014

Raspberry Pi connecting with Joystick in Pygame

Programming Joystick gaming with Raspberry pi

Install joystick using the command below:

sudo apt-get install joystick
 
after installation you can find file js0 in the directory:
 
/dev/input/
 
sudo cat /dev/input/js0
 
sudo cat /dev/input/js0 | hexdump
 
 
Pygame program to read joystick buttons

joystick = pg.joystick.Joystick(0)
joystick.init()
 
pg.joystick.joystick(0) returns the joystick object and init() function initialize the device values.
 button1 = joystick.get_button(0) retrives the button(0)
  
below program includes functions to read the keyboard input and mouse inputs. 
 
 
Pygame Joystick program:
 
import pygame as pg
# initialize pygame
pg.init()

# use an image you have (.bmp  .jpg  .png  .gif)
image_file = "ball"
# RGB color tuple for screen background
black = (0,0,0)
# screen width and height
sw = 640
sh = 480
# create a screen
screen = pg.display.set_mode((sw, sh))
# give the screen a title
pg.display.set_caption('image follows mouse click position')
# load an image
# convert() unifies the pixel format for faster blit
image = pg.image.load(image_file).convert()
# get the rectangle the image occupies
# rec(x, y, w, h)
start_rect = image.get_rect()
image_rect = start_rect
running = True
joystick = pg.joystick.Joystick(0)
joystick.init()
while running:
    event = pg.event.poll()
    keyinput = pg.key.get_pressed()
    button3 = joystick.get_button(2)
    button1 = joystick.get_button(0)
    # exit on corner 'x' click or escape key press
    if keyinput[pg.K_ESCAPE]:
        raise SystemExit
    elif event.type == pg.QUIT:
        running = False
    elif keyinput[pg.K_LEFT]:
        image_rect.left = image_rect.left - 1
        image_rect.right = image_rect.right-1
        print "corner coordinates --> (%d, %d, %d, %d)" % \
            (image_rect.left, image_rect.top, image_rect.right,
            image_rect.bottom)

        screen.fill(black)

    elif keyinput[pg.K_RIGHT]:
        image_rect.left = image_rect.left + 1
        image_rect.right = image_rect.right+1
        screen.fill(black)
        screen.blit(image, image_rect)
        pg.display.flip()
    elif keyinput[pg.K_DOWN]:
        image_rect.top = image_rect.top + 1
        image_rect.bottom = image_rect.bottom+1
        screen.fill(black)
        screen.blit(image, image_rect)
        pg.display.flip()

    elif keyinput[pg.K_UP]:
        image_rect.top = image_rect.top - 1
        image_rect.bottom = image_rect.bottom-1
        screen.fill(black)
        screen.blit(image, image_rect)
        pg.display.flip()

    elif button3:
        print("Joystick up pressed")
        image_rect.top = image_rect.top - 1
        image_rect.bottom = image_rect.bottom-1
        screen.fill(black)
        screen.blit(image, image_rect)
        pg.display.flip()

    elif button1:
        print("Joystick down pressed")
        image_rect.top = image_rect.top + 1
        image_rect.bottom = image_rect.bottom+1
        screen.fill(black)
        screen.blit(image, image_rect)
        pg.display.flip()
 
 
 
 
 
Pygame built with Raspberry Pi & Joystick 






Thursday, July 24, 2014

Trying owncloud in Raspberry Pi

I am trying owncloud in Raspberry pi following the instructions .  succeeded to lauch owncloud in Raspberry.


install it using following steps






sudo /etc/init.d/php5-fpm restart
sudo /etc/init.d/nginx restart



type in browser :  get ip address from ifconfig command

https://192.168.1.10/owncloud






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.
 
 
 
 
 

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/