internet of things using raspberry pi
TRANSCRIPT
Workshop on
Internet of Things using
Raspberry PiByK.THARUN KUMAR REDDYASSISTANT PROFESSOR,DEPARTMENT O ECE.KUPPAM ENGINEERING COLLEGE,KUPPAM-517425
The Internet of Things is a global network of computers, sensors, and actuators connected through Internet protocols
Introduction to IoT
Communication Options
20 metes 100 meters 3-10km 15km 10km 35km max for GSM
Projected Growth of IoT
• Internet Protocol version 4 (IPv4) addresses are 32 bits long
• IPv4 offers an address space of 2^32, roughly 4 billion IP addresses.
• This is a problem because there are more than 4 billion Internet-connected computers in the
world. And also Present World Population is 7.6 Billions.
• This has led to a shortage of IPv4 addresses.
• IPv6 is a new addressing protocol. It is the successor of IPv4.
• IPv6 addresses are 128 bits long
• IPv6 offer an address space of 2^128, which is almost equal to 340 trillion trillion trillion
addresses
• we could assign an IPV6 address to EVERY ATOM ON THE SURFACE OF THE EARTH, and
still have enough addresses left to do another 100+ earths.
Importance of IPv6 in IoT
Applications of IoT
Best IoT Hardware Platforms
Two examples:
Arduino
Raspberry Pi
• We shall use RPi in this workshop
It has lot more features!
Lets see how RPi is different than Arduino
FEATURE ARDUINO RASPBERRY PI
Speed 16 MHz 1.2 GHz
Architecture 8 bit 64 bit
RAM 8 KB 1 GB
ROM 256 KB SD CARD
Internet connection Not Easy Very Easy
Analog to Digital Yes No
Programming Language Arduino / C or C++ No Limit
Multi tasking One Program at a time Possible
ARDUINO vs RASPBERRY PI
• The Raspberry Pi is a low cost, credit-card sized computer thatplugs into a computer monitor or TV, and uses a standardkeyboard and mouse.
• It is a capable little device that enables people of all ages toexplore computing, and to learn how to program in languageslike Scratch and Python.
What is raspberry pi?
Raspberry Pi – Hardware
GPU
+
CPU
+
RAM
Broadcom BCM2837
CPU core is an ARMv8
Inter-Integrated Circuit (I²C)
• I²C is an interface on which you can connect multiple
I²C slave devices.
• The Raspberry Pi acts as the master on the bus
Board pin BCM GPIO number
Function Description
3 0 SDA DATA
5 1 SCL CLOCK
Universal Asynchronous Receiver/transmitter (UART)
• The UART is a serial bus connection.
Board pin BCM GPIO number Function Description
8 14 TX Transmit
10 15 RX Receive
Serial Peripheral Interface (SPI)
• SPI is an interface on which you can connect multiple SPI slave devices.
• The Raspberry Pi can only act as the master on the bus.
There are five pins available to connect devices to the Raspberry Pi using SPI:
Board pin BCM GPIO number
Function Description
19 10 MOSI Master Out, Slave In
21 9 MISO Master In, Slave Out
23 11 SCLK Serial Clock
24 8 CE0 Channel Enable 0. Also known as Slave Select (SS)
26 7 CE1 Channel Enable 1. Also known as Slave Select (SS)
What we can do with Raspberry Pi:
COMPUTER Arcade gaming machines using RPi
RPI Robot Landline using RPi and Google Voice RPi based decoration lights control
PIBOT SUPER COMPUTER
Basics of Python:
• Python is a simple and high-level language
• Easy to Learn
As you will see, Python is extremely easy to get started with. Python has an extraordinarily simple
syntax.
• Portable
All your Python programs will work on any of these platforms without requiring any changes at all
• Interpreted
When you use an interpreted language like Python, there is no separate compilation and execution
steps. You just run the program from the source code.
• Extensive Libraries
• Free and Open Source
• High-level Language
Programmers use Python to create things like:
Web applications
Desktop applications and utilities
Special GUIs
Small databases
2D games
To access Python from the command prompt, type “python” or “python3”, then it opens up the Python
interactive shell , from which you can enter Python commands just like you use the command line.
What you will need
Installing OS on Raspberry Pi
To install a Raspberry Pi operating system image on an SD card. You will need another computer with an SD
card reader to install the image.
Official images for recommended operating systems are available to download from the Raspberry Pi website
Downloads page.
After downloading the .zip file, unzip it to get the image file (.img) for writing to your SD card.
you need to use an image writing tool to install it on your SD card.
Ex: win32diskimager
You need to use SD Formatting Tool to format SD card
Ex: SD Card Formatter
Insert the SD card into your SD card reader.
Note the drive letter assigned to the SD card. You can see the drive letter in the left hand column of Windows
Explorer, for example F:
Download the Win32DiskImager utility and run it to install the software
Run the Win32DiskImager utility from your desktop or menu.
Select the image file you extracted earlier.
Select the drive letter of the SD card in the device box
Click 'Write' and wait for the write to complete.
Exit the imager and eject the SD card.
Insert SD Card and Power ON Raspberry Pi.
S.No Command Description
1 pwd The pwd command displays the name of the present working directory
2 ls The ls command lists the content of the current directory
3 mkdir You can use mkdir to create a new directory, e.g. mkdir tharun would create the directory tharun in the present working directory.
4 rmdir To remove empty directories, use rmdir. So, for example, rmdir tharun will remove the directory tharun only if it is empty
5 nano nano example.txt: Opens the file example.txt in the Linux text editor Nano
6 rm The command rm removes the specified file
7 touch Creates a new, empty file in the current directory.
8 date Prints the current date. To Change Date type sudo date MMDDHHmmYYYY
9 cd To Change the Directory
10 mv The mv command moves a file and places it at the specified location (so where cp performs a 'copy-paste', mv performs a 'cut-paste').
Basic Linux Commands
S.No Command Description
11 sudo The sudo command enables you to run a command as a superuser
12 unzip The unzip command extracts the files from a compressed zip file
13 wget Download a file from the web directly to the computer with wget. So wget http://www.raspberrypi.org/documentation/linux/usage/commands.md will download this file to your computer as commands.md
14 ping The ping utility is usually used to check if communication can be made with another host
15 ifconfig To check the status of the wireless connection you are using (to see if wlan0 has acquired an IP address)
16 iwconfig To check which network the wireless adapter is using.
17 iwlist Prints a list of the currently available wireless networks.
18 hostname –I The hostname –I command displays the IP address of your Raspberry Pi.
19 free Shows how much free memory is available.
20 df-h Shows information about the available disk space
S.No Command Description
21 lssub Lists USB hardware connected to your Raspberry Pi
22 apt-get update If software updates are available, you can get the updates with sudo apt-get update
23 apt-get upgrade install the updates with sudo apt-get upgrade, which will upgrade all of your packages.
24 apt-get install To upgrade a specific package, without upgrading all the other out-of-date packages at the same time, you can use sudo apt-get install some package
25 apt-get remove To uninstall a package.
26 apt-get purge To completely remove the package and its associated configuration files
27 poweroff To shutdown immediately.
28 reboot To reboot immediately
29 raspi-config Opens the configuration settings menu
30 shutdown -h 01:22 To shutdown at 1:22 AM
Establishing REmotE DEsktop ConnECtion with RaspbERRy pi:
To access the Raspbian GUI from another computer, we need to configure it to work with a
remote desktop application.
This will allow us to access our Raspberry Pi desktop (or the command line) from anywhere in
the world as long as we have a computer with an internet connection.
To do this, we need to install XRDP Server on RaspberryPi, execute the below commands in terminal.
1. sudo apt-get remove xrdp vnc4server tightvncserver
2. sudo apt-get install tightvncserver
3. sudo apt-get install xrdp
1. Now, go to your Windows computer.
2. Click the “Start” button or Windows button, and type “Remote Desktop Connection” to search for the
Remote Desktop Application.
3. Open up the Remote Desktop Application, and enter your local IP address for your Raspberry Pi connected
over WiFi
4. Click connect, and you will be connected to the xrdp login screen for the Raspberry Pi
5. Enter your username and password here,(username= pi and password= raspberry).
6. Click “Ok” and you will be logged into the Raspbian GUI
Blinking LED using Python:
• Connect Anode(long leg) of LED to pin no:11 via 180 ohm resistor• Connect Cathode(short leg) of LED to Ground
Interfacing PIR Sensor with RaspberryPi:
s.no piR RaspbERRy pi
1 Vin pin 02
2 out pin 11
3 gRounD pin 06
s.no bmp180 RaspbERRy pi
1 Vin pin 01
2 gRounD pin 06
3 sDa pin 03
4 sCl pin 05
Connecting BMP180 to Raspberry Pi:
It is a digital pressure and temperature sensor.
It is using Piezo-electric technology.
The pressure range is 300-1000 hpa .
Operating Voltage Range: 1.8v to 3.6v
s.no Dht11 RaspbERRy pi
1 VCC pin 01
2 Data pin 07 (gpio 4)
3 nC ---
4 gnD pin 06
Connecting DHT11 to Raspberry Pi:
It can measure both Humidity and temperature .
It uses capacitive humidity sensor and thermistor to measure Humidity & Temperature.
Operating range : humidity 0-100%RH
temperature -40~80 Centigrade
Uploading Sensors Data to Thing Speak
Signup for thingspeak
Create a New Channel under my channels
Enter the name of Project and Field Names, then u will see Graphs on Private show.
Note down Write API Key to write the data to channel
Connect DHT11 and BMP 180 to Raspberry Pi
Execute the Program and check the graphs on Thing Speak.
Sending Basic Email using Python
Note: You have to allow “less secure apps” on your Gmail account
Sending SMS using Python
• Create Account in MSG91.com and get Authorization Key from it.
How to Launch Python Script on Startup
In order to run program when the Pi boots, you can add commands to the rc.local file.
This is especially useful if you want to be able to plug your Pi in to power headless, and have it run a
program without configuration or a manual start.
On your Pi, edit the file /etc/rc.local using the editor of your choice
Type the Following Command in Terminal
Add commands below the comment, but leave the line exit 0 at the end, then save the file and exit.
sudo nano /etc/rc.local
python /home/pi/myscript.py &
Q&A SESSION
THANK YOU !