Internet of Things (20CS002) Department of Computer Science and Engineering Vignan's Foundation for Science, Technology & Research
IoT building blocks Nodes: This block alludes to the collection of information which is further shared over the network and processed by an IoT system. This can be carried out using sensors, which require power in the form of heat, vibration, battery or wireless power transfer. Gateway/Bridge/Router: This block is mainly the transmission stage in which the information is shared over the network with the help of servers, to be processed further. Cloud: The cloud computing is a part of service platform and enabler that involves handling, breaking down data streams and forwarding the data further for IoT applications. Ref: A . Prasad and P. Chawda , "Power management factors and techniques for IoT design devices," 19th International Symposium on Quality Electronic Design (ISQED) , 2018, pp. 364-369, doi : 10.1109/ISQED.2018.8357314.
IoT building blocks Ref: https://www.scnsoft.com/blog/iot-architecture-in-a-nutshell-and-how-it-works
Block diagram of an IoT Device
Arduino It's an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board. Arduino Nano Arduino Mega Arduino LilyPad Arduino Mini Arduino Leonardo Arduino Uno
Arduino boards comparison Ref: https://forum.core-electronics.com.au/t/arduino-boards-compared/167 Types of memory, Ref: https://www.electronicshub.org/types-of-memory-on-arduino/
Arduino UNO Digital pins: 14 digital IO pins 6 are PWM pins (3, 5, 6, 9, 10, and 11) Analog pins: 6 analog pins(A0, A1, A2, A3, A4, and A5) Takes analog values as an input What is analog ? It is continuous range of voltage values (not just 0 or 5V) Why convert to digital ? Because our microcontroller only understands digital.
Arduino: Integrated Development Environment Following steps are required to setup an Arduino board Power the board by connecting it to a PC via USB cable Launch the Arduino IDE Open the project Select the Arduino board Select the serial port Upload the program to board
Arduino: Integrated Development Environment
Structure of an Arduino code 1. Define Variables 2. Setting up functions 3. Eternal loop void setup () {} void loop () {} Setup function is run once, when the microcontroller boots up or resets. After setup function the processor moves to run code inside the loop function. Code inside loop function will be run over and over until the microcontroller is shut down. int pin = 1; Before going to the setup function constant variables should be defined
Arduino C – Basic functions pinMode(var1, var2) pinMode functions sets the mode of given pin . Var1 is PIN number and var2 is the mode (INPUT, OUTPUT) digitalWrite changes the status of the pin . var1 is PIN number and var2 is the status (LOW, HIGH). digitalWrite(var1, var2) digitalRead(var1) digitalRead returns the current status (LOW, HIGH) of the pin . var1 is PIN number analogRead(var1) AnalogRead returns a 10-bit (by default) value equal to the voltage of the pin relative to the analog reference voltage. AnalogWrite sets a pin (var1) to a voltage relative to the analog reference voltage equal to an 8-bit (by default) value. analogWrite(var1, var2)
LED On/ Off Program int ledPin = 13; //Variable to store the pin number void setup () { pinMode ( ledPin , OUTPUT ); //set ledPin as output } void loop () { digitalWrite ( ledPin , HIGH ); //LED ON delay (1000); //Wait 1000ms digitalWrite ( ledPin , LOW ); //LED OFF delay (1000); //Wait 1000ms }
Fading in and Fading Out (Analog or Digital?) To create an analog signal, the microcontroller uses a technique called Pulse Width Modulation (PWM) . By varying the duty cycle , mimic an “average” analog voltage.
Fading in and Fading Out (Analog or Digital?) analogWrite (pin, val ); pin – refers to the OUTPUT pin ( 3, 5, 6, 9, 10, 11) val – 8 bit value (0 – 255). 0 => 0V | 255 => 5V
Fading - Code
Fading - Code
Recommended Books By Simon Monk By John Boxall By Jeremy Blum
What is the Raspberry Pi? Affordable credit-card sized computer Plugs into a computer monitor or TV Uses standard keyboard and mouse Can browse the internet and play HD video Can also interact with the outside world!
Raspberry Pi Foundation Educational charity based in the UK The Foundation’s goal is to advance the education of adults and children in the field of computers, computer science, and related subjects. https://www.raspberrypi.org/about
Corral-García, J., Lemus-Prieto, F., González-Sánchez, J.L. and Pérez-Toledano, M.Á., 2019. Analysis of energy consumption and optimization techniques for writing energy-efficient code. Electronics , 8 (10), p.1192. Raspberry Pi Models Comparison
Arduino vs Raspberry Pi
Raspberry Pi OS Raspbian Raspbian Linux is a Debian Wheezy port optimized for Raspberry Pi. Arch Arch is an Arch Linux port for AMD devices. Pidora Pidora Linux is a Fedora Linux optimized for Raspberry Pi. RaspBMC RaspBMC is an XBMC media-center distribution for Raspberry Pi. OpenELEC OpenELEC is a fast and user-friendly XBMC media-center distribution. RISC OS RISC OS is a very fast and compact operating system. Ref: https://raspberrytips.com/best-os-for-raspberry-pi/
Raspberry Pi
A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose input/output) pins along the top edge of the board. "General Purpose Input/output." GPIO is a type of pin found on an integrated circuit that does not have a specific function. While most pins have a dedicated purpose, such as sending a signal to a certain component, the function of a GPIO pin is customizable and can be controlled by software. A 40-pin GPIO header is found on all current Raspberry Pi boards Any of the GPIO pins can be designated (in software) as an input or output pin and used for a wide range of purposes. Raspberry Pi
PWM (pulse-width modulation) PWM works by pulsating DC current and varying the amount of time that each pulse stays 'on' to control the amount of current that flows to a device such as an LED. Software PWM available on all pins Hardware PWM available on GPIO12, GPIO13, GPIO18, GPIO19 Serial Peripheral Interface (SPI) A communication protocol used to transfer data between micro-computers like the Raspberry Pi and peripheral devices(sensors or actuators). SPI0: MOSI (GPIO10); MISO (GPIO9); SCLK (GPIO11); CE0 (GPIO8), CE1 (GPIO7) SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18); CE1 (GPIO17); CE2 (GPIO16) For example, SD card modules, RFID card reader modules, and 2.4 GHz wireless transmitter/receivers all use SPI to communicate with microcontrollers. One unique benefit of SPI is the fact that data can be transferred without interruption. Raspberry Pi
I2C It is a useful bus that allows data exchange between microcontrollers and peripherals with a minimum of wiring. Data: (GPIO2); Clock (GPIO3) EEPROM Data: (GPIO0); EEPROM Clock (GPIO1) Seen in projects that use OLED displays, barometric pressure sensors, or gyroscope /accelerometer module. Serial The serial port is a low-level way to send data between the Raspberry Pi and another computer system. This can be useful if you want the Raspberry Pi to control another device. TX (GPIO14); RX (GPIO15) UART stands for Universal Asynchronous Receiver/Transmitter DIY electronics projects to connect GPS modules, Bluetooth modules to your Raspberry Pi. A UART’s main purpose is to transmit and receive serial data. One of the best things about UART is that it only uses two wires to transmit data between devices. Raspberry Pi
Configuring the Pi Installing the Operating System The micro SD that you have comes pre-installed with the Linux based Raspbian OS. Raspbian is a fork of another Linux distribution called Debian.
Configuring the Pi Login: pi Password: raspberry How to log into the Raspberry Pi for the first time You won’t see the password as you type it. This is a Linux security feature.
Configuring the Raspberry Pi for the first time Launch the Raspberry Pi Configuration Tool ~$ sudo raspi-config Configuring the Pi
Setting the keyboard layout 1. Choose option 4 Internationalization Options Configuring the Pi
Setting the keyboard layout 2. Choose option I3 Change Keyboard Layout Configuring the Pi
Setting the keyboard layout 3. Choose an appropriate US keyboard type Configuring the Pi
Setting the keyboard layout 4. Choose English (US) for keyboard layout Configuring the Pi
Setting special command keys for the keyboard 5. Choose the default for the keyboard layout Configuring the Pi
Setting special command keys for the keyboard 6. Select No for the Control+Alt+Backspace command Configuring the Pi
Enabling the camera socket 7. Choose option 5 Enable Camera Configuring the Pi
Enabling the camera socket 8. Select Enable Configuring the Pi
Configuring the Pi Optional: Set to automatically boot to GUI 9. Choose option 3 Enable Boot to Desktop/Scratch
Configuring the Pi Optional: Set to automatically boot to GUI 10. Select Log in as user ‘pi’ at the graphical desktop then select Ok
Configuring the Pi Exit the configuration tool 11. Select Finish
Configuring the Pi Exit the configuration tool 12. Select Yes if prompted to reboot
WiFi Setup Login: pi Password: raspberry The Command Line ~$ Type the following command and press ENTER ~$ startx
WiFi Setup The Raspbian Desktop
WiFi Setup Confirm that the WiFi dongle has been detected Click the LXTerminal button in the top left menu bar Type the command below into the command line ~$ ifconfig
WiFi Setup Confirm that the WiFi dongle has been detected You should see wlan0 in the list You can close the terminal by typing exit and pressing ENTER if wlan0 is in the list
WiFi Setup Connect to ND-Guest Click the menu button find Preferences From Preferences select WiFi Configuration
WiFi Setup Connect to ND-Guest Click the Scan button Double click ND-Guest from the list
WiFi Setup Connect to ND-Guest 9. Click on the Add button without making any changes to ND-Guest
WiFi Setup Connect to ND-Guest Make sure ND-Guest is the selected network Click the Connect button
WiFi Setup The Wifi connection should now be working The WiFi Configuration Tool will be running in the background. See it in the top right corner of your screen.
Command Line The command line gives you more control Click on the LXTerminal button in the top left menu bar. This will give you access to a console that can do everything the GUI can and more.
Command Line Echo will print the argument to the console.
Command Line Man will show you the manual page for the argument. Press Q on the keyboard to exit the manual page.
Command Line Apropos is used to search the manual page descriptions for the specified keyword. You can find commands with “copy” in their descriptions as an example.
Command Line Clear will move the prompt to the top of the console window. This effectively clears the console.
Command Line Pwd will print the current working directory path. This is basically “where you are” with this console.
Command Line ls list the directories in the current working directory.
Command Line Most commands have options (arguments) that change their behavior. The options usually start with a “-” and are typed after the command. ~$ ls -a Display hidden files ~$ ls -l List files in long format
Command Line Using both “a” and “l” after the ls command.
Command Line mkdir will create a new directory with the name you specify after the command. Use mkdir and then use ls to see the directory created .
Command Line Create and open a simple text file with leafpad myfile.txt This creates a text file called myfile.txt and opens it in a text editor called l eafpad automatically. Type a short message
Command Line Use the ls command to see the new text file. If you want to view the contents of the text file without opening LeafPad back up, use the cat command followed by the file name.
Command Line cp will copy your file to the specified directory. In this example you can type ls /home/pi to see the copied file.
Command Line rm will remove the specified file or files. Add the argument “-v” (verbose) to have an explanation of what is being done printed to the console.
Command Line Updating the Raspberry Pi Sudo means Super-User DO and is followed by a command that requires the super-user to complete. Apt-get is a package manager that you use to install, update, and upgrade your software. Wget is used to access files from the internet.
Command Line U pdating the Raspberry Pi Use the following command to download a file I have prepared from the internet. The file will be downloaded into your current working directory. ~$ wget http s:/www.dropbox.com /s/ pLmz498wo3kgnpj/ss2015.tar
Command Line Updating the Raspberry Pi A file called update-script.sh is in the ss2015 directory. This is a shell script. It’s a text file that contains console commands that will execute if you run the shell script. Type cat update-script.sh to see the contents of the script. ~$ cat update-script.sh
Command Line Updating the Raspberry Pi Try to run the shell script by typing the following: ~$ ./update-script.sh What did it do?
Command Line Updating the Raspberry Pi You need to set permissions for the shell script file. Type ls -l to see the permissions for the files in ss2015 . R = read, W = write, X = execute Owner Group World r w x r w x r w x
Command Line Updating the Raspberry Pi File to have full permissions for the owner, and read/execute permissions for all others. We use the chmod command to accomplish this. ~$ chmod 755 update-script.sh
Command Line Updating the Raspberry Pi You can use ls -l to see that the file now has the proper permissions. - rwxr - xr -x
Command Line Installing the Python Pi Camera module To install this module type the following: ~$ sudo apt-get install python- picamera If you are prompted to confirm any of your updates, just press Y and then press ENTER .
Python and PiCamera Controlling the Pi Camera with Python Before Python execution , run this command in a console: ~$ raspistill -v -o ss2015.jpg
Python and PiCamera Controlling the Pi Camera with Python This command will take a picture with the Pi Camera using the default settings. The picture will be called “ss2015.jpg” (unless you called it something else). The text that printed out are all options , can control.
Python and PiCamera Controlling the Pi Camera with Python Lets launch IDLE from the console, which is an integrated development environment for Python.
Python and PiCamera Controlling the Pi Camera with Python First, t ype import os and press ENTER so have access to operating system functionality. This will let us call the raspistill command from inside of IDLE with Python.
Python and PiCamera Controlling the Pi Camera with Python Call the same command we used earlier in the console. To do that type the following: os.system (“ raspistill -v -o hello.jpg”)
Python and PiCamera Controlling the Pi Camera with Python Now try using some of these options for the camera: -w 600 –h 800 –q 70 – ifx cartoon
Python and PiCamera Controlling the Pi Camera with Python Take video with the camera: os.system (“ raspivid -o myvideo.h264”)
Python and PiCamera Controlling the Pi Camera with Python Use this command to see a small preview of your video: os.system (“ omxplayer --win ‘0 320 240’ myvideo.h264”) Or this to see it full size: os.system (“ omxplayer myvideo.h264”)
Python and PiCamera Options for the raspistill and raspivid commands -o -w -h - sh - co -br - sa -vf -hf output file name (-o picture.jpg or vid.h264) width (-w 600) height (-h 800) sharpness, -100 to 100 (-sh 75) contrast, -100 to 100 (-co 50) brightness, to 100 (-br 65) saturation, -100 to 100 (-sa 85) vertically flip image horizontally flip image
Python and PiCamera jpeg image quality, to 100 (-q 70) image effects (-ifx negative, solarise , sketch, oilpaint , hatch, pastel, film, watercolour, emboss, blur, cartoon, and more!) Options for the raspistill and raspivid commands -q -ifx There are many more options for the Pi Camera: https://www.raspberrypi.org/documentation/raspbian /applications/camera.md