Sei sulla pagina 1di 56

Introduction to Raspberry Pi

Thomas Sabu
Team Lead | R&D
Neo Green Labs, Kochi
Contents
Raspberry Pi Intro
Familiarizing RPi Mini Computer
OS for RPi
Loading OS in to SD Card
Using RPi Computer
Introduction to Python
Python Programming
Blinking LED
Dislove
Raspberry Pi
Mini Computer
Applications
Low Cost Computer
Controlling the real world
Different Raspberry Pi Boards
Rpi 3 B
RPi 2 B+
Rpi 2 B
Rpi 1 B
Rpi 1 A+
Rpi 1 A
Working with RPi
Download the OS from Internet
Load OS in to the SD Card
Boot the RPi with OS
Develop your applications!
Operating System for Raspberry Pi

Raspbian
Windows 10 IOT
Loading OS in to SD Card
OS: Raspbian Jessie
Micro SD Card (8GB Class 10)
Tools Required
Winrar
Win32disk imager
Familiarize your RPi Computer
Programming Language
Basic
C
C++
Java
Python
Python Programming Environment
Familiarize it
Python
A simple & powerful Language
Programming with Python: Steps
open python
write the code
save the code with a name with an
extension .py
hello.py
run the code
Our first program
Write a program to Display
Hello! Whatsup??
Displaying a Character or
sentence
print
eg: print Hello! Whatsup??
Storing a Number, Character or
Sentence in the memory
(variable)
a=10
b=5
q=a
p=hello
print a
print b
print q
print p

print a,b,q,p
Mathematic Calculations

+ - * / %
Program to find the sum, difference
product and division of two numbers

a=18
b=6
c=a+b
d=a-b
e=a*b
d=a/b

print c
print d
print e
print d
Getting input from you / any other
user
int(raw_input())

eg: b=int(raw_input(enter the input))


Find the sum of two numbers
given by you / or the user

a=int(raw_input(enter the first number))


b= int(raw_input(enter the second number))
c=a+b
print c
Find the product of two numbers
given by you / or the user

a=int(raw_input(enter the first number))


b= int(raw_input(enter the second number))
c=a*b
print c
Print first 5 natural numbers

a=1
b=2
c=3
d=4
e=5
print a,b,c,d,e
Another method
a=1

print a

a=a+1

print a

a=a+1

print a

a=a+1

print a

a=a+1

print a
Easy method (using Loop)
a=1

print a

Four times
a=a+1
Using For loop
for a in range(1,6,1):
print a
Print the first natural numbers up
to a limit given by the user
n=int(raw_input(enter the limiting number))
for a in range(1,n,1):
print a
Find the sum of first n natural
numbers, where n is the limiting
number given by the user
Using While loop
a=1
while(a<6):
print a
a=a+1
Print the first integers up to a limit
given by the user
n=int(raw_input(enter the limiting number))
a=1
while (a<n):
print a
a=a+1
Find the sum of first n integers,
where n is the limiting number
given by the user
To find the largest of two numbers
a=5
b=10
if a>b:
print the largest number is:
print a
else:
print the largest number is:
print b
Find the largest of two numbers
given by the user
Find the smallest of two numbers
given by the user
Find the largest of first n numbers,
where n is the limit entered by the
user
n=int(raw_input(enter the limiting number))
a=1
b=1
while (a<n):
if a>b:
b=a
a=a+1
print the largest number is
print b
Interesting Applications of
Raspberry Pi
It can turn on an LED as per your
program
It can turn off and led as per your
program
It can blink an led
It can turn on/off an led when u press a
switch
How is it possible
Through the input / output pins on the
raspberry pi
RPi 2 Model B+ GPIO Header
LED
Turning on led with a battery
Connect the LED to the raspberry
pi
Can you turn it off without
disconnecting the wire???
Input output LIBRARY
First line of your program
import RPi.GPIO as GPIO
Functions
Second line of code
GPIO.setmode(GPIO.BOARD)

To connect led to the pin


GPIO.setup(pin no, GPIO.OUT)

To Turn off the LED


GPIO.output(pin no, GPIO.LOW)

To Turn on the LED


GPIO.output(pin no, GPIO.HIGH)
Your program
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.OUT)

GPIO.output(11, GPIO.HIGH)
Blinking an LED
Means
Turn on the led
wait for some time
turn off the led
Wait for some time
To wait for some time
You need another library
import time

Wait for one second time


time.sleep(1)

Wait for one second time


time.sleep(2)

Wait for one Half second


time.sleep(0.5)
import RPi.GPIO as GPIO
Import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, GPIO.HIGH)
time.sleep(1)
GPIO.output(11, GPIO.LOW)
time.sleep(1)
Blink the LED for ten times
You need a loop
You can use for loop or while loop
Program (using while loop)
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
i=0
while (i<10):
GPIO.output(11, GPIO.HIGH)
time.sleep(1)
GPIO.output(11, GPIO.LOW)
time.sleep(1)
i=i+1
Using for loop
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
for i in range(0,10,1):
GPIO.output(11, GPIO.HIGH)
time.sleep(1)
GPIO.output(11, GPIO.LOW)
time.sleep(1)
Blink the LED for infinite times
You need an infinite loop
while(1)
Thank You

Thomas Sabu
thomas@neogreenlabs.com
9495242563

Potrebbero piacerti anche