Upload
tony-gerdjikov
View
81
Download
4
Embed Size (px)
Citation preview
WWW.FACTORY3D.BG
IOT AND RASPBERRY PI FOR DUMMIES
BY TONY GERDJIKOV
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.
WWW.FACTORY3D.BG
IOT COMMUNICATION PROTOCOLS
• Ipv6/4• Messaging via MQTT or ZeromQ• Rest• SOAP
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.
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
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.
RPI FAMILIY
RPI B
RPI 2 B+
PRI ZEROWWW.FACTORY3D.BG
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$
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.
WWW.FACTORY3D.BG
OPERATING SYSTEMS
• Raspberrian• Arch Linux• Android• Windows 10 IoT• Ubuntu and other Linux distros.
WWW.FACTORY3D.BG
PROGRAMMING LANGUAGES
• Python• JAVA• C# for Windows IoT Core
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.
WWW.FACTORY3D.BG
GPIO
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”
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
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
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
WWW.FACTORY3D.BG
HARDWARE HOWTO – T CLOBBER AND CAMERA
WWW.FACTORY3D.BG
GETTING TO KNOW THE STARTUP KITS- BREADBOARD
WWW.FACTORY3D.BG
GETTING TO KNOW THE STARTUP KITS- TOUCH SCREEN
WWW.FACTORY3D.BG
GETTING TO KNOW THE STARTUP KITS – DUPONT WIRES
WWW.FACTORY3D.BG
GETTING TO KNOW THE STARTUP KITS: RESISTORS
WWW.FACTORY3D.BG
GETTING TO KNOW THE STARTUP KITS: RESISTORS
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
WWW.FACTORY3D.BG
GETTING TO KNOW THE STARTUP KITS: RELAYS
WWW.FACTORY3D.BG
PUTTING ALL THINGS TOGETHER…
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
WWW.FACTORY3D.BG
CONNECTING A LEDimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.output(7,True)
WWW.FACTORY3D.BG
GPIO
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()
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.
WWW.FACTORY3D.BG
CONNECTING RELAY
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:
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)
WWW.FACTORY3D.BG
SERVO MOTOR
WWW.FACTORY3D.BG
SERVO MOTOR
WWW.FACTORY3D.BG
SERVO MOTOR
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)
WWW.FACTORY3D.BG
MANAGE A DC MOTOR )
WWW.FACTORY3D.BG
MANAGE A DC MOTOR
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
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
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()
WWW.FACTORY3D.BG
ANALOGS: ORANGE PI AND BANANA PI
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.
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.
WWW.FACTORY3D.BG
QUESTIONS ?
WWW.FACTORY3D.BG
USEFUL LINKS
• http://www.instructables.com/howto/raspberry+pi/ • https://www.adafruit.com/Raspberrypi • https://
learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/software • http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-the-ra
spberry-pi/ • www.rs-online.com• www.farnell.com
WWW.FACTORY3D.BG
USEFUL LINKS
• https://www.raspberrypi.org/magpi/issues/• http://playground.arduino.cc/Bulgarian/Kombinirane • https://pimylifeup.com/raspberry-pi-webcam-server/ • https://scanlibs.com/raspberry-pi-cookbook/ • https://pimylifeup.com/raspberry-pi-gpio/ • http://wiringpi.com/download-and-install/
WWW.FACTORY3D.BG
THANK YOU