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/UCC_Course_2021/WebHome
Other pages for class resources
https://github.com/uraich/IoT-Course
Our processor needs interfaces to these sensors and actuators.
that read out sensors and/or control actuators
These processors communicate with each other
over the Internet with or without human intervention.
Design decisions:
The Raspberry Pi is a small computer powerful enough to run a full blown Linux operating system: A quad core 1.2 GHz Broadcom 64 bit ARM CPU
|
![]() |
ESP8266 or ESP32 processor board ESP8266 specs:
ESP32 is even more powerful Cost: ~ 4.5 US$ |
![]() |
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.
For Python beginners: https://docs.python.org/3/tutorial/index.html
and for everybody the Python docs: https://docs.python.org/3/index.html
Python is powerful... and fast;
plays well with others;
runs everywhere;
is friendly & easy to learn;
is Open.
Type print(“Hello world”). Hit enter and it prints Hello world on the screen.
To exit from the interactive mode, type quit().
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.
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
python3 scriptName
or we can make it executable and run it like we would run
any compiled C program or any bash script:
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 .
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.
We discuss the following data types
Python accepts either pair of single, double quotes and triples(single/double) quotes.
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.
They are enclosed in brackets().
Their content cannot be changed unlike the list whose content can be changed.
Thus tuples are read only.
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.
Python has two primitive loop commands:
Python comes with builtin functions such as print().
Users can define and use their own functions in the code.
User defined functions begin with the keyword def followed by the name of the function.
A function may take parameters
We may want to keep function definitions in separate files
and use these definitions in several main programs.
In our example of the functions we can save the definitions in a file called function.py
In order to use the definitions we must import them with
import function
In order to call the functions we have to use the module name:
function.sum(20,30)
or if we we want to import a single function:
from function import sum
sum(20,30)
The module name is found in the variable name
However it is also possible to include the function calls (the main routine)
into the module e.g. to demonstrate how the functions are to be used.
In this case the name of the module changes to __main__
We can therefore find out if the module is imported or executed by checking the name variable:
if __name __ == "__main__"
this executes the main code only if not imported into a main program
Each package is a directory which MUST contain a specific file called
__init__.py indicating the directory is a package.
the __ init __.py file may be empty.
Package can be imported the same way as module.
Suppose we have several modules prime.py, fibonacci.py, factorial.py
in a directory, we may group them in a package called priff.
A class defines the behavior of an object and the kind of information an object can store.
The information in a class is stored in attributes, and functions that belong to a class are called methods.
A child class inherits the attributes and methods from its parent class.
You may define a method with name __init__which is called when
the instance object of the class is created (in the above example: mc = MyClass)
The short description of the class can be found in the instance variable __Doc.__
perform many actions without writing your code
A very typical example of a python library is matplotlib for plotting.
GUI elements (widgets) are set up by the programmer and events are attached to them.
Typical examples are:
(the callback functions) when any of the above events happens. The event is then
acted upon and control is returned to the GUI main loop.
The main loop will wait for an event (2 s elapsed) and call the callback function when
the event has occurred.
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
![]() |
Home_page.png | r1 | manage | 534.7 K | 2023-11-27 - 09:43 | UliRaich | |
![]() |
arduino.png | r1 | manage | 191.1 K | 2021-02-07 - 19:31 | IsaacArmahMensah | |
![]() |
commandline.png | r1 | manage | 23.9 K | 2023-11-27 - 10:02 | UliRaich | |
![]() |
dictionary.png | r1 | manage | 217.8 K | 2021-02-07 - 20:30 | IsaacArmahMensah | |
![]() |
list.png | r1 | manage | 206.8 K | 2021-02-07 - 20:26 | IsaacArmahMensah | |
![]() |
mosquittoDemo.png | r1 | manage | 522.0 K | 2023-11-27 - 10:14 | UliRaich | |
![]() |
mqtt.png | r1 | manage | 53.5 K | 2021-02-07 - 19:36 | IsaacArmahMensah | |
![]() |
raspberry-pi-3-b.jpg | r1 | manage | 78.4 K | 2023-11-27 - 09:45 | UliRaich | |
![]() |
raspberry-pi.webp | r1 | manage | 583.5 K | 2021-02-07 - 19:25 | IsaacArmahMensah | |
![]() |
raspberry_pi.png | r1 | manage | 914.0 K | 2021-02-07 - 19:27 | IsaacArmahMensah | |
![]() |
script.png | r1 | manage | 139.9 K | 2021-02-07 - 15:06 | IsaacArmahMensah | |
![]() |
sheild.png | r1 | manage | 743.0 K | 2021-02-07 - 19:34 | IsaacArmahMensah | |
![]() |
string.png | r1 | manage | 31.2 K | 2023-11-27 - 10:13 | UliRaich | |
![]() |
uno.png | r1 | manage | 254.6 K | 2023-11-27 - 09:55 | UliRaich | |
![]() |
variable.png | r1 | manage | 33.5 K | 2023-11-27 - 10:19 | UliRaich | |
![]() |
wemosShields.png | r1 | manage | 388.3 K | 2023-11-27 - 09:55 | UliRaich | |
![]() |
while.png | r1 | manage | 146.3 K | 2021-02-07 - 20:26 | IsaacArmahMensah |