week 2 - mfa - 9.10.15

18
MFA Design & Technology IOT Fall 2015 Ayodamola (Ayo) Okunseinde | [email protected]

Upload: ayodamola-okunseinde

Post on 09-Dec-2015

16 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Week 2 - MFA - 9.10.15

MFA Design & TechnologyIOT Fall 2015

Ayodamola (Ayo) Okunseinde | [email protected]

Page 2: Week 2 - MFA - 9.10.15

● Intro to Python

Page 3: Week 2 - MFA - 9.10.15

History of Pythonhttps://docs.python.org/2/tutorial/introduction.html#

● "Python is an interpreted, interactive, object-oriented programming language".

● Python is similar in some ways to Perl and Java. Knowing Perl or Java will help you learn Python, but it's just as easy to pick it up as a language. Python is great for both shell and web scripting and is making it's way into every facet of computing from APIs to video and interactivity.

● Guido van Rossum first created Python in the late eighties and early nineties. It is now maintained by a core development team.

Page 4: Week 2 - MFA - 9.10.15

Why Python

Python is Efficient : Iterative processes, good with lists, memory management

Python is Fast : Even if interpretive language can add decorators to speed up. Increasing in performance

Python is Broad : Systems automation, testing, gaming, CGI, and web development. Many modules

Python is Easy : Readable syntax, easy for non-programmer types, plays well with other languages

Python is Fun : Broaden your programing base, show off, reason differently

Page 5: Week 2 - MFA - 9.10.15

Basic Python math/stringsOn Laptop Terminal type - $ python

>>> 2+2 4>>> (5-20*2)/4 -9>>> 7**2 49

>>> width = 20>>> height = 5 * 9>>> width * height 900

>>> s="hot">>> p="dog">> print s+p hotdog

>>> j = "hotdog wa oishii desu">>> print j[10:16] oishii>>> len(j) 21

Page 6: Week 2 - MFA - 9.10.15

Basic Python list/while

>>> s=[1,4,5,6]>>> s[1]=20>>> print s [1, 20, 5, 6]

>>> a, b = 0, 1>>> while b < 10:

… print b … a, b = b, a+b … 1.1.2.3.5.8

>>> a, b = 0, 5>>> while b<1000: … print b … a,b = b, a+b 5.5.10.15.25…

>>> import time>>> while True: … time.sleep(2) … print "sleeping" sleeping...

Page 7: Week 2 - MFA - 9.10.15

Basic Python if/for

>>> x=int(raw_input(“#?”))>>> if x < 0:

… print “Neg Number” elif x == 0: … print “Number is 0” elif x == 1: … print “Number is 1” else: … print “Other”

>>> words = [‘neko’,’inu’,’ratto’,’sakana’]>>> for w in words: … print w, len (w) >>> for i in range (5,100,2):

… print i

>>> words = [‘ringo’,’nashi’,’hana,’ki’]>>> for i in range (len(words)):

… print i, words[i]

Page 8: Week 2 - MFA - 9.10.15

Basic Python functions

>>> def fib(n): #fibonacci function… a, b =0,1… while a<n:… print a… a,b=b,a+b

>>> fib(2000)

>>> def greeting(n): #hello function… name = raw_input(“enter name ”)… print “hello ”+name+”you are ” + n

Page 9: Week 2 - MFA - 9.10.15

Script - ip-email.pyRaspberry Pi

ssh and log into pi$ cd Desktop$ touch ip-email.py$ sudo nano ip-email.pypaste contents of “ip-email.py” into terminal$ sudo nano /etc/rc.localwrite path of script before “exit 0”$ sudo python /home/pi/Desktop/ip-email.py

Laptop Terminal

$ cd /home/path/toscript$ touch ip-email.py$ sudo nano ip-email.pypaste contents of script into terminal$ sudo python ip-email.py

Page 10: Week 2 - MFA - 9.10.15

Script - email-read.py, email-notify.py

Page 11: Week 2 - MFA - 9.10.15

Python update/GPIO

Install latest python 2.7 and python pip$ sudo apt-get install python-pip python2.7-dev

Update distribution$ sudo easy_install -U distribute

Install feedparser$ sudo pip install feedparser

Page 12: Week 2 - MFA - 9.10.15

● GPIO

Page 13: Week 2 - MFA - 9.10.15

GPIO

GPIO.BCM

http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples

GPIO.BOARD

Page 14: Week 2 - MFA - 9.10.15

Digital Output - gpio-blink.py

● BOARD / BCM● Resistors

Page 15: Week 2 - MFA - 9.10.15

Digital Input - gpio-buttons.py

● Resistors● Debounce● Pullup● Pulldown● Digital in only

Page 16: Week 2 - MFA - 9.10.15

Analog Input - gpio-rc.py

https://arduinodiy.wordpress.com/2013/10/19/793/

● ADC● RC analog input

http://www.raspberrypi-spy.co.uk/2013/10/analogue-sensors-on-the-raspberry-pi-using-an-mcp3008/

Page 17: Week 2 - MFA - 9.10.15

Analog Output - gpio-angout.py

● PWM● Fading LED● Servo

Page 18: Week 2 - MFA - 9.10.15

Assignment●