SlideShare a Scribd company logo
1 of 10
Download to read offline
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')

More Related Content

What's hot

The Benefits of Type Hints
The Benefits of Type HintsThe Benefits of Type Hints
The Benefits of Type Hintsmasahitojp
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtleRenyuan Lyu
 
Gevent what's the point
Gevent what's the pointGevent what's the point
Gevent what's the pointseanmcq
 
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? EdurekaEdureka!
 
First look on python
First look on pythonFirst look on python
First look on pythonsenthil0809
 
Apache PIG - User Defined Functions
Apache PIG - User Defined FunctionsApache PIG - User Defined Functions
Apache PIG - User Defined FunctionsChristoph Bauer
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Max 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 2011swatith
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesjulien pauli
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMax 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 knowRoy van Rijn
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 

What's hot (20)

The Benefits of Type Hints
The Benefits of Type HintsThe Benefits of Type Hints
The Benefits of Type Hints
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
 
Alias
AliasAlias
Alias
 
Libraries
LibrariesLibraries
Libraries
 
Gevent what's the point
Gevent what's the pointGevent what's the point
Gevent what's the point
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
 
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
 
First look on python
First look on pythonFirst look on python
First look on python
 
Apache PIG - User Defined Functions
Apache PIG - User Defined FunctionsApache PIG - User Defined Functions
Apache PIG - User Defined Functions
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
 
(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
 
Python Intro-Functions
Python Intro-FunctionsPython Intro-Functions
Python Intro-Functions
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Control Flow
Control FlowControl Flow
Control Flow
 
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
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Slicing
SlicingSlicing
Slicing
 

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

Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonYi-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 SealTzung-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 PyPyDong-hee Na
 
Lisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyLisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyA Jorge Garcia
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry piSudar Muthu
 
나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스효준 강
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : PythonOpen 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 1Robert 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.pptxusvirat1805
 
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-sequelMark Rees
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientistsaeberspaecher
 
[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 MoreMatt Harrison
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance PythonIan Ozsvald
 

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
 
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
 
[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
 
Lisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyLisandro dalcin-mpi4py
Lisandro dalcin-mpi4py
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Python 3
Python 3Python 3
Python 3
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Prototipare col raspberry pi
Prototipare col raspberry piPrototipare col raspberry pi
Prototipare col raspberry pi
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
 
나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스
 
function.pptx
function.pptxfunction.pptx
function.pptx
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
 
mpi4py.pdf
mpi4py.pdfmpi4py.pdf
mpi4py.pdf
 
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
 
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
 
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
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
[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
 
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
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 

Recently uploaded

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Recently uploaded (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

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')