Start Presentation

Slide 1: Introduction to Internet of Things (IoT)

Session 1: Introduction to IoT and Python

Isaac Armah-Mensah

University of Cape Coast, Ghana

Slide 2: Introduction of Lecturers

  1. Uli Raich -- Formally CERN, Geneva, Switzerland
  2. Isaac Armah-Mensah -- University of Cape Coast Ghana

Slide 3: The TWiki server

All information about this tutorial is available on a TWiki server.

TWiki uses the same documentation format as Wikipedia.

This makes it very simple for the lecturer to provide on-line documentation,

which can be extended by students.

This is our Twiki server:

https://afnog.iotworkshop.africa/do/view

Other pages for class resources

Micropython Demos:

https://github.com/uraich/MicroPython_IoTDemos and
https://github.com/uraich/MicropythonCayenneMQTTClient

C++ version:
https://github.com/uraich/C-IoTDemos

Slide 4: Workshop Page

workshop.png

Slide 5: The Internet of Things (IoT)

When the Internet was invented it was used for communications between humans

Typical applications where:

  • Email

  • Remote login

  • File transfers

With cheaper and more powerful micro-controllers devices can communicate with each other

or with centralized servers over the network and they can observe their environment

with dedicated sensors.

This is what we call the Internet of Things (IoT)

Slide 6: Introduction to Python

The python programming language is a high level programming language that is very interactive and object oriented.

Python is an interpreted language which means that the statements which make up the python program is processed at run-time but not compiled first.

Python also supports object oriented programming style which employs the use of encapsulating codes within objects.

What can python be used for?

  • Used to create web applications.

  • Used to connect to database systems.

  • It can be used to perform complex mathematics

  • It can be used in data analysis.

If you want to learn Python, Try the Python tutorial!

For Python beginners: https://docs.python.org/3/tutorial/index.html

and for everybody the Python docs: https://docs.python.org/3/index.html

Slide 7: Writing Python Programs

Python is a programming language that lets you work more quickly and integrate your systems more effectively.

  • Python is powerful... and fast;

  • plays well with others;

  • runs everywhere;

  • is friendly & easy to learn;

  • is Open.

Python programs can either be written using any standard editor like nano, emacs as a script or can be written from the python command line.

Slide 8: Using the Command Line (Interactive mode)

Simply type python in your terminal and press the enter key to start the interactive python mode.

Type print(“Hello world”). Hit enter and it prints Hello world on the screen.

commandline.png

To exit from the interactive mode, type quit().

Slide 9: Using the script mode

Using the interactive mode doesn’t keep the statements of code we wrote permanently .

But in an ideal situation we might want to keep the codes for future reference.

Hence we make use of an editor like the nano, emacs, etc.

helloworld.png

helloworld2.png

Slide 10: Using Thonny

Instead of running a standard editor like nano or emacs you may want to run

an Integrated Development Environment (IDE) created specifically for Python instead.

Thonny is Easy to get started. Thonny comes with Python 3.7 built in,
so just one simple installer is needed and you're ready to learn programming.

It is very suitable for beginners and programming micro-controllers

For basic description of Thonny check https://thonny.org/ and https://realpython.com/python-thonny/

Lets try thonny

Slide 11: Thonny Python Shell and Editor

Here you see the 2 idle windows.

The top one contains the editor, the second the Python shell

thonny.png

Slide 12: Running a python script

Script in python can be run from the Linux command shell with:

python3 scriptName

or we can make it executable and run it like we would run

any compiled C program or any bash script:

runpython.png

Slide 13: Command Line Arguments

Programs can be called with arguments.

Python has a module that helps users parse command-line options and arguments.

Many programs can be run to provide basic information about how they
should be run and it employs the use of command line arguments.

The Python sys module provides access to any command-line arguments via the sys.argv .

argscript.png

runcmdlineArg.png

Slide 14: Variables

Variables are just memory allocations for storing values.

Every variable created has a space in memory allocated for it.

Based on the data type of a variable, the interpreter allocates memory and
decides what can be stored in the reserved memory.

Python variables do not need explicit declaration to reserve memory space.

The declaration happens automatically when you assign a value to a variable.

The equal sign (=) is used to assign values to variables.

The operand to the left of the = operator is the name of the variable and
the operand to the right of the = operator is the value stored in the variable.

variable.png

Slide 15: Data Types in Python

Programs store data in one form or the other and must be of a certain type.

We discuss the following data types

Slide 16: Strings in Python

Strings in Python are identified as a contiguous set of characters represented in the quotation marks.

Python accepts either pair of single, double quotes and triples(single/double) quotes.

string.png

Slide 17: List in Python

The list is a most versatile datatype available in Python.

It can be written as a list of comma-separated values (items) between square [] brackets.

A list need not be of the same type.

The values present in a list are indexed starting from zero.

The values stored in a list can be accessed using the slice operator ([ ] and [:]) with
indexes starting at 0 in the beginning of the list and working their way to end -1.

list.png

Slide 18: Tuple in Python

Tuples are much more like a list.

They are enclosed in brackets().

Their content cannot be changed unlike the list whose content can be changed.

Thus tuples are read only.

tuples.png

Slide 19: Dictionary in Python

A dictionary is a collection which is unordered, changeable and indexed.

In Python dictionaries are written with curly brackets, and they have keys and values.

Python's dictionaries allow you to connect pieces of related information.

Each piece of information in a dictionary is stored as a key-value pair.

When you provide a key, Python returns the value associated with that key.

You can loop through all the key-value pairs, all the keys, or all the values.

dict.png

Slide 20: Basic Operators

Python supports multiple operators including

  • arithmetic,
  • comparison,
  • assignment,
  • logical,
  • bitwise,
  • membership and
  • identity operators.

Slide 21: Arithmetic Operators:

The arithmetic operators supported by python is addition(+) , subtraction(-),
multiplication(* ), division(/), modulus(%), exponent(**)

operators.png

Slide 22: Python Bitwise Operators

Bitwise operator works on bits and performs bit-by-bit operation

binaryops.png


-- Isaac Armah-Mensah - 2019-05-30

Comments


Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng argscript.png r1 manage 29.7 K 2019-06-09 - 03:30 IsaacArmahMensah  
PNGpng binaryops.png r1 manage 130.0 K 2019-06-10 - 20:46 IsaacArmahMensah  
PNGpng commandline.png r2 r1 manage 61.2 K 2019-06-09 - 02:44 IsaacArmahMensah  
PNGpng commandlinearg.png r1 manage 15.5 K 2019-06-09 - 03:21 IsaacArmahMensah  
PNGpng dict.png r1 manage 193.5 K 2019-06-10 - 20:24 IsaacArmahMensah  
PNGpng helloworld.png r2 r1 manage 5.8 K 2019-06-09 - 02:24 IsaacArmahMensah  
PNGpng helloworld2.png r2 r1 manage 22.0 K 2019-06-09 - 02:25 IsaacArmahMensah  
PNGpng idle.png r1 manage 105.5 K 2019-06-09 - 02:57 IsaacArmahMensah  
PNGpng idlescript.png r1 manage 39.8 K 2019-06-09 - 03:03 IsaacArmahMensah  
PNGpng idleshell.png r1 manage 33.7 K 2019-06-09 - 03:03 IsaacArmahMensah  
PNGpng if.png r1 manage 45.2 K 2019-06-10 - 21:19 IsaacArmahMensah  
PNGpng list.png r2 r1 manage 198.2 K 2019-06-10 - 20:28 IsaacArmahMensah  
PNGpng loops.png r1 manage 150.9 K 2019-06-10 - 21:19 IsaacArmahMensah  
PNGpng operators.png r1 manage 113.4 K 2019-06-10 - 20:47 IsaacArmahMensah  
PNGpng runcmdlineArg.png r1 manage 26.0 K 2019-06-09 - 03:30 IsaacArmahMensah  
PNGpng runpython.png r1 manage 102.6 K 2019-06-09 - 03:14 IsaacArmahMensah  
PNGpng string.png r3 r2 r1 manage 231.9 K 2019-06-10 - 20:28 IsaacArmahMensah  
PNGpng thonny.png r1 manage 121.5 K 2019-06-09 - 21:02 IsaacArmahMensah  
PNGpng tuples.png r1 manage 170.7 K 2019-06-10 - 20:24 IsaacArmahMensah  
PNGpng variable.png r3 r2 r1 manage 74.0 K 2019-06-09 - 21:10 IsaacArmahMensah  
PNGpng workshop.png r1 manage 250.4 K 2019-05-30 - 06:02 IsaacArmahMensah  
Edit | Attach | Watch | Print version | History: r11 | r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r6 - 2019-06-10 - IsaacArmahMensah
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback