我爱编程

[Mooc]IoT Course 4 The Raspberry

2017-05-07  本文已影响0人  Vinchent

Week 1

Reading Material

Lesson 1

Lecture 1.1 Raspberry Pi Board

Raspberry Pi Hardware Specs
Raspberry Pi B+
IoTM4W1L1.1.png IoTM4W1L1.1_2.png

Lecture 1.2 Raspberry Pi Processor

ARM Processors
ARM Processor Family

Lecture 1.3 Raspberry Pi vs. Arduino

Raspberry Pi vs. Arduino
Using an Operating System

Lesson 2

Lecture 2.1 Operating System Benefits

User Interface
File System

Lecture 2.2 Processes

Multiple Processes
Using Hardware Devices

Lecture 2.3 Raspberry Pi IoT

Is Raspberry Pi and IoT Device?

Maybe - Depends on how it is used
Similarities

Differences

Lesson 3

Lecture 3.1 Raspberry Pi Setup

Setup of the Raspberry Pi

Step1 : Plug in a monitor(via HDMI) and a keyboard and mouse (via USB)

Step2 : Get an operating system

Installing an Operating System

use New Out-Of-Box Software(NOOBS)

NOOBS

Lecture 3.2 Raspberry Pi Configuration

Raspi-Config
Raspi-Config Options

Lecture 3.3 Overclocking

Overclocking
Impact of Overclocking
Impact of Increasing Voltage

Week 2

Reading material

Lesson 1

Lecture 1.1 Linux Basics

The Shell
Console or Terminal

Lecture 1.2 Login

Accounts
Man(ual) Pages

Lecture 1.3 Linux Filesystem

The Filesystem
IoTM4W2L1.3.png
PWD

Lesson 2

Lecture 2.1 Navigating the Filesystem

CD
ls
Mkdir, Rmdir

Lecture 2.2 Text Editors

Creating Files
Nano

Lecture 2.3 Accessing Files

Viewing a File
CP
MV

Lesson 3

Lecture 3.1 Permissions

File Permissions
Viewing File Permissions
Root Account

Lecture 3.2 Processes

Processes
Viewing Processes
Shutdown

Lecture 3.3 Linux Graphic User Interface

Using the GUI for Raspian
File Manager

Week 3

Reading Material

Lesson 1

Lecture 1.1 Python on Raspberry Pi

Raspberry Pi for IoT
Python Language

Lecture 1.2 Python Programming Environment

Python Programming Environment

Two possible environments:

  1. Integrated Development Environment(IDE)

    • IDLE is the best option
    • Invoke via Menu > Programming > Python
    • Select Python 2 or Python 3 (use 3 for now)
  2. Text editor and interpreter, separately

    • Use Pico or Nano to write a program, "test.py"
    • Execute program by typing "python3 test.py"
Executing Python Code

Two ways to do it:

  1. Interactive: execute lines typed interactively in a Python console.
  2. Batch: execute an entire Python program
    • Interactive execution requires a Python shell
      • Start IDLE, shell s default
      • In terminal, type "python3"
Executing Programs from IDLE
  1. Start IDLE
  2. File > New File to create a new text editor window
  3. Type in code
  4. Select Run > Run Module
  5. Python shell will open and code will execute

Lecture 1.3 Python Expressions

Algebraic Expressions
Boolean Expressions
Boolean Operators
Variables, Assignments

Lesson 2

Lecture 2.1 Strings

Strings
String Operators
IoTM4W3L2.1.png
Indexing Operator

Lecture 2.2 Functions

Defining Functions
>>> def test():
     print('A test function')

>>> test()
A test function
>>>
Defining/Calling Functions

Lecture 2.3 Function Arguments

Function Parameters/Arguments
>>> def circle_area(rad) :
      print(3.14 * rad * rad)
>>> circle_area(2)
12.56
Function Return Values
>>> def circle_area(rad) :
      return 3.14 * rad * rad
>>> circle_area(2)
12.56
>>> 3 + circle_area(2)
15.56
>>>

Lesson 3

Lecture 3.1 Lists

Lists
>>> pets = ['ant', 'bat', 'cod', 'dog']
>>> lst = [0, 1, 'two', [4, 'five']]
>>> nums = [0, 1, 2, 3, 4]
>>>
List Operators and Functions
IoTM4W3L3.1.png

Lecture 3.2 Lists Methods

List Methods
>>> lst = [1, 2, 3]
>>> lst.append(8)
>>> lst
[1, 2, 3, 8]
IoTM4W3L3.2.png

Lecture 3.3 Control Flow

Control Flow

Statements that change the order in which lines or code are executed

  1. if statement
  2. for loop
  3. while loop
If statement

Template:

if <condition>:
    <indented code block>
<non-indented statement>

Example:

if temp > 80:
    print('It is hot!')
print('Goodbye.')
If-else statement

Template:

if <condition>:
    <indented code 1>
else:
    <indented code 2>
<non-indented statement>

Example:

if temp > 80:
    print('hot!')
else:
    print('not hot.')
print('Goodbye.')
For Loop
>>> name = 'Ian'
>>> for char in name:
     print(char)
I
a
n
>>>
For Example
>>> for name in ['Jon', 'Mary', 'Pete']:
     print(name)
Jon
Mary
Pete
>>>
While Loop
>>> i = 0
>>> while i < 3:
     print(i)
     i = i + 1
0
1
2
>>>

Week 4

Reading material

Lesson 1

Lecture 1.1 General Purpose IO Pins

GPIO Pins Raspberry Pi B+
IoTM4W4L1.1.png
General Purpose/Multi-Function
UART Pins

Lecture 1.2 Protocol Pins

I2C Pins
SPI Communication Pins

Lecture 1.3 GPIO Access

GPIO Access in Python
Pin Numbering Modes

Two ways to refer to the pins

  1. The number of the pins in their order on the board
    • Shown in circles in the picture
  2. The Broadcom SoC number
    • Shown in rectangles, after "GPIO"
Selection Pin Numbering Mode

GPIO.setmode(GPIO.BOARD)

GPIO.setmode(GPIO.BCM)

Lesson 2

Lecture 2.1 General Purpose IO Pins

Pin Direction and Assignment

GPIO.setup(13, GPIO.OUT)

GPIO.setup(13, GPIO.OUT)

Blink an LED
import Rpi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.OUT)
while True:
    GPIO.output(13, True)
    time.sleep(1)
    GPIO.output(13, False)
    time.sleep(1)
Reading Input Pins

GPIO.setup(13, GPIO.IN)

value = GPIO.input(13)

Lecture 2.2 Pulse Width Modulation

Pulse Width Modulation

PWM functions in GPIO library

PWM Initialization

pwm_obj = GPIO.PWM(18, 400)

pwm_obj.start(100)

PWM Control

pwm_obj.ChangeDutyCycle(50)

Frequency Control
While True:
    GPIO.output(18, True)
    time.sleep(0.5)
    GPIO.output(18, False)
    time.sleep(0.5)

Lecture 2.3 Demo of a Blink

Lesson 3

Lecture 3.1 Graphic User Interface

Graphic User Interface
Event Loop

Lecture 3.2 Tkinter Library

Tkinter
from Tkinter import *
root = Tk()
root.geometry('800x600')
c = Canvas(root, width=800, height=600)
c.pack()
r = c.create_rectangle(0, 0, 50, 50, fill='red', outline='red')

Opens a window with a red rectangle in the corner

Lecture 3.3 Interaction

Scale Widget
from Tkinter import *
master = Tk()
w = Scale(master, from_=0, to=100, orient=HORIZONTAL)
w.pack()
Interacting with the Widget
w = Scale(master, from_=0, to=100, orient=HORIZONTAL, command = update)

def update(duty):
    pwm.ChangeDutyCycle(float(duty))
上一篇 下一篇

猜你喜欢

热点阅读