50
IOT AND RASPBERRY PI FOR DUMMIES BY TONY GERDJIKOV WWW.FACTORY3D.BG

Raspbeery PI IoT

Embed Size (px)

Citation preview

Page 1: Raspbeery PI IoT

WWW.FACTORY3D.BG

IOT AND RASPBERRY PI FOR DUMMIES

BY TONY GERDJIKOV

Page 2: Raspbeery PI IoT

WWW.FACTORY3D.BG

WHAT IS IOT ?

• is the network of physical devices, vehicles, buildings and other items—embedded with electronics, software, sensors, actuators, and network connectivity that enable these objects to collect and exchange data.• The IoT allows objects to be sensed and controlled remotely across existing

network infrastructure• encompasses technologies such as smart grids, smart homes, intelligent

transportation and smart cities.• According to Gartner, Inc. (a technology research and advisory corporation),

there will be nearly 20.8 billion devices on the internet of things by 2020.

Page 3: Raspbeery PI IoT

WWW.FACTORY3D.BG

IOT COMMUNICATION PROTOCOLS

• Ipv6/4• Messaging via MQTT or ZeromQ• Rest• SOAP

Page 4: Raspbeery PI IoT

WWW.FACTORY3D.BG

ENABLING TECHNOLOGIES

• RFID and near-field communication – In the 2000s, RFID was the dominant technology. Later, NFC became dominant (NFC). NFC have become common in smartphones during the early 2010s, with uses such as reading NFC tags or for access to public transportation.

• Rapid developments in the Optical technologies like Li-Fi, Cisco's 40 Gbit/s bidirectional optical technology (BiDi[148]) may aid the development of IoT.

• Optical tags and quick response codes – This is used for low cost tagging. Phone cameras decode QR code using image-processing techniques. In reality QR advertisement campaigns gives less turnout as users need to have another application to read QR codes.

• Bluetooth low energy – This is one of the latest tech. All newly releasing smartphones have BLE hardware in them. Tags based on BLE can signal their presence at a power budget that enables them to operate for up to one year on a lithium coin cell battery. Bluetooth Beacons.

• Low energy wireless IP networks – embedded radio in system-on-a-chip designs, lower power WiFi, sub-GHz radio in an ISM band, often using a compressed version of IPv6 called 6LowPAN.

Page 5: Raspbeery PI IoT

WWW.FACTORY3D.BG

ENABLING TECHNOLOGIES• ZigBee – This communication technology is based on the IEEE 802.15.4 2.4 GHz-band radio protocol to implement physical and

MAC layer for low-rate wireless Private Area Networks.

• Z-Wave – is a communication protocol that is mostly used in smart home applications. It uses a radio protocol in the 900 MHz-band.

• Thread – Like ZigBee, this IoT communication technology relies on the IEEE 802.15.4 2.4 GHz-band radio protocol. IPv6-compatible.

• LTE-Advanced – LTE-A is a high-speed communication specification for mobile networks. Compared to its original LTE, LTE-A has been improved to have extended coverage, higher throughput and lower latency. One important application of this technology is Vehicle-to-Vehicle (V2V) communications.

• WiFi-Direct – It is essentially WiFi for peer-to-peer communication without needing to have an access point. This feature attracts IoT applications to be built on top of WiFi-Direct to get benefit from the speed of Wi Fi while they experience lower latency.

• HomePlug – IOT communication over a home or building's power lines

• MoCA – communication over CATV-type coaxial cable

• Ethernet – This general purpose networking standard can be used to enable IOT communication over twisted pair or fiber network links

Page 6: Raspbeery PI IoT

WWW.FACTORY3D.BG

RASPBERRY PI

• The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation• All models feature a Broadcom system on a chip (SoC), which includes

an ARM compatible central processing unit (CPU) and an on chip graphics processing unit (GPU, a VideoCore IV). CPU speed ranges from 700 MHz to 1.2 GHz for the Pi 3 • On board memory range from 256 MB to 1 GB RAM.• SD CARD Slot from 4 to 32 GB.

Page 7: Raspbeery PI IoT

RPI FAMILIY

RPI B

RPI 2 B+

PRI ZEROWWW.FACTORY3D.BG

Page 8: Raspbeery PI IoT

WWW.FACTORY3D.BG

HISTORY

• The first generation (Pi 1) was released in February 2012 in basic model A and a higher specification model B• Raspberry Pi 2(RPI2) model B+ was released in February 2015 35 US$• Raspberry Pi 3 (RPI3) model B in February 2016. 35 US$• A cut down "compute" model was released in April 2014, and a Pi

Zero with smaller size and limited input/output (I/O), general-purpose input/output (GPIO), abilities released in November 2015 for 5 US$

Page 9: Raspbeery PI IoT

WWW.FACTORY3D.BG

RPI SPECIFICATION

• Most boards have between one and four USB slots, • HDMI and composite video output, and a 3.5 mm phono jack

for audio• Lower level output is provided by a number of GPIO pins

which support common protocols like I²C. Some models have an 8P8C Ethernet port and • the RPi 3 has on board Wi-Fi 802.11n and Bluetooth.

Page 10: Raspbeery PI IoT

WWW.FACTORY3D.BG

OPERATING SYSTEMS

• Raspberrian• Arch Linux• Android• Windows 10 IoT• Ubuntu and other Linux distros.

Page 11: Raspbeery PI IoT

WWW.FACTORY3D.BG

PROGRAMMING LANGUAGES

• Python• JAVA• C# for Windows IoT Core

Page 12: Raspbeery PI IoT

WWW.FACTORY3D.BG

MAKE YOUR RASPBERRY USEFULL

• Media Center with RaspBMC• Home automation• WEB/ DB Server/ Network Shared server• WordPress• 2D Games and Games development e.g MineCraft.

Page 13: Raspbeery PI IoT

WWW.FACTORY3D.BG

GPIO

Page 14: Raspbeery PI IoT

WWW.FACTORY3D.BG

INSTALLING RASPBERRIAN OS FROM WINDOWS

https://www.raspberrypi.org/documentation/installation/installing-images

Windows:• Insert SD Card in your reader• Download the Win32DiskImager utility• Extract downloaded OS image• Open image file with Wind32DiskImager• Select image file and SD card Drive• Click “Write”

Page 15: Raspbeery PI IoT

WWW.FACTORY3D.BG

INSTALLING RASPBERRIAN OS FROM LINUX

https://www.raspberrypi.org/documentation/installation/installing-images

Linux:1. Run df -h to see what devices are currently

mounted.2. Insert your SD card and run df -h again to

identify your card. e.g /dev/mmcblk0 or /dev/sdd3. Unmount card with: umount /dev/sdd14. Sudo dd bs=4M if=2016-09-23-raspbian-jessie.img

of=/dev/sdd1 5. Make sure the device name is the name of the whole

SD card as described above, not just a partition of it; for example, sdd, not sdds1

6. Check progress in new terminal with sudo pkill -USR1 -n -x dd

Page 16: Raspbeery PI IoT

WWW.FACTORY3D.BG

INSTALLING WINDOWS 10 – IOT

1. Select your raspberry type PRI2 or RPI3 and download image.

2. Download and start the Windows 10 IoT Core Dashboard

3. Select your device, type, Wi Fi Settings and SD Card.

4. Boot the RPI from the Card.5. Download and Install Visual Studio 2015 on your PC6. Download and Install C# samples.

https://developer.microsoft.com/en-us/windows/iot/getstarted

Page 17: Raspbeery PI IoT

WWW.FACTORY3D.BG

FIRST USEFULL LINUX COMMANDSsudo apt-get updatesudo apt-get upgrade 

 sudo raspi-config

sudo apt-get install pip

sudo apt-get install python-dev python-rpi.gpio 

Page 18: Raspbeery PI IoT

WWW.FACTORY3D.BG

HARDWARE HOWTO – T CLOBBER AND CAMERA

Page 19: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS- BREADBOARD

Page 20: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS- TOUCH SCREEN

Page 21: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS – DUPONT WIRES

Page 22: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS: RESISTORS

Page 23: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS: RESISTORS

Page 24: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS: DC MOTORS, SERVO MOTORS, STEPPER MOTORS

DC Motor2 wires

Stepper Motor 4 wires

Servo Motor3 wires

Page 25: Raspbeery PI IoT

WWW.FACTORY3D.BG

GETTING TO KNOW THE STARTUP KITS: RELAYS

Page 26: Raspbeery PI IoT

WWW.FACTORY3D.BG

PUTTING ALL THINGS TOGETHER…

Page 27: Raspbeery PI IoT

WWW.FACTORY3D.BG

“HELLO WORD” PROGRAM ON PYTHON1.  Create a simple text file named

“myPython.py”2. Enter the following text:

#!/usr/bin/env python print “Hello Word from Python”

3. Save the file4.Open terminal windows and execute command: sudo chmod +X myPython.py5.Run your python application with: sudo python myPython.py

Page 28: Raspbeery PI IoT

WWW.FACTORY3D.BG

CONNECTING A LEDimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.output(7,True) 

Page 29: Raspbeery PI IoT

WWW.FACTORY3D.BG

GPIO

Page 30: Raspbeery PI IoT

WWW.FACTORY3D.BG

MAKING A BLINKING A LED#import the GPIO and time package import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT)

# loop through 50 times, on/off for 1 second for i in range(50):      GPIO.output(7,True)      time.sleep(1)      GPIO.output(7,False)      time.sleep(1)

GPIO.cleanup()

Page 31: Raspbeery PI IoT

WWW.FACTORY3D.BG

CONNECTING BUTTON

import RPi.GPIO as GPIO   import time   # to use Raspberry Pi board pin numbers   GPIO.setmode(GPIO.BOARD)   # set up GPIO input channel   GPIO.setup(7, GPIO.IN)     while True: inputValue = GPIO.input(7) if input_value == False: print ‘The button was pressed‘ #todo make led on. else: #todo meke led off.

Page 32: Raspbeery PI IoT

WWW.FACTORY3D.BG

CONNECTING RELAY

Page 33: Raspbeery PI IoT

WWW.FACTORY3D.BG

CONNECTING TEMPERATURE SENSOR

sudo apt-get install git-coregit clone https://github.com/adafruit/Adafruit_Python_DHT.gitcd Adafruit_Python_DHTsudo apt-get install build-essential python-devsudo python setup.py install

Getting the libraries:

Page 34: Raspbeery PI IoT

WWW.FACTORY3D.BG

CONNECTING TEMPERATURE#!/usr/bin/pythonimport sysimport Adafruit_DHT

while True:

humidity, temperature = Adafruit_DHT.read_retry(11, 4)

print 'Temp: {0:0.1f} C Humidity: {1:0.1f}%'.format(temperature, humidity)

Page 35: Raspbeery PI IoT

WWW.FACTORY3D.BG

SERVO MOTOR

Page 36: Raspbeery PI IoT

WWW.FACTORY3D.BG

SERVO MOTOR

Page 37: Raspbeery PI IoT

WWW.FACTORY3D.BG

SERVO MOTOR

Page 38: Raspbeery PI IoT

WWW.FACTORY3D.BG

SERVO MOTORimport timedef set(property, value): try: f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w') f.write(value) f.close() except: print("Error writing to: " + property + " value: " + value)  def setServo(angle): set("servo", str(angle))

set("delayed", "0")set("mode", "servo")set("servo_max", "180")set("active", "1")delay_period = 0.01 while True: for angle in range(0, 180): setServo(angle) time.sleep(delay_period) for angle in range(0, 180): setServo(180 - angle) time.sleep(delay_period)

Page 39: Raspbeery PI IoT

WWW.FACTORY3D.BG

MANAGE A DC MOTOR )

Page 40: Raspbeery PI IoT

WWW.FACTORY3D.BG

MANAGE A DC MOTOR

Page 41: Raspbeery PI IoT

WWW.FACTORY3D.BG

• RPI • RPI

DISTRIBUTED ARCHITECTURE

Rest Server MQT

Tserve

r

UPNPclient

• RPI 1MQT

Tclient

• RPI (N)

MQTT

client

• Arduino Device

MQTT

client

• Android Device

• Web Browser

• Wi FI route

r WEBServer

Page 42: Raspbeery PI IoT

WWW.FACTORY3D.BG

RASPBERRY PI AND ARDUINOhttp://raspberrypi-aa.github.io/session3/firmata.htmlsudo apt-get install python-pip python-serial sudo pip install pyfirmata1.Open Arduiono IDE:2.Click File->Examples->Firmata->StandardFirmata 3.From the Tools->Board menu, select the type of 4.Arduino you are using. From the Tools->Serial Port menu, choose the USB port to which your Arduino is connected. 4.Click the upload button (it looks like a right arrow, just next to the checkmark) and wait for image to load

Page 43: Raspbeery PI IoT

WWW.FACTORY3D.BG

RASPBERRY PI AND ARDUINO – READ DIGITAL AND ANALOG INPUTS.

ANALOG:>>> it = util.Iterator(board) >>> it.start() >>> board.analog[0].enable_reporting() >>> board.analog[0].read() >>> it.start()

DIGITAL:>>> from pyfirmata import Arduino, util >>> board = Arduino('/dev/ttyUSB0')>>> board.digital[2].write(1) >>> print board.digital[2].read()

Page 44: Raspbeery PI IoT

WWW.FACTORY3D.BG

ANALOGS: ORANGE PI AND BANANA PI

Page 45: Raspbeery PI IoT

WWW.FACTORY3D.BG

USINNG CAYENE MY DEVICES

• IoT cloud for Raspberry Pi and Arduino• Installs Agent and discovers devices• Zero code configuration• Support various known actuators, sensors and shields.• Manage everything from your phone with cool widgets and

gauges.

Page 46: Raspbeery PI IoT

WWW.FACTORY3D.BG

CAYENE INSTALLATION STEPS

• Goto https://cayenne.mydevices.com and register• Download Android or IOS application for your phone• Download Raspberry PI agent • Discover your Raspberry PI• Create a new project and start adding sensors / elements.

Page 47: Raspbeery PI IoT

WWW.FACTORY3D.BG

QUESTIONS ?

Page 50: Raspbeery PI IoT

WWW.FACTORY3D.BG

THANK YOU