Tag Archive : OSMC

/ OSMC

Raspberry

The Raspberry Pi’s very existence can be chalked up to creativity.  Raspberry Pi Foundation created the $35 Single Board Computer to inspire students to learn computer science and play with programs.

Raspberry help you to connect with various I/O Devices (Sensors,Lights,motors,etc..) using 40 Pin GPIO Ports.This help users to make a gateway between computer programming and electronic devices. You can control this ports using Python directly.

OSMC

The popular Media Center operating system Kodi on Raspberry Pi has its own set of drawbacks and benefits. OSMC has a few key features that may draw you to it over XBian or OpenELEC.

One of the first things you’ll notice about OSMC is that, out of the box, it looks different. It uses its own Kodi skin, a lightweight one that helps keep things fast. The OSMC Kodi skin is kind of similar to Mimic, which is one of Kodi’s best skins, so this may draw you to OSMC.

Why OSMC

OSMC is based on Debian Linux Operating System so it support  all linux command as well as you can install all applications like Apache,Mysql etc . You can also install packages required for GPIO Ports which help you to connect the electronic gadgets using relay.

How to Install OSMC on Raspberry Pi

Requirement :

1.Raspberry Pi

2.HDMI Cable

3.16GB Memory Card

4.Card Reader

Steps To Install OSMC

Step 1: Put your SD card into your computer’s SD card reader

 

Step 2: Download the OSMC installer

We’re installing OSMC on the micro SD card, not on our computer. So in this stage, we’re installing a program for our computer that will then install OSMC on the SD card. You can find the right version for your computer’s operating system on OSMC’s website.

 

Step 3: Run OSMC Installer and Install OSMC on your micro SD card

Step 4: Setup Raspberry Pi

Eject the SD card and plug it into your Raspberry Pi. Then make sure all your cables are connected properly – your HDMI cable, your ethernet (or Wi-Fi dongle). Plug the power cord in last.

Step 4: Boot Raspberry Pi

OSMC will set up automatically. Just wait for a while so that OSMC will automatically the format and setup the device, and then enjoy!

Raspberry

The Raspberry Pi’s very existence can be chalked up to creativity.  Raspberry Pi Foundation created the $35 Single Board Computer to inspire students to learn computer science and play with programs.

Raspberry help you to connect with various I/O Devices (Sensors,Lights,motors,etc..) using 40 Pin GPIO Ports.This help users to make a gateway between computer programming and electronic devices. You can control this ports using Python directly.

Python

It’s a programming language which help raspberry to connect the raspberry GPIO Pin to switch it ON and OFF. Python is simple and easy to learn and it’s totally dependent on indentation.

Code

#!/usr/bin/env python
import RPi.GPIO as GPIO
import sys, getopt

def gpio(pin):
    pin = int(pin)
    switcher = {
        2: 3,3: 5,4: 7,5: 29,6: 31,7: 26,8: 24,9: 21,10: 19,11: 23,12: 32,13: 33,14: 8,15: 10,16: 36,17: 11,18: 12,19: 35,20: 38,21: 40,22: 15,23: 16,24: 18,25: 22,26: 37,27: 13,
    }
    return switcher.get(pin, "false")

def main(argv):
    gpiopin = ''
    status = ''
    type = 'pin'
    try:
        GPIO.setmode(GPIO.BOARD)
        opts, args = getopt.getopt(argv,"hg:s:t:",["gpio=","status=","type="])
    except getopt.GetoptError:
        print 'gpio.py -g  -s  -t <pin/gpio>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'gpio.py -g  -s  -t <pin/gpio>'
            sys.exit()
        elif opt in ("-g", "--gpio"):
            gpiopin = arg
        elif opt in ("-s", "--status"):
            status = arg
        elif opt in ("-t", "--type"):
            type = arg
    if gpiopin != "":
        gpiopin=int(gpiopin)
        status=int(status)
        GPIO.setwarnings(False)
        if type=='gpio':
            gpiopin=gpio(gpiopin)
        GPIO.setup(gpiopin, GPIO.OUT)
        GPIO.output(gpiopin,status)
        if status == 0:
            GPIO.cleanup()
    else:
        print 'gpio.py -g  -s  -t <pin/gpio>'
    
if __name__ == "__main__":
    main(sys.argv[1:])

How to execute

sudo python gpio.py -g <pin number> -s < 0(off) / 1(on) > -t <pin/gpio>

Example

sudo python gpio.py -g 19  -s 0 -t gpio

PIR infrared sensor module is based on infrared technology, automatic control products. High sensitivity, high reliability, low power consumption, low voltage operation mode. Widely used in various auto-sensing electrical equipment, especially for battery-powered automatic control products.

Using PIR we can identify the motion and this sensor will transmit a signal for 3 sec so we need to do a program and detect the motion and as per your requirement you can activate or deactivate any functions like switching on camera when motion is detected.

I am going to use Raspberry Pi 2 For this small Project . In this Project i am designing and program to detect a motion and on basis of that alarm will be played for 1 minute.

Requirement :

1.Raspberry Pi

2.Pyroelectric Infrared Pir Motion Sensor Detector Module

3.Computer With Putty Installed

 

Step 1.

Install any raspberry based Operating system with GPIO Package installed and as well as Python Installed. I am using OSMC.

Step 2.

Connect the PIR VCC,OUT,GND to Raspberry pi 5v,GPIO4,GND

pir_wiring

VCC – > 5v
GND -> GND
OUT -> GPIO4 (Pin 7)

 

Step 3

Connect to raspberry pi using SSH (Putty For Windows)

Step4

Create a python program and copy bellow code .And after saving run the script with sudo permission

import RPi.GPIO as GPIO
import time
import os
#GPIO Pin number where the sensor out is connected
pin=4
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin,GPIO.IN)
timer=0;
switch_on=0;
while True:
    time.sleep(1)
    sensor_input=GPIO.input(pin)
    if sensor_input == 1 :
		#Timer in seconds for activation
        timer = 60
    if timer > 0 :
        timer = timer - 1
        print "De-activating in :",timer,"secs"
        if switch_on!=1 :
            #If you want to output using 26 GPIO Remove below 2 lines comment
            #GPIO.setup(26, GPIO.OUT) 
            #GPIO.output(26,1)
            switch_on=1
            print "--- Switch Activated ---"
    else:
        if switch_on!=0 :
            print "Switch Deactivated"
            switch_on=0
            #If you want to output using 26 GPIO Remove below 2 lines comment
            #GPIO.setup(26, GPIO.OUT)
            #GPIO.output(26,0)