SlideShare a Scribd company logo
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
1
MODULE WORKSHOP “ Raspberry Pi3 With Python”
2018
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
2
Secript Python
1. turn-off-led.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
GPIO.output(16,GPIO.HIGH)
time.sleep(2)
GPIO.output(16,GPIO.LOW)
GPIO.cleanup()
Ket:
 Import RPi.GPIO as GPIO Merupakan modul atau library yang digunakan untuk
mengakses GPIO pin pada raspberry pi.
Import Rpi.GPIO as GPIO Is a module or library that is used to access GPIO pins on
raspberry pi.
 Import time juga merupakan library atau modul yang digunakan untuk pengoperasian
terkait dengan waktu.
Import time Is a module or library that is used to access about the time related.
 GPIO setmode(GPIO.BCM) untuk mengaktifkan sistem penomoran pin GPIO.
GPIO setmode(GPIO.BCM) is command to activating numbering system of GPIO pins.
 GPIO.setwarnings(False) memberitahu python untuk mengabaikan perintah jika pin
GPIO sudah digunakan.
GPIO.setwarnings(False) is command to show the python to ignor notice if GPIO pin has
been used.
 GPIO.setup(16,GPIO.OUT) memberitahu python apabila pin GPIO 16 yang akan
digunakan.
GPIO.setup(16,GPIO.OUT) is command to show the pyhton if GPIO pin 16 has been
used.
 GPIO.output(16,GPIO.HIGH) perintah menyalakan lampu LED
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
3
GPIO.output(16,GPIO.HIGH) is command to turn on of the LED lights.
 Time.sleep(2) Perintah untuk menjeda nyala lampu LED
Time.sleep(2) is command to interrupt turn on of the LED lights.
 GPIO.output(16,GPIO.LOW) perintah untuk mematikan lampu LED
GPIO.output(16,GPIO.LOW) is command to turn off the LED lights.
 GPIO.cleanup() perintah untuk memastikan bahwa tidak ada arus listrik di pin GPIO
GPIO.cleanup() is command to makesure if nothing electric current on GPIO pins.
2. blink.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
for i in range(3):
GPIO.output(16, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(16, GPIO.LOW)
time.sleep(0.5)
GPIO.cleanup()
Ket:
 For i in range(3) ini adalah perintah perulangan(for loop) yang nantinya lampu LED
akan berkedip sebanyak 3 kali.
For i in range(3) is command to repeat (for loop) which the LED lights will blink 3 times
 Time.sleep(0.5) waktu jeda lampu
Time.sleep(0.5) is break time of the lights
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
4
3. traffic.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pinList =[16,20]
SleepTime = 1
for i in pinList:
GPIO.setup(i, GPIO.OUT)
for i in pinList:
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTime)
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTime)
GPIO.cleanup()
Ket:
 PinList=[16,20] ini adalah perintah List yang akan memberitahu kepada python bahwa pin
GPIO tersebut akan digunakan
PinList=[16,20] this is command to list which give the notice to python if the GPIO pins
has been used.
 SleepTime=1 adalah perintah jeda waktu lampu LED.
SleepTime=1 is command the break time of LED lights.
4. flip_flop.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
5
pinList =[16,20]
SleepTime = 0.2
for i in pinList:
GPIO.setup(i, GPIO.OUT)
try:
while True:
for i in pinList:
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTime)
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTime)
except KeyboardInterrupt:
pass
GPIO.cleanup()
Ket:
 flip-flop tidak jauh berbeda dengan traffic hanya saja di flip-flop loop-nya terus
menerus(infinite)
Flip-flop not really different from traffic only in the flip-flop looping continuously
(infinite)
 SleepTiem= 0.2 adalah jeda waktu lampu ketika sedang dioprasikan.
SleepTiem=0.2 is the break time of the lights while being operated.
 Except KeyboardInterrup() mengalihkan loop dan akan diterusakn ke GPIO.cleanup
jika ada intrupsi dari keyboard dengan menekan (CRL+C).
Except KeyboardInterrupt is command to switch the loop and will be continue to GPIO.cleanup if
there is an interruption from the keyboard by pressing (CRL+C)
5. piemail.py
import RPi.GPIO as GPIO
import time, math
import smtplib, time
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
6
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
jawab = "y"
def send_email(username, password, recipient, subject, text):
print(username, password, recipient, subject, text)
smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(username, password)
header = 'To:' + recipient + 'n' + 'From: ' + username
header = header + 'n' + 'Subject:' + subject + 'n'
msg = header + 'n' + text + ' nn'
smtpserver.sendmail(username, recipient, msg)
smtpserver.close()
username = "nscmanajemen@gmail.com"
password = "NSC12345"
recipient = "your_to_send_email@gmail.com"
subject = "NSC Workshop"
message_a = "ligth 1 telah menyala "
message_b = "light 1 telah padam"
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
7
message_c = "light 2 telah menyala "
message_d = "light 2 telah padam "
message_e = "light 3 telah menyala "
message_f = "light 3 telah padam "
message_g = "lights 1,2 dan 3 menyala "
message_h = "lights 1,2 dan 3 telah padam "
while (jawab == 'y'):
perintah = input('masukan perintah : ')
if perintah == 'ON led1':
GPIO.output(16,GPIO.HIGH)
send_email(username, password, recipient, subject, message_a)
status = 'led 1 menyala'
elif perintah == 'OFF led1':
GPIO.output(16,GPIO.LOW)
send_email(username, password, recipient, subject, message_b)
status = 'led 1 padam'
elif perintah == 'ON led2':
GPIO.output(20,GPIO.HIGH)
send_email(username, password, recipient, subject, message_c)
status = 'led 2 menyala'
elif perintah == 'OFF led2':
GPIO.output(20,GPIO.LOW)
send_email(username, password, recipient, subject, message_d)
status = 'led 2 padam'
elif perintah == 'ON semua':
GPIO.output(16,GPIO.HIGH)
GPIO.output(20,GPIO.HIGH)
send_email(username, password, recipient, subject, message_g)
status = 'semua led menyala'
elif perintah == 'OFF semua':
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
8
GPIO.output(16,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
send_email(username, password, recipient, subject, message_h)
status = 'semua led padam'
else :
status = 'no perintah'
print ('status : ' + status)
jawab = input("tambah perintah ?")
print ('terimakasih')
Ket:
 import time, math merupakan library atau modul yang digunakan untuk pengoperasian
terkait dengan waktu
Import time, math is library or module to use for related operation with the time.
 import smtplib,time modul yang digunakan untuk mengirim email
Import smtlib,time is module which use for sending email.
 SMTP_SERVER= 'smtp.gmail.com' Protokol yang digunakn untuk mengirim pesan e-
mail antar server.
SMTP SERVER = ‘smtp.gmail com’ is the protocol to used for sending email massage
between server.
 SMTP_PORT = 587 Protokol koneksi yang menghubungkan program
SMTP PORT = 587 is the connection protocol to connect the program
 def sendiri adalah Identitas
Def is identification.
 send-email disebut fungsi
Send-email is funtion
 (username, password, recipient, subject, text) ini di sebut parameter
(Username, password, recepient, subject, text) is parameters.
 Print digunakan untuk mencetak nilai di dalam parameter ke-layar
Print is used for print the value to display in the parameter.
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
9
 smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) Untuk mengkoneksikan
dan mengirim email
smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) For connecting and
sending email.
 smtpserver.ehlo() memberitahu dan akan mengalihkan printah ketika server tidak
mendukung
smtserver.ehlo() for notice and switch off command when the server not support.
 smtpserver.starttls() mengirim perintah
Smtpserver.starttls() to send the command.
 smtpserver.login(username, password) berfungsi untuk masuk ke akun email.
smtpserver.login(username, password) Function to login email account
 header disini untuk membuat form
Header is use for make a form
 smtpserver.sendmail(username, recipient, msg) perintah yang akan mengirim email
smtpserver.sendmail(username, recipient, msg Command for sending email
 if , elif, else adalah statement di dalam python yang berguna untuk membangun alur
logika pada program
If, elif, else is a statement in python that is useful for building logic paths in the program.
 if adalah suatu kondisi dalam pemrograman yang berarti(jika)
If is condition of the meaning (if) in the program
 elif, juga suatu kondisi dalam pemrograman yang berarti (dan jika)
Elif is condition of the meaning (and if) in the program.
 else juga termasuk dalam kategori kondisi pemrograman yang berarti(selain)
Else is also included in the category of programming conditions which the meaning
(other than)
6. Percabangan.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
10
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
jawab = "y"
while (jawab == 'y') :
perintah = input ('masukan perintah : ')
if perintah == 'ON led1':
GPIO.output(16,GPIO.HIGH)
status = 'led 1 menyala'
elif perintah == 'OFF led1':
GPIO.output(16,GPIO.LOW)
status = 'led 1 padam'
elif perintah == 'ON led2':
GPIO.output(20,GPIO.HIGH)
status = 'led 2 menyala'
elif perintah == 'OFF led2':
GPIO.output(20,GPIO.LOW)
status = 'led 2 padam'
elif perintah == 'ON semua':
GPIO.output(16,GPIO.HIGH)
GPIO.output(20,GPIO.HIGH)
status = 'semua led menyala'
elif perintah == 'OFF semua':
GPIO.output(16,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
status = 'semua led padam'
else :
status = 'no perintah'
print ('status : ' + status)
jawab = input("tambah perintah ? ")
print ('terimakasih')
Ad

More Related Content

What's hot (20)

The Benefits of Type Hints
The Benefits of Type HintsThe Benefits of Type Hints
The Benefits of Type Hints
masahitojp
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
Renyuan Lyu
 
Alias
AliasAlias
Alias
Marieswaran Ramasamy
 
Libraries
LibrariesLibraries
Libraries
Marieswaran Ramasamy
 
Gevent what's the point
Gevent what's the pointGevent what's the point
Gevent what's the point
seanmcq
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
fefe7270
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
웅식 전
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? Edureka
Edureka!
 
First look on python
First look on pythonFirst look on python
First look on python
senthil0809
 
Apache PIG - User Defined Functions
Apache PIG - User Defined FunctionsApache PIG - User Defined Functions
Apache PIG - User Defined Functions
Christoph Bauer
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
Max Kleiner
 
(Www.entrance exam.net)-ignou mca solved assignment 2011
(Www.entrance exam.net)-ignou mca  solved assignment 2011(Www.entrance exam.net)-ignou mca  solved assignment 2011
(Www.entrance exam.net)-ignou mca solved assignment 2011
swatith
 
Python Intro-Functions
Python Intro-FunctionsPython Intro-Functions
Python Intro-Functions
Sumitava Mukherjee
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
P3 InfoTech Solutions Pvt. Ltd.
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
julien pauli
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
Control Flow
Control FlowControl Flow
Control Flow
Marieswaran Ramasamy
 
What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to know
Roy van Rijn
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
Slicing
SlicingSlicing
Slicing
Marieswaran Ramasamy
 
The Benefits of Type Hints
The Benefits of Type HintsThe Benefits of Type Hints
The Benefits of Type Hints
masahitojp
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
Renyuan Lyu
 
Gevent what's the point
Gevent what's the pointGevent what's the point
Gevent what's the point
seanmcq
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
fefe7270
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
웅식 전
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? Edureka
Edureka!
 
First look on python
First look on pythonFirst look on python
First look on python
senthil0809
 
Apache PIG - User Defined Functions
Apache PIG - User Defined FunctionsApache PIG - User Defined Functions
Apache PIG - User Defined Functions
Christoph Bauer
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
Max Kleiner
 
(Www.entrance exam.net)-ignou mca solved assignment 2011
(Www.entrance exam.net)-ignou mca  solved assignment 2011(Www.entrance exam.net)-ignou mca  solved assignment 2011
(Www.entrance exam.net)-ignou mca solved assignment 2011
swatith
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
julien pauli
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to know
Roy van Rijn
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 

Similar to Module Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RR (20)

Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
Yi-Lung Tsai
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
Tzung-Bi Shih
 
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
Dong-hee Na
 
Lisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyLisandro dalcin-mpi4py
Lisandro dalcin-mpi4py
A Jorge Garcia
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
Python 3
Python 3Python 3
Python 3
Andrews Medina
 
Introduction to Python Programming – Part I.pptx
Introduction to Python Programming  –  Part I.pptxIntroduction to Python Programming  –  Part I.pptx
Introduction to Python Programming – Part I.pptx
shakkarikondas
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
Oon Arfiandwi
 
Prototipare col raspberry pi
Prototipare col raspberry piPrototipare col raspberry pi
Prototipare col raspberry pi
Gabriele Guizzardi
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
Sudar Muthu
 
나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스
효준 강
 
function.pptx
function.pptxfunction.pptx
function.pptx
SwapnaliGawali5
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
Open Gurukul
 
mpi4py.pdf
mpi4py.pdfmpi4py.pdf
mpi4py.pdf
A Jorge Garcia
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
Robert Stern
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
usvirat1805
 
Pypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelPypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequel
Mark Rees
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
aeberspaecher
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Tomomi Imura
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
Yi-Lung Tsai
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
Tzung-Bi Shih
 
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
Dong-hee Na
 
Lisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyLisandro dalcin-mpi4py
Lisandro dalcin-mpi4py
A Jorge Garcia
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
Introduction to Python Programming – Part I.pptx
Introduction to Python Programming  –  Part I.pptxIntroduction to Python Programming  –  Part I.pptx
Introduction to Python Programming – Part I.pptx
shakkarikondas
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
Oon Arfiandwi
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
Sudar Muthu
 
나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스
효준 강
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
Open Gurukul
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
Robert Stern
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
usvirat1805
 
Pypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelPypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequel
Mark Rees
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
aeberspaecher
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Tomomi Imura
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
Ad

Recently uploaded (20)

How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho..."Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
ruslana1975
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho..."Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
ruslana1975
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Ad

Module Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RR

  • 1. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 1 MODULE WORKSHOP “ Raspberry Pi3 With Python” 2018
  • 2. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 2 Secript Python 1. turn-off-led.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16,GPIO.OUT) GPIO.output(16,GPIO.HIGH) time.sleep(2) GPIO.output(16,GPIO.LOW) GPIO.cleanup() Ket:  Import RPi.GPIO as GPIO Merupakan modul atau library yang digunakan untuk mengakses GPIO pin pada raspberry pi. Import Rpi.GPIO as GPIO Is a module or library that is used to access GPIO pins on raspberry pi.  Import time juga merupakan library atau modul yang digunakan untuk pengoperasian terkait dengan waktu. Import time Is a module or library that is used to access about the time related.  GPIO setmode(GPIO.BCM) untuk mengaktifkan sistem penomoran pin GPIO. GPIO setmode(GPIO.BCM) is command to activating numbering system of GPIO pins.  GPIO.setwarnings(False) memberitahu python untuk mengabaikan perintah jika pin GPIO sudah digunakan. GPIO.setwarnings(False) is command to show the python to ignor notice if GPIO pin has been used.  GPIO.setup(16,GPIO.OUT) memberitahu python apabila pin GPIO 16 yang akan digunakan. GPIO.setup(16,GPIO.OUT) is command to show the pyhton if GPIO pin 16 has been used.  GPIO.output(16,GPIO.HIGH) perintah menyalakan lampu LED
  • 3. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 3 GPIO.output(16,GPIO.HIGH) is command to turn on of the LED lights.  Time.sleep(2) Perintah untuk menjeda nyala lampu LED Time.sleep(2) is command to interrupt turn on of the LED lights.  GPIO.output(16,GPIO.LOW) perintah untuk mematikan lampu LED GPIO.output(16,GPIO.LOW) is command to turn off the LED lights.  GPIO.cleanup() perintah untuk memastikan bahwa tidak ada arus listrik di pin GPIO GPIO.cleanup() is command to makesure if nothing electric current on GPIO pins. 2. blink.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16,GPIO.OUT) for i in range(3): GPIO.output(16, GPIO.HIGH) time.sleep(0.5) GPIO.output(16, GPIO.LOW) time.sleep(0.5) GPIO.cleanup() Ket:  For i in range(3) ini adalah perintah perulangan(for loop) yang nantinya lampu LED akan berkedip sebanyak 3 kali. For i in range(3) is command to repeat (for loop) which the LED lights will blink 3 times  Time.sleep(0.5) waktu jeda lampu Time.sleep(0.5) is break time of the lights
  • 4. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 4 3. traffic.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) pinList =[16,20] SleepTime = 1 for i in pinList: GPIO.setup(i, GPIO.OUT) for i in pinList: GPIO.output(i, GPIO.HIGH) time.sleep(SleepTime) GPIO.output(i, GPIO.LOW) time.sleep(SleepTime) GPIO.cleanup() Ket:  PinList=[16,20] ini adalah perintah List yang akan memberitahu kepada python bahwa pin GPIO tersebut akan digunakan PinList=[16,20] this is command to list which give the notice to python if the GPIO pins has been used.  SleepTime=1 adalah perintah jeda waktu lampu LED. SleepTime=1 is command the break time of LED lights. 4. flip_flop.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False)
  • 5. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 5 pinList =[16,20] SleepTime = 0.2 for i in pinList: GPIO.setup(i, GPIO.OUT) try: while True: for i in pinList: GPIO.output(i, GPIO.HIGH) time.sleep(SleepTime) GPIO.output(i, GPIO.LOW) time.sleep(SleepTime) except KeyboardInterrupt: pass GPIO.cleanup() Ket:  flip-flop tidak jauh berbeda dengan traffic hanya saja di flip-flop loop-nya terus menerus(infinite) Flip-flop not really different from traffic only in the flip-flop looping continuously (infinite)  SleepTiem= 0.2 adalah jeda waktu lampu ketika sedang dioprasikan. SleepTiem=0.2 is the break time of the lights while being operated.  Except KeyboardInterrup() mengalihkan loop dan akan diterusakn ke GPIO.cleanup jika ada intrupsi dari keyboard dengan menekan (CRL+C). Except KeyboardInterrupt is command to switch the loop and will be continue to GPIO.cleanup if there is an interruption from the keyboard by pressing (CRL+C) 5. piemail.py import RPi.GPIO as GPIO import time, math import smtplib, time
  • 6. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 6 SMTP_SERVER = 'smtp.gmail.com' SMTP_PORT = 587 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16,GPIO.OUT) GPIO.setup(20,GPIO.OUT) jawab = "y" def send_email(username, password, recipient, subject, text): print(username, password, recipient, subject, text) smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(username, password) header = 'To:' + recipient + 'n' + 'From: ' + username header = header + 'n' + 'Subject:' + subject + 'n' msg = header + 'n' + text + ' nn' smtpserver.sendmail(username, recipient, msg) smtpserver.close() username = "nscmanajemen@gmail.com" password = "NSC12345" recipient = "your_to_send_email@gmail.com" subject = "NSC Workshop" message_a = "ligth 1 telah menyala " message_b = "light 1 telah padam"
  • 7. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 7 message_c = "light 2 telah menyala " message_d = "light 2 telah padam " message_e = "light 3 telah menyala " message_f = "light 3 telah padam " message_g = "lights 1,2 dan 3 menyala " message_h = "lights 1,2 dan 3 telah padam " while (jawab == 'y'): perintah = input('masukan perintah : ') if perintah == 'ON led1': GPIO.output(16,GPIO.HIGH) send_email(username, password, recipient, subject, message_a) status = 'led 1 menyala' elif perintah == 'OFF led1': GPIO.output(16,GPIO.LOW) send_email(username, password, recipient, subject, message_b) status = 'led 1 padam' elif perintah == 'ON led2': GPIO.output(20,GPIO.HIGH) send_email(username, password, recipient, subject, message_c) status = 'led 2 menyala' elif perintah == 'OFF led2': GPIO.output(20,GPIO.LOW) send_email(username, password, recipient, subject, message_d) status = 'led 2 padam' elif perintah == 'ON semua': GPIO.output(16,GPIO.HIGH) GPIO.output(20,GPIO.HIGH) send_email(username, password, recipient, subject, message_g) status = 'semua led menyala' elif perintah == 'OFF semua':
  • 8. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 8 GPIO.output(16,GPIO.LOW) GPIO.output(20,GPIO.LOW) send_email(username, password, recipient, subject, message_h) status = 'semua led padam' else : status = 'no perintah' print ('status : ' + status) jawab = input("tambah perintah ?") print ('terimakasih') Ket:  import time, math merupakan library atau modul yang digunakan untuk pengoperasian terkait dengan waktu Import time, math is library or module to use for related operation with the time.  import smtplib,time modul yang digunakan untuk mengirim email Import smtlib,time is module which use for sending email.  SMTP_SERVER= 'smtp.gmail.com' Protokol yang digunakn untuk mengirim pesan e- mail antar server. SMTP SERVER = ‘smtp.gmail com’ is the protocol to used for sending email massage between server.  SMTP_PORT = 587 Protokol koneksi yang menghubungkan program SMTP PORT = 587 is the connection protocol to connect the program  def sendiri adalah Identitas Def is identification.  send-email disebut fungsi Send-email is funtion  (username, password, recipient, subject, text) ini di sebut parameter (Username, password, recepient, subject, text) is parameters.  Print digunakan untuk mencetak nilai di dalam parameter ke-layar Print is used for print the value to display in the parameter.
  • 9. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 9  smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) Untuk mengkoneksikan dan mengirim email smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) For connecting and sending email.  smtpserver.ehlo() memberitahu dan akan mengalihkan printah ketika server tidak mendukung smtserver.ehlo() for notice and switch off command when the server not support.  smtpserver.starttls() mengirim perintah Smtpserver.starttls() to send the command.  smtpserver.login(username, password) berfungsi untuk masuk ke akun email. smtpserver.login(username, password) Function to login email account  header disini untuk membuat form Header is use for make a form  smtpserver.sendmail(username, recipient, msg) perintah yang akan mengirim email smtpserver.sendmail(username, recipient, msg Command for sending email  if , elif, else adalah statement di dalam python yang berguna untuk membangun alur logika pada program If, elif, else is a statement in python that is useful for building logic paths in the program.  if adalah suatu kondisi dalam pemrograman yang berarti(jika) If is condition of the meaning (if) in the program  elif, juga suatu kondisi dalam pemrograman yang berarti (dan jika) Elif is condition of the meaning (and if) in the program.  else juga termasuk dalam kategori kondisi pemrograman yang berarti(selain) Else is also included in the category of programming conditions which the meaning (other than) 6. Percabangan.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False)
  • 10. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 10 GPIO.setup(16,GPIO.OUT) GPIO.setup(20,GPIO.OUT) jawab = "y" while (jawab == 'y') : perintah = input ('masukan perintah : ') if perintah == 'ON led1': GPIO.output(16,GPIO.HIGH) status = 'led 1 menyala' elif perintah == 'OFF led1': GPIO.output(16,GPIO.LOW) status = 'led 1 padam' elif perintah == 'ON led2': GPIO.output(20,GPIO.HIGH) status = 'led 2 menyala' elif perintah == 'OFF led2': GPIO.output(20,GPIO.LOW) status = 'led 2 padam' elif perintah == 'ON semua': GPIO.output(16,GPIO.HIGH) GPIO.output(20,GPIO.HIGH) status = 'semua led menyala' elif perintah == 'OFF semua': GPIO.output(16,GPIO.LOW) GPIO.output(20,GPIO.LOW) status = 'semua led padam' else : status = 'no perintah' print ('status : ' + status) jawab = input("tambah perintah ? ") print ('terimakasih')
  翻译: