0% found this document useful (0 votes)
81 views32 pages

Prof Sachin Gajjar Maker Community Boards For Iot

This document discusses the opportunities and challenges of implementing an Internet of Things (IoT) network for a smart city project in India. It proposes using sensors, microcontrollers, and other low-cost, low-power devices to create an intelligent network of nodes that can provide unified access to public services. Some of the challenges mentioned are developing low-energy hardware and software, connecting nodes to the cloud, designing algorithms for decision making and data analysis, and ensuring security and privacy. Preliminary investigation of existing smart city projects is also recommended.

Uploaded by

Karan Mistry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views32 pages

Prof Sachin Gajjar Maker Community Boards For Iot

This document discusses the opportunities and challenges of implementing an Internet of Things (IoT) network for a smart city project in India. It proposes using sensors, microcontrollers, and other low-cost, low-power devices to create an intelligent network of nodes that can provide unified access to public services. Some of the challenges mentioned are developing low-energy hardware and software, connecting nodes to the cloud, designing algorithms for decision making and data analysis, and ensuring security and privacy. Preliminary investigation of existing smart city projects is also recommended.

Uploaded by

Karan Mistry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

3/14/2017

Company
Internet Evolution Internet Evolution
LOGO

Maker Boards for IoT


1ST
Sachin Gajjar Wave
(Vivek, Anunyay, Mehul, Vandana)
(Prerak, Tridash, Rushi, Sagar, Ankit, Anik) Evolution
sachin.gajjar@nirmauni.ac.in Of Internet
Connecting Computer (1990Era)
Internet Of Internet Of Internet Of Internet Of Internet Of
Documents Commerce Applications People Things

Electronics and Communication Engineering


Institute of Technology, Nirma University

Internet Evolution Internet Evolution Internet of Things (IoT)


q Objects that surround us becoming part of the Internet
q The network of physical “things”
2nd 3rd
Wave Wave q Through embedded sensors, actuators, or any devices that
collects and transmits data
q Data is used for optimizing and measuring products,
Evolution Internet providing services, trigger actuation based on the data
Of
Of Mobile phone Every Thing
Connecting People (2000 Era)

1
3/14/2017

Making S-E-N-S-E of IoT Internet of Things explained Why now? Enablers of the IoT

Opportunities are Everywhere


Project Ideas
GOI’s Smart City Mission

q Intelligent network to make better use of public resources, increase quality


of services for citizens, reduce operational costs of public administrations
(Source: Ministry of Urban Development, Government of India’s Smart City Mission Transformation, Mission
Statement and Guidelines, June 2015)

q How – by deployment of an intelligent network of nodes that provides


unified, simple, and economical access to a plethora of public services

2
3/14/2017

Challenges and Constraints Preliminary Investigation


Societal Impact (Project Ideas) (Existing Projects)
q Identifying low cost, low power, robust: sensors, microcontrollers, trans receiver, q Survey of existing smart city network projects/proposals
qWill bring together technology, cloud service, smart boards suitable for Indian environment
q Butler Project (European Union FP7 project)
q Low energy hardware and software protocol stack design for intelligent nodes and
government, society to offer: sink
q Outsmart Project (European Commission’s Information Society and Media
Directorate General )
q Connect the sink to the cloud
qsmart people – increased quality of life q Design of algorithms for decision making and information exchange for different
q Smart Cities at the Forefront of the Future Internet (Generic implementations
of ITU-T’s Ubiquitous Sensor Network (USN) model)
qsmart mobility – save fuel services
q Maintenance techniques of such installations, including energy scavenging
q CitySense (Architecture and Prototype for Cambridge City)
q Butler Project, http://www.iot-butler.eu.
qsmart, superior, sustainable life style q Ensuring reliable readings from a plethora of intelligent nodes and efficient
calibration of a large number of nodes deployed everywhere from lamp-posts to
q Outsmart Project, http://envirofi.nilu.no/AbouttheProject.aspx.
q
qsmart environment – save energy waste bins José M. Hernández-Muñoz, Jesús Bernat Vercher, Luis Muñoz, José A. Galache,
Mirko Presser, Luis A. Hernández Gómez, Jan Pettersson, “Smart cities at the
q Algorithms for analysis and processing of data acquired in the city and making
forefront of the future internet”, The future internet, Springer-Verlag, Berlin,
qsmart governance – save/share resources “sense” out of it on the cloud (noise map, smart phone detection)
Heidelberg, pp. 447-462, 2011.
q Security and privacy of data
q
qsmart economy q Overcoming challenges of wireless as transmission medium like signal
Rohan Narayana Murty , Geoffrey Mainland, Ian Rose , Atanu Roy Chowdhury,
Abhimanyu Gosain, Josh Bers , Matt Welsh, “CitySense: An Urban-Scale Wireless
attenuation with increase in distance, fading, hidden expose terminal problems etc Sensor Network and Testbed”, IEEE Conference on Technologies for Homeland
Security, 2008, 1-6 DOI: 10.1109/THS.2008.4534518.

Why Shoud I Care? Why Shoud I Care? Most Influential Internet Of Things Companies

q McKinsey research estimates that IoT market will be $4 trillion


to $11 trillion by 2025
q 40 percent of value could be generated in developing economies
q Cisco forecasts that there could be 50 billion connected
devices by 2020
q Gartner projects $300 billion in revenues, just for hardware
suppliers

Intel
M.C 115.41 B

3
3/14/2017

Most Influential Internet Of Things Companies Most Influential Internet Of Things Companies Most Influential Internet Of Things Companies

IBM
M.C 203.48 B Microsoft
Cisco
M.C 373 B
M.C 125.0B

Most Influential Internet Of Things Companies Forecasted Growth of IoT per Industries in 2025 Drivers of Smart Systems and IoT

Google
M.C 397B

4
3/14/2017

Maker boards Arduino developer team Open source Hardware


qBoards having most of the hardware to
create toys, tools, technology, dreams
qhttp://makezine.com/comparison/boards/ho
w-we-test/shootout/ Shields

qArduino
qRaspberry Pi
qBeaglebone
qGalileo
qXBEE transceiver module David Cuartielles, Gianluca Martino, Tom Igoe, David Mellis, and Massimo Banzi
Arduino board was born in the classrooms
of the Interactive Design Institute in Ivrea, Italy

Arduino ARDUINO UNO

5
3/14/2017

INSTALLING THE Arduino IDE ARDUINO IDE

int ledPin = 13

6
3/14/2017

Toolbar:

Verify, Upload,
New, Open, Save

ARDUINO PROGRAMMING ARDUINO PROGRAMMING ARDUINO PROGRAMMING

q Arduino is programmed in the C, C++


q http://www.arduino.cc/

Why?

7
3/14/2017

ARDUINO PROGRAMMING ARDUINO PROGRAMMING ARDUINO PROGRAMMING

Working with Arduino Working with Arduino Working with Arduino

1. Download and install the Arduino IDE 2. Select the Microcontroller in the IDE

Find COM port on which the


board is connected to

8
3/14/2017

Working with Arduino Working with Arduino Blinky Code

3. Select the Serial Port

Input

4. Open Blink Sketch Status Bar


Program
Notification
Area

Working with Arduino Working with Arduino Connecting to Internet- IoT


Temboo way
5. Verify/Compile 7. Upload it

6. Once it compiles, you must see the following messages in


the Status bar and the Program notification Area 8. Once it uploaded, you must see the following messages in the
Status bar and the Program notification Area

9
3/14/2017

Temboo What we want to do? Using Temboo

qHas software stack that provides pre built processes qSend an SMS as soon an input is given to A0
that handle common aspects of IoT applications – pin of Arduino Uno
monitoring, data logging & plotting, notifications qYou'll need a Temboo account and a Twilio
(e-mail, SMS) , actuation account
qM2M-2-Cloud with support for messaging protocols qYou’ll need the latest version of Temboo's
MQTT, CoAP, HTTP Arduino library installed
qGenerate Your Sketch

q Log in to Temboo, go to Twilio > SMSMessages > SendSMS


Choreo in Temboo Library

Using Temboo Using Temboo Using Temboo

q Log in to Temboo and go to the Twilio > SMSMessages > q Find your Twilio Account SID and Auth Token
SendSMS Choreo in the Temboo Library q Add details about Arduino shield to connect to the Internet

10
3/14/2017

Using Temboo Using Temboo Using Temboo

q When Choreo is run, Temboo


automatically generates code to
make API call from Arduino
code
q Copy the code, and paste it into
a new sketch in the Arduino IDE
as TembooAccount.h

When one logs in temboo account, this information is automatically populated in the sketch
q Fill your Twilio Account SID, Auth Token, other details….

Using Temboo Temboo Demo Connecting to Internet- IoT Xively way

qSend the SMS by running the choreo in your


code as and when required
qint inputPin = A0;
qint sensorValue = digitalRead(inputPin);
qif (sensorValue == HIGH)
q{
q // Run the Choreo
q unsigned int returnCode = SendSMSChoreo.run();
q}

11
3/14/2017

Connecting to Internet- IoT ThingSpeak way ZigBee Standard ZigBee and Other Wireless Technologies

qLow-data rate (upto 250 kBps)


qLow power consumption, devices turned off most of
the time (<1% duty cycle)
qLow cost (Rs. 1700 xbee + Rs. 600 shield)
qLow offered message throughput
qLow to no QoS guarantees
qLess Complex. 32kB protocol stack vs 250kB for
Bluetooth

XBee Xbee - a serial line replacement XBee Pins

q One way to transmit data wirelessly is through XBees qXBee – TX transmits data received through serial
q XBee is based on Zigbee standard input over the air
q XBee works at 3.3 volts, is a transceiver qXBee – RX receives data from air, sents through
q From ‘Digi International’ a family of radio modules serial interface
q ISM band of 2.4GHz
q P2P & Star topology
q Built in ADC for direct sensor interfacing
q Sleep mode (<10uA) – battery life up to few years
q Compact in size

12
3/14/2017

Configuring XBee
XBee Pin Description
Using XBee
q To connect XBee to Arduino/Computer XBee Shield/XBee Explorer
is used
q Explorer board has a USB-to-Serial converter Platforms to Configure Xbee

Xbee Shield
Xbee Explorer

XCTU Coolterm
(No coding required) (Coding required)
q When using Arduino with shield is used Arduino should have blank
code (basic template dumped in)

Benefits of using X-CTU Using XCTU Software Using XCTU Software


2. Select port on which XB explorer/Arduino+XB shield is connected from the
qAutomatically detects module type 1. Connect XBee to USB port. Lauch X-CTU. Click discover device.
list of ports.
qDisplays data in terminal window (The port can also be found from Mycomputerà manage à device manager)

qCan upgrade RF module firmware online


qDisplay of Receive Signal Strength Indictator (RSSI)
qSave and retrieve commonly used module
configurations (profiles)
qAllows to test radio modems in actual environment
with a computer

13
3/14/2017

Using XCTU Software Using XCTU Software


3. Select baud rate, parity options, data bit, flow control, stop bit . Click finish. 4. X-CTU will look for devices attached on serial port (USB) and lsit the available
Using XCTU Software
The serial port (USB) of PC is configured to look for attached Xbee devices. devices. Select device you want, click the “Add selected device” icon.

5. Click on the module that appeared at left. X-CTU reads the configuration settings of
XBee.
6. To test another Xbee on the same computer and connect them wirelessly
Using XCTU Software
Settings

• Connect second Xbee repeat the same procedure


• A second entry will be added to the “Radio Modules” list.
7. In order to allow communication between
• Select the device to display its configuration settings. two zigbee modules ,
§ Keep the PAN ID same for both the modules
§ Exchange DH and DL address of Coordinator
Zigbee Module with SH and SL of Router/End
Set the PAN ID,
should be same
Device Zigbee Module
for all the devices • http://tutorial.cytron.com.my/2012/03/08/xbee-series-2-point-to-point-
you wish to communication/
connect

14
3/14/2017

PAN ID and address settings PAN ID and address settings PAN ID and address settings

Using XCTU Software Using XCTU Software Using XCTU Software

8. Click “Switch to Consoles” to launch the serial window 9. Start a serial connection of each device by clicking the 10. Now type in console (RED) and notice it transmitted in
connect icon it will turn the console’s border to green. another console (BLUE)
11. Xbee Demo

15
3/14/2017

Raspberry Pi Raspberry Pi Models Raspberry Pi Zero

q Tiny fanless computer, size of a credit – card q Price $5


q Made by “The Raspberry Pi Foundation”, a UK charity q A full-fledged member of the family, featuring:
q A Broadcom BCM2835 application processor
q Plugs into a TV/monitor
q 1GHz ARM11 core (40% faster than Raspberry Pi 1)
q Very cheap (about $5 (Raspberry Pi Zero) - $35 , depending q 512MB of LPDDR2 SDRAM
on the model)
q A micro-SD card slot
q Consists of pre-installed Python IDE, Office, Java IDE … q A mini-HDMI socket for 1080p60 video output
q Micro-USB sockets for data and power
q An unpopulated 40-pin GPIO header
q Identical pinout to Model A+/B+/2B
q An unpopulated composite video header
q Smallest ever form factor, at 65mm x 30mm x 5mm
q Runs Raspbian and all applications, including Scratch,
Minecraft and Sonic Pi

Raspberry Pi Zero

Raspberry Pi Zero Mini-HDMI Micro-USB adapter

16
3/14/2017

How to make it work? How to make it work? Popular OS support

q To get it up and running –

q Power Supply
q HDMI cable *
q USB mouse and keyboard * OS Available
q SD memory card (min. 4 GB)
q SD memory card reader
q LAN cable **

* - Required while using in Head mode


** - Required while using in Headless mode

• NOOBS (New Out of Box Software) or Raspbian OS

OS Installation Downloading OS SD Card


q Download the file “RASPBIAN Jessie Operating.zip” and unzip the image file
q Download ISO file from RPi official web site q Insert SD card into SD card reader
q http://downloads.raspberrypi.org/raspbian_latest
q Download Disk Imager Raspbian Installation Step 1 q Insert it in SD card slot of PC or use SD adaptor with USB port
q Burn iso onto SD card q Format the SD card

17
3/14/2017

Downloading Disk Manager Burning the OS image Working with RPi in headless mode

q http://sourceforge.net/projects/win32diskimager/files/latest/do q Extract the zip file and run Win32DiskImager utility


wnload q Right-click on the file, and select Run as administrator qHaving only RPi board and no Monitor,
q Browse the image file keyboard, mouse, HDMI cable
q Click write and wait for the write to be done qRequirements
q Exit the imager and eject the SD card qSD card with Raspbian OS
qComputer with Windows 7, XP, Vista OS
qRPi and Windows computer connected
on same local network (through router)
qIP scanner installed in PC

Knowing the IP address of RPi The IP Scanner Options for connecting RPi

q First we need to know the IP address of the RPi qMobaXterm


q Use IP scanner utility like Angry IP scanner
q It lists all devices in the network (IP, name, port)
qPutty
q Find the IP address which pings as Raspberry Pi qVNC server
q Found the IP address of the Raspberry pi
qXming server

18
3/14/2017

MobaXterm MobaXterm MobaXterm

q Download MobaXterm personal/home edition q Extract MobaXterm_Personal_6.0.exe file q In session settings, choose session type
http://mobaxterm.mobatek.net/download-home-edition.html q Select SSH
q Launch MobaXterm
q SSH Secure Shell/Secure Socket Shell is UNIX based command interface
q In MobaXterm, click Sessions -> New session for securely getting access to remote computer

MobaXterm MobaXterm MobaXterm

q Select the LXDE desktop q In the login prompt enter RPi’s username/password
q Enter RPi IP address in remote host
q Default user is pi , and password is raspberry

19
3/14/2017

MobaXterm Putty VnC Server

q RPi desktop on PC q Can also use Putty (prompt) to connect RPi to PC q Can also use VnC Server (screen) to connect Rpi to PC

Working with RPi in head mode Working with RPi in head mode Pre-installed programs in RPi

q There is RPi board, Monitor, keyboard, mouse, HDMI cable q BlueJ, an IDE for Java
q PLUGGING IN YOUR RASPBERRY PI q Free, simple to use,
q Slot in SD card into the SD card slot of RPi q Smaller and simpler interface than professional environments
like netbeans or eclipse
q Plug in USB keyboard and mouse in USB slots of RPi
q Geany, an IDE for almost any language
q Turn on monitor/TV, and select the HDMI input q C, Java, PHP, HTML, Python, Perl and Pascal
q Connect HDMI cable from RPi to monitor/TV q Greenfoot, IDE for Java
q To connect RPi to Internet, plug in an Ethernet cable into q A full IDE which includes project management, syntax
Ethernet port highlighting, and other tools common to most IDEs
q Finally, plug in the micro USB power supply to boot RPi q Publish your work both on and offline
q Mathematica, serious math on an RPi
q For technical
q With Mathematica Online, it is on cloud through any web
browser, and natively on all modern desktop systems

20
3/14/2017

Pre-installed programs in RPi Pre-installed programs in RPi Raspberry Pi GPIO

q Node-RED - Wiring for the IoT q Scratch qGeneral Purpose Input/Output


q A free, open source “tool for wiring together hardware devices, q To create animations, games, etc.
APIs and online services”
qIt allows peripherals and expansion boards to
q For event-driven programming with multiple active objects called
q Developed by IBM Emerging Technologies sprites access CPU by exposing the inputs and outputs.
q Also runs on every major operating system q Sprites can be drawn, as vector or bitmap graphics, from scratch qC language library included to read and write to the
q Python, IDLE (Integrated DeveLopment Environment or in it’s editor
q Or can be imported from external sources, including webcams
GPIO interface
Integrated Development and Learning Environment)
q An IDE for Python q Wolfram Language qWorks with other languages
q Is cross-platform, Multi-window text editor with syntax q Programming language of Mathematica and of the Wolfram qC#, Java, Perl, Python, Ruby, Shell, Scratch
highlighting, smart indent, debugger, call stack visibility Programming Cloud
q Emphasizes symbolic computation, functional programming, qExamples on this page
q Sonic Pi
q A free, open source, live coding music synthesizer
rule-based programming qhttp://elinux.org/RPi_Low-level_peripherals
q Includes built-in functions for generating and running Turing
machines, creating graphics and audio, analyzing 3D models, qhttp://www.raspberrypi.org/archives/1471
matrix manipulations, and solving differential equations

LED Blinking in RPi Python IDE Blinky Code in python

q Learn Basics of GPIO connection import RPi.GPIO as GPIO #Infinite loop


import time while True:
q Learn basics of GPIO programming GPIO.output(LED1, True) #Turn ON the LED
q Blink LED GPIO.setmode(GPIO.BCM) time.sleep(0.5) #0.5 secs delay
GPIO.setwarnings(False) GPIO.output(LED2, True)
q Use Python scripting time.sleep(0.5)
LED1=21 GPIO.output(LED3, True)
LED2=20 time.sleep(0.5)
LED3=16 GPIO.output(LED4, True)
LED4=12 time.sleep(0.5)
GPIO.output(LED4, False)
#Set pins in output mode time.sleep(0.5)
GPIO.setup(LED1, GPIO.OUT) GPIO.output(LED3, False)
GPIO.setup(LED2, GPIO.OUT) time.sleep(0.5)
GPIO.setup(LED3, GPIO.OUT) GPIO.output(LED2, False)
GPIO.setup(LED4, GPIO.OUT) time.sleep(0.5)
GPIO.output(LED1, False)
time.sleep(0.5)

21
3/14/2017

Ubidots Ubidots Ubidots

q A codeless Internet of Things (IoT) platform that lets you store,


analyze, and visualize sensor data in real time
q Ubidots was created to help you scale and prototype your own IoT
initiatives moving from DIY projects to business solutions.

Ubidots Ubidots Ubidots

22
3/14/2017

Ubidots Ubidots Ubidots

Smart Water Management Smart Water Management Smart Water Management

Dashboard
For manual control of
inlet
For monitoring usage
Inlet control ON/OFF control based of water
on water in the tank Notification of
Water level through
SMS, e-mail, live on Circuit
dashboar
Diagram
Track of
Water
usage

23
3/14/2017

Individual Dashboard: Web based Individual Dashboard: Mobile Smart Mirror


On website using URL

q Detect presence of individual with


help of Ultrasonic sensor
Water level indicator, Water usage indication q Identify the individual
q Display his identity
Inlet valve ON/OFF control (LED indicator, Button for input)
q Look for his google calendar
q Display Events he is involved in,
Weekly, Monthly, Yearly usage details Birthdays, To do lists etc.
q Hardware: Raspberry Pi, Ultrasonic
Sensor, Display Screen.

Real time data in graphical form after


every 2 msec Using I

FARMNET: Agriculture Support System using


Smart Water Management Sensor and Actuator Network FARMNET

Web Server (Flask)

Nitrogen, Phosphorus, Potasium -> Fertigation

24
3/14/2017

FARMNET
GSM

Sensor 1
Sensor 2
Node Data Base
Server
1 Station
Actuation Control
Sensor n

|
|

- - - - - - - - - -Crop
- - -Crop - - - - - - - - - Drip Irrigation- - - -Crop
- - - - - - - - - - - - -Crop
--
|
| | Actuation
| Actuation | Data Control
|
| Control |
| |
Data
Crop
| Sensor 1
Sensor 1 |
Sensor 2
Sensor 2 |
Node | -- ---- Node 3
2 |
|
Sensor n
Crop
| Sensor n

GSM Shield

25
3/14/2017

GSM Shield FARMNET Sense HAT

vgujcost-farmnet.mp4 q Add-on board for RPi


q HAT is Hardware Attached on-Top
q Contains suite of sensors for RPi to sense the world

Sensors Sense HAT Sense HAT


q Gyroscope
q To determine orientation object (for detecting which way up the board is) q Can measure how fast is Pi travelling (i.e. measure your
q Angular rate sensor: +/-245/500/2000 deg per sec speed), how hot is it? how humid is it? (air humidity), which
q Accelerometer direction is RPi facing?
q To determine Linear acceleration of object (for detecting movement)
q +/-2/4/8/16 gravitational force q LED Matrix to display data from sensors
q Magnetometer
q To determine orientation of object w.r.t earth’s magnetic field (for detecting
q Play games like Tetris, Pong, Snake with joystick
magnetic fields) q Interact with programs with joystick
q Magnetic Sensor: +/- 4/8/12/16 gauss
q Barometer (260 – 1260 hecto Pascal absolute range (accuracy depends on the q Writing programs for Sense HAT requires a Python library
temperature and pressure, +/- 0.1 hPa under normal conditions)
q Temperature sensor (Temperature accurate to +/- 2 degC in the 0-65 degC
range)
q Relative Humidity sensor (accurate to +/- 4.5% in the 20-80%rH range,
accurate to +/- 0.5 degC in 15-40 degC range)
q 8x8 LED matrix display
q Small 5 button joystick

26
3/14/2017

For projects and other information Sense HAT Installation Sense HAT Software Overview

q http://astro-pi.org/
q https://www.hackster.io/raspberry-pi/products/sense-hat
q https://www.raspberrypi.org/learning/astro-pi-
guide/emulation.md
q http://pythonhosted.org/sense-hat/ Install the Sense HAT software by opening a Terminal window and
entering the following commands (while connected to the Internet):
q https://github.com/RPi-Distro/python-sense-
hat/blob/master/examples/README.md
q http://pythonhosted.org/sense-hat/api/
q https://trinket.io/
q https://www.raspberrypi.org/learning/getting-started-with-the-
sense hat/worksheet/
q https://sense-emu.readthedocs.io/en/v1.0/index.html#
q http://pythonhosted.org/sense-hat/

RTIMULib RTIMULib Sense-Hat Emulator

qSense HAT emulator mirrors official Sense HAT API


qImport library at top of code
qfrom sense_emu import SenseHat
qto change code to run on actual HAT change line to
qfrom sense_hat import SenseHat

27
3/14/2017

Sense-Hat Emulator Sense-Hat Emulator Sense-Hat Emulator

q To run the scripts under the emulator


q Start the emulator application, then the scripts
q Several example scripts are available at
q File ‣Open example menu within the emulator.
q Selecting an example from this menu will open it in Python’s
IDLE environment
q Run the code from the Python’s IDLE

Running Sense-Hat code online Hello World example Sense-Hat code

q The code can be run at https://trinket.io/sense-hat also q from sense_hat import SenseHat
q sense = SenseHat() //calling constructor
q sense.show_message("Hello world!")
q //object.function call

28
3/14/2017

Sense-Hat APIs Sense-Hat APIs Sense-Hat APIs

Sense-Hat APIs Sense-Hat APIs Sense-Hat APIs

29
3/14/2017

Sense-Hat APIs Sense-Hat APIs Sense-Hat APIs

Sense-Hat code sample codes Reading Temperature on Sense-Hat Sense-Hat Code on Emulator

q Reading Temperature On Sense-Hat


q Code:
q Reading Humidity On Sense-Hat
q from sense_emu import SenseHat
q Getting Started with Joystick
q sense = SenseHat()
q Using 8*8 Led (Display Rainbow)
q red = (255, 0, 0)
q blue = (0, 0, 255)
q while True:
q temp = sense.temp
q pixels = [red if i < temp else blue for i in range(64)]
q sense.set_pixels(pixels)

30
3/14/2017

Reading Humidity on Sense-Hat Sense-Hat Code on Emulator Getting Started with Joystick

q Code: Code: if event.action in ('pressed', 'held'):


#!/usr/bin/python3 x = clamp(x + {
q from sense_emu import SenseHat from sense_emu import SenseHat 'left': -1,
x=y=4 'right': 1,
q sense = SenseHat() hat = SenseHat() }.get(event.direction, 0))
q green = (0, 255, 0) def update_screen(): y = clamp(y + {
hat.clear() 'up': -1,
q white = (255, 255, 255) hat.set_pixel(x, y, 255, 255, 255) 'down': 1,
q while True: def clamp(value, min_value=0, }.get(event.direction, 0))
max_value=7): update_screen()
q humidity = sense.humidity return min(max_value, max(min_value, while True:
value)) for event in hat.stick.get_events():
q humidity_value = 64 * humidity / 100 def move_dot(event): move_dot(event)
q pixels = [green if i < humidity_value else white for i in global x, y update_screen()
range(64)]
q sense.set_pixels(pixels)

Sense-Hat Code on Emulator Using 8*8 Led (Display Rainbow) Sense-Hat Code on Emulator
from colorsys import hsv_to_rgb
from time import sleep
from sense_emu import SenseHat
# Hues represent the spectrum of colors as values hat = SenseHat()
between 0 and 1. The range def scale(v):
# is circular so 0 represents red, ~0.2 is yellow, ~0.33 return int(v * 255)
is green, 0.5 is cyan, while True:
# ~0.66 is blue, ~0.84 is purple, and 1.0 is back to # Rotate the hues
red. These are the initial hues = [(h + 0.01) % 1.0 for h in hues]
# hues for each pixel in the display. # Convert the hues to RGB values
hues = [ pixels = [hsv_to_rgb(h, 1.0, 1.0) for h in hues]
0.00, 0.00, 0.06, 0.13, 0.20, 0.27, 0.34, 0.41, # hsv_to_rgb returns 0..1 floats; convert to ints in the
0.00, 0.06, 0.13, 0.21, 0.28, 0.35, 0.42, 0.49, range 0..255
0.07, 0.14, 0.21, 0.28, 0.35, 0.42, 0.50, 0.57, pixels = [(scale(r), scale(g), scale(b)) for r, g, b in
0.15, 0.22, 0.29, 0.36, 0.43, 0.50, 0.57, 0.64, pixels]
0.22, 0.29, 0.36, 0.44, 0.51, 0.58, 0.65, 0.72, # Update the display
0.30, 0.37, 0.44, 0.51, 0.58, 0.66, 0.73, 0.80, hat.set_pixels(pixels)
0.38, 0.45, 0.52, 0.59, 0.66, 0.73, 0.80, 0.87, sleep(0.04)
0.45, 0.52, 0.60, 0.67, 0.74, 0.81, 0.88, 0.95,
]

31
3/14/2017

Future Technology with QNX Useful Links Useful Links

q http://en.wikipedia.org/wiki/Raspberry_Pi q http://www.adafruit.com/products/859
q http://elinux.org/Rpi_Datasheet_201_Raspberry_Pi_Computer q http://elinux.org/RPi_VerifiedPeripherals
q http://elinux.org/RPi_Hardware q http://elinux.org/Rpi_Low-level_peripherals
q http://elinux.org/R-Pi_Hub q http://www.raspberrypi.org/downloads
q http://www.element14.com/community/docs/DOC-43016/l/broadcom- q http://elinux.org/RPi_Easy_SD_Card_Setup#Copying_an_image_to_th
datasheet-for-bcm2835-soc-used-in-raspberry-pi e_SD_Card_in_Linux_.28command_line.29
q http://en.wikipedia.org/wiki/List_of_single-board_computers q http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-
q http://www.sakoman.com/OMAP/microsd-card-perfomance-test- Burning/Win32-Disk-Imager.shtml
results.html q http://www.h2g2.com/approved_entry/A13735596
q http://elinux.org/RPi_VerifiedPeripherals q http://www.raspberrypi.org/faqs
q http://elinux.org/Rpi_Low-level_peripherals q https://thepihut.com/products/raspberry-pi-zero?variant=14062734980
q http://elinux.org/RPi_Cases q https://thepihut.com/products/raspberry-pi-zero?variant=14062734980

Thank You

32

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy