6.2 Everything Becomes Programmable-MIQ
6.2 Everything Becomes Programmable-MIQ
6.2 Everything Becomes Programmable-MIQ
Programmable
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
Apply Basic Programming to
Support IoT Devices
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Basic Programming Concepts
Follow the Flowchart
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
Basic Programming Concepts
Flowcharts
Flowcharts:
▪ Diagrams that are used to
represent processes or
workflows.
▪ Illustrate how a process
should work.
▪ Show input states, any
decisions made, and the
results of those decisions.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
Basic Programming Concepts
System Software, Application Software, and Computer Languages
▪ Two common types of computer
software: system software and
application software.
• Application software programs are
created to accomplish a certain task or
collection of tasks.
• System software works between the
computer hardware and the application
program.
• Both system software and application
software are created using a
programming language.
• Python is an example of an interpreted
programming language.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
Basic Programming Concepts
Programming Variables
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
Basic Programming Concepts
Basic Program Structures ▪ Most common logic structures are:
• IF – THEN allows the computer to make a decision
based on the result of an expression.
• myVar > 0
• True if the value stored in the myVar variable is greater than
zero.
• If false, the computer moves on to the next structure,
• If true, the computer executes the associated action before
moving on to the next instruction in the program.
• FOR Loops execute a specific set of instructions a
specific number of times, based on an expression.
• A variable acts as a counter inside a range of values
identified by a minimum and a maximum. Every time the
loop is executed, the counter variable is incremented.
When the counter is equal to the defined maximum value,
the loop is abandoned and the execution moves on to the
next instruction.
• WHILE Loops execute a specific set of instructions
while an expression is true.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
Basic Programming Concepts
Lab – Create a Process Flowchart
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
Basic Programming Using Blockly
What is Blockly
Setting Up a Variable
Work Space
▪ Visual programming tool created to help beginners understand the concepts of programming. Allows
a user to create a program without entering any lines of code.
▪ Assigns different programming structures to colored blocks which contain slots and spaces to allow
programmers to enter values. Programmers can connect structures together by dragging and
attaching the appropriate blocks.
▪ Specific blocks represent functions. Select and drag function blocks to the work space and fill in the
required slots.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
Basic Programming Using Blockly
Blockly Games
https://blockly-games.appspot.com/
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
Basic Programming Using Blockly
Lab – Blinking an LED Using Blockly
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
Programming with Python
What is Python?
Guessing
Guessing
Game with
Game with
Python
Blockly
▪ Python is a very popular language that is designed to be easy to read and write.
▪ The Python interpreter understands and executes Python code. Python code can be created in any
text editor and Python interpreters are available for many operating systems.
▪ In Linux machines, the Python interpreter is usually installed in /usr/bin/python or /usr/bin/python3.
▪ With the new Windows Python installer, Python is installed by default into the user’s home directory.
After the Python interpreter has been installed, it operates somewhat like the Linux shell. This means
that when called with no arguments, it reads and executes commands interactively. When called with
a file name argument or with a file as standard input, it reads and executes a script from that file.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
Programming with Python
The Python Interpreter (Cont.)
IF-THEN Block
▪ To start the interpreter, simply type python or python3 at the shell prompt.
▪ In interactive mode, the interpreter waits for commands. The primary prompt is represented by three
greater-than signs (>>>). Continuation lines are represented by three dots (...).
▪ The >>> prompt indicates the interpreter is ready and waiting commands.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
Programming with Python
Variables and Basic Statements in Python
▪ The interpreter receives and executes statements interactively.
▪ To assign values to
▪ Attempts to use a not defined variable will
variables, use the = sign.
result in an error.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
Programming with Python
Variables and Basic Statements in Python (Cont.)
▪ The interpreter receives and executes statements interactively.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
Programming with Python
Useful Functions and Data Types in Python (Cont.)
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
Programming with Python
Useful Functions and Data Types in Python (Cont.)
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
Programming with Python
Useful Functions and Data Types in Python (Cont.)
▪ A dictionary is a list of
elements that are separated
by commas.
▪ Each element is a
combination of a value and a
unique key.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 21
Programming with Python
Programming Structures in Python
▪ FOR Loop
▪ IF-THEN, ELSE, ELIF • Iterates the items of any ▪ WHILE Loop
• Make decisions based upon the sequence (a list or a string),
in the order that they appear • Executes a block of code if
result of an expression the expression is true
in the sequence
• ELSE specify instructions to be
executed if the expression is false.
• ELIF is used to perform a second
test.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 22
Programming with Python
Lab – Setting Up a Virtualized Server Environment
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 23
Programming with Python
Lab – Basic Python Programming
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 24
Programming with Python
Lab – Create a Simple Game with Python
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 25
Prototyping Your Idea
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 26
What is Prototyping?
Defining Prototyping
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 27
What is Prototyping?
How to Prototype
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 28
Prototyping Resources
Physical Materials
▪ A good place to start is, of course, the Internet. People who have never physically met can now
collaborate and work together.
▪ Maker Media is a global platform for connecting makers with each other to exchange projects and
ideas.
▪ Meccano, or Erector Set, is a model construction system that consists of reusable metal strips,
plates, angle girders, wheels, axles, and gears, with nuts and bolts to connect the pieces. It lets
you build working prototypes and mechanical devices.
▪ 3D printing is the process of making a solid object based on a 3D model computer file.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 29
Prototyping Resources
Electronic Toolkits
▪ While you can create programs for almost any computer, some platforms are designed for the
beginner. Below you will find some of the most popular platforms:
• Arduino is an open-source physical computing platform based on a simple microcontroller board, and a
development environment for writing software for the board. You can develop interactive objects that take
input from a variety of switches or sensors to control lights, motors, and other physical objects.
• Raspberry Pi is a low cost, credit-card-sized computer that plugs into a computer monitor or TV. You
operate it using a standard keyboard and mouse. It is capable of doing everything a computer can do,
from browsing the Internet and playing high-definition video, to making spreadsheets, word-processing,
and playing games.
• The Beaglebone is very similar to the Raspberry Pi in size, power requirements, and application. The
Beaglebone has more processing power than the Raspberry Pi; therefore, it is a better choice for
applications with higher processing requirements.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 30
Prototyping Resources
Programming Resources
▪ Programming is critical to the IoT. Creating custom code is very useful when developing an IoT
solution. There are many other free resources that can help you get started with programming:
• The MIT OpenCourseWare (OCW) is a web-based publication of almost all MIT course content. Open
and available to the world, OCW is a great place to get familiar with computer programming for free.
OCW programming related courses can be found at http://ocw.mit.edu/courses/intro-programming.
• Khan Academy is a non-profit educational website created in 2006 to provide “a free, world-class
education for anyone, anywhere”. The lectures related to computer programming can be found
at https://www.khanacademy.org/computing/cs.
• Code Academy is another excellent resource. It relies on interactivity to help people learn how to write
computer programs. You can find them at http://www.codeacademy.com.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 31
Prototyping Resources
Community Inventor and Entrepreneurship Workshops
▪ So, perhaps you have just created something
really great. What now? There are a number of
places where you can get help exposing your idea
or prototype to others.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 32
Prototyping Resources
Optional Lab – Setting up PL-App with the Raspberry Pi
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 33
Prototyping Resources
Optional Lab – Using a PL-App Notebook
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 34
Prototyping Resources
Optional Lab – Blinking an LED using Raspberry Pi and PL-App
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 35
Prototyping Resources
Optional Lab – Introduction to Arduino
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 36
Chapter Summary
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 37
Chapter Summary
Summary
▪ Flowcharts are diagrams that are used to represent processes.
▪ There are two common types of computer software: system software and application software.
Application software programs are created to accomplish a certain task. System software works
between the computer hardware and the application program.
▪ The most common logic structures are IF – THEN, FOR Loops, and WHILE Loops.
▪ Blockly is a visual programming tool created to help beginners understand the concepts of
programming. Blockly implements visual programming by assigning different programming
structures to colored blocks.
▪ Python is a very popular language that is designed to be easy to read and write. Python is an
interpreted language; therefore, an interpreter is required to parse and execute Python code.
▪ Python supports many useful functions and datatypes including Range(), Tuples, Lists, Sets,
Dictionary. Python also implements two sub-structures named ELSE and ELIF.
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 38