SystemOverview
RetrievingSensorData
ControllingLight,Heating,OpentheDoor,etc.
Temperature
Light
Camera? Youmay,e.g.,puttheSensorsonaBreadboard,usee.g.aPushButtonforDoorControl,LEDstoillustrateLightandHeatingControlRFID?
HomeAutomation Controller
DigitalSensors?
LabTopics• HomeAutomation/SmartHouseSolutions• InternetofThings(IoT)• Windows10• EmbeddedSystems• Protocols• SensorsandActuators• etc.
3
LabAssignmentOverview1. Setup&Configuration:InstallandConfigure
Windows10ontheRaspberryPi2. FollowStep-by-StepExampleswithBasic
SensorsandActuators3. SelectoneofthefollowingTasks:
a) DigitalSensorswithMonitoring/Loggingb) CameraSurveillancec) RFIDAccessControl
Seenextslidesfordetails...
Note!Notsupported inWindows10IoTCore/VisualStudio.UseMATLABifyouchooseoneofthese(seelaterslides)
Software
YoucandownloadVisualStudioProfessional2015fromDreamSparks
MakesuretoinstallthenecessarySoftwarebeforeyougotothelaboratory!
Software
Windows10IoTCore
Note!TheRaspberryPi2should useWindows10IoTCore,whileyourPCshould runthefullversionofWindows10
Hardware
NetworkEquipment?(ifneeded)
Hardware
YourPersonalComputer
SmallSensors
3.Camera
2.RFID
HumiditySensor
1.DigitalSensors
Temperature
TemperatureLight
Windows10IoT Core
HomeAutomationsolutionshasgreatlyincreasedinpopularityoverthepastseveralyears.HomeAutomationmayincludecentralizedcontroloflighting,heating,ventilationandairconditioning,appliances,securitylocksofgatesanddoorsandothersystems,toprovideimprovedconvenience,comfort,energyefficiencyandsecurity.
HomeAutomation• Thepossibilitiesareendless,youcancollectdatafromsensors,cameramonitoring,securitycontrol,lightcontrol,etc.
• TheRaspberryPiisagreatHomeAutomationControllerthatcanbeusedforthesepurposesandmore
9
A900MHzquad-coreARMCortex-A7CPU,1GBRAM
Windows10IoTCore
Small-ScaleComputer
RaspberryPi2- OverviewTheRaspberryPi2isalowcost,credit-cardsizedcomputerthatplugs intoacomputermonitororTV,andusesastandardkeyboardandmouse.TheRaspberryPi2canrunWindows10IoTCore.
13x- GPIOpins2x- SPIbuses1x- I2Cbus2x- 5Vpowerpins2x- 3.3Vpowerpins8x- Groundpins
3.5mmaudiojack/compositevideo
RaspberryPi2- Connectors
12
TheRaspberryPi2typeBrunsaquad-coreARMCortex-A7CPUand1GBRAM.ItoffersthefollowingConnectors:• 4xUSB2.0sockets• 10/100BaseT Ethernetsocket• HDMIvideosocket• RCAcompositevideosocket• microSD cardsocket• PoweredfrommicroUSB socket• 3.5mmaudiooutjack• HeaderforGPIOandserialbuses(I2CandSPI)• DisplaySerialInterface(DSI)15wayflatflexcableconnectorwithtwodata
lanesandaclocklane• Cameraconnector15-pinMIPICameraSerialInterface(CSI-2)
RaspberryPi2– GPIO
using Windows.Devices.Gpio;
public void GPIO()
// Get the default GPIO controller on the systemGpioController gpio = GpioController.GetDefault();if (gpio == null)
return; // GPIO not available on this sytem
// Open GPIO 5using (GpioPin pin = gpio.OpenPin(5))
// Latch HIGH valuepin.Write(GpioPinValue.High);
// Set the IO direction as outputpin.SetDriveMode(GpioPinDriveMode.Output);
// Close pin - will revert to its power-on state
GPIO:GeneralPurpose Input/Output
ThesePinscanbeusedforDigitalInput/Output
ThisExampleopensGPIO5 asanoutputandwritesadigital‘1’outonthepin
CommunicationProtocols• UART(UniversalAsynchronousReceiver/Transmitter,)• ...
– http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
• SPI(SerialPeripheralInterface)– ...– http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
• I2C(Inter-IntegratedCircuit)– ...– http://en.wikipedia.org/wiki/I2C
15http://www.byteparadigm.com/applications/introduction-to-i2c-and-spi-protocols
RaspberryPi2– SPIBus• SerialPeripheralInterface(SPI)isasynchronous serialdataprotocolusedby
microcontrollers forcommunicatingwithoneormoreperipheraldevicesquicklyovershortdistances.
• WithanSPIconnection thereisalwaysonemasterdevice(usuallyamicrocontroller)whichcontrolstheperipheraldevices.
• SPIdevicescommunicateinfullduplexmodeusingamaster-slavearchitecturewithasinglemaster.
• TheinterfacewasdevelopedbyMotorolaandhasbecomeadefactostandard.• Typicalapplicationsincludesensors,SecureDigitalcards,andliquidcrystaldisplays
(LCD).
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
SCLK:SerialClock(output frommaster)MOSI:MasterOutput,SlaveInput(output frommaster)MISO:MasterInput,SlaveOutput(output fromslave)SS(orSC):SlaveSelect(activelow,outputfrommaster)
https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi
RaspberryPi2– SPIBusThereare2SPIbuscontrollersavailableontheRPi2:SPI0 andSPI1
SPI0:Pin19- SPI0MOSIPin21- SPI0MISOPin23- SPI0SCLKPin24- SPI0CS0Pin26- SPI0CS1
SPI1:Pin38- SPI1MOSIPin35- SPI1MISOPin40- SPI1SCLKPin11- SPI1CS0
using Windows.Devices.Enumeration;using Windows.Devices.Spi;
public async void SPI()
// Get a selector string for bus "SPI0"string aqs = SpiDevice.GetDeviceSelector("SPI0");
// Find the SPI bus controller device with our selector stringvar dis = await DeviceInformation.FindAllAsync(aqs);if (dis.Count == 0);
return; // "SPI0" not found on this system
// Use chip select line CS0var settings = new SpiConnectionSettings(0);
// Create an SpiDevice with our bus controller and SPI settingsusing (SpiDevice device = await SpiDevice.FromIdAsync(dis[0].Id, settings))
byte[] writeBuf = 0x01, 0x02, 0x03, 0x04 ;device.Write(writeBuf);
RaspberryPi2- I2CBus
http://en.wikipedia.org/wiki/I2C
• I²C(Inter-IntegratedCircuit),isamulti-master,multi-slave,single-ended,serialcomputerbus
• Itistypicallyusedforattachinglower-speedperipheralICstoprocessorsandmicrocontrollers.
• I²CistypicallyspelledI2C(pronouncedI-two-C)• TheI²Cbuswasdevelopedin1982byPhilipsSemiconductor.• TheI²Cprotocolrequiresonly2wiresforconnectingalltheperipheraltoamicrocontroller.
https://learn.sparkfun.com/tutorials/i2c
RaspberryPi2- I2CBusThereisoneI2Ccontroller I2C1 exposedonthepinheaderwithtwolinesSDA andSCL.1.8KΩinternalpull-up resistorsarealreadyinstalledontheboardforthisbus.
Pin3- I2C1SDAPin5- I2C1SCL
using Windows.Devices.Enumeration;using Windows.Devices.I2c;
public async void I2C()
// Get a selector string for bus "I2C1"string aqs = I2cDevice.GetDeviceSelector("I2C1");
// Find the I2C bus controller with our selector stringvar dis = await DeviceInformation.FindAllAsync(aqs);if (dis.Count == 0)
return; // bus not found
// 0x40 is the I2C device addressvar settings = new I2cConnectionSettings(0x40);
// Create an I2cDevice with our selected bus controller and I2C settingsusing (I2cDevice device = await I2cDevice.FromIdAsync(dis[0].Id, settings))
byte[] writeBuf = 0x01, 0x02, 0x03, 0x04 ;device.Write(writeBuf);
SCL:SerialClockLine
SDA:SerialDataLine
BasicSensors&Actuators
21
Analog TemperatureSensor
PushButtonLED
ADC
Analog toDigitalConverter
TMP36
http://home.hit.no/~hansha/documents/lab/Lab%20Equipment/iot_sensors.htm
Windows10IoT Core• Windows10IoT CoreisasmallscaledversionofWindowsrunningonsmalldevicessuchasRaspberryPi2
• https://dev.windows.com/iot
IoT– InternetofThings
RaspberryPi+Windows10• Install andConfigureWindows10ontheRaspberryPi
• CreatesomeExamples (2?)(seenextslides)inordertobefamiliarwithArduino+Windows10IoTCore
• AddValue(ImprovethemwithyourPersonaltouch)totheExamplesyouselect!!
HelloWorldExampleApp
Followtheinstructionshere:http://ms-iot.github.io/content/en-US/win10/samples/HelloWorld.htm
26
BlinkingLEDExampleFollowtheinstructionshere:http://ms-iot.github.io/content/en-US/win10/samples/Blinky.htm
27
PushButtonExampleFollowtheinstructionshere:http://ms-iot.github.io/content/en-US/win10/samples/PushButton.htm
28
PotentiometerSensorExample
Followtheinstructionshere:http://ms-iot.github.io/content/en-US/win10/samples/Potentiometer.htm
29
TemperatureSensorExample
Followtheinstructionshere:https://www.hackster.io/4796/temperature-sensor-sample
TMP36TemperatureSensor
ADCConverter
ThissampleusesSPIcommunication.AtemperaturesensorisconnectedtoaADC,thenADCisconnectedtoraspberryPi2throughSPIPins.
DigitalSensors(I2C)
• CreateanApplicationforMonitoring/LoggingDatafromDigitalSensors
• Useone/orbothofthefollowingSensors:– TC74DigitalTemperatureSensorwithI2CInterface– HoneywellHumiditySensorwithI2CInterface
DigitalTemperatureSensorwithI²CInterface
34http://home.hit.no/~hansha/documents/lab/Lab%20Equipment/iot_sensors.htm
HoneywellHumiditySensor
35
withI²C/SPIInterface
HoneywellHIH-6120-021-0014-PinSIPTemperature&Humidity Sensor
http://home.hit.no/~hansha/documents/lab/Lab%20Equipment/iot_sensors.htm
(Thissensorisalittlemorecomplicatedtouse)
Camera- HomeSecurityApplication
• CreateanApplicationforVideoMonitoring,i.e.,anApplicationviewinganImageorVideofromtheRaspberryPiCamera
• Useeither–Windows10/VisualStudio2015– MATLABorSimulink
RaspberryPiCameraTheRaspberryPiCameraisidealforHomeSecurityApplications
ConnectitdirectlytotheCameraInterfaceon theRaspberryPi
https://www.raspberrypi.org/help/camera-module-setup/
5megapixelresolutionStillimages2592x1944Video:1080p30
Note!Thismoduleisonlycapableoftakingpicturesandvideo,notsound
RaspberryPiSupportfromMATLABhttp://se.mathworks.com/hardware-support/raspberry-pi-matlab.html
UsingMATLABwithaRaspberryPiCameraBoard:http://se.mathworks.com/videos/using-matlab-with-a-raspberry-pi-camera-board-94192.html
WiththeMATLABSupportPackageforRaspberryPiHardware,youcanaccessperipheraldevicesthroughtheRaspberryPi.ThissupportallowsyoutoacquiredatafromsensorsandimagingdevicesconnectedtotheRaspberryPi.Specifically,alibraryofMATLABfunctionsareprovidedforthefollowingRaspberryPiadd-onsandinterfaces:• RaspberryPiCameraBoard• I2Cinterface• SPIinterface• Serialinterface• GPIO
IfyouinadditionhasMATLABImage/VisionToolbox(es), youcanusebuilt-infunctions forfacerecognition, etc.
RFIDRadioFrequencyIDentification (RFID)isthewirelessuseofelectromagneticfields totransferdata,forthepurposesofautomaticallyidentifyingandtrackingtagsattachedtoobjects.
44https://en.wikipedia.org/wiki/Radio-frequency_identification
NFC• Nearfieldcommunication(NFC)isthesetofprotocolsthatenableselectronicdevicestoestablishradiocommunicationwitheachotherbytouchingthedevicestogetherorbringingthemintoproximitytoadistanceoftypically10cmorless.
• TwoNFCenableddevicesshouldbebroughtwithinfewcentimetersofeachothertoconnectthem,andthatiswhy,itisreferredastouchbasedinteraction
• ExampleApplePay
45https://en.wikipedia.org/wiki/Near_field_communication
RFIDvs.NFC• NFCisactuallyanextensionorasubcategoryofRFID.• NFCisthenewerversionofRFIDthatistypicallyforuseinaveryshort
distanceformakingpaymentsanddownloadingadvertisements• AsNFCisasafertechnologywithitsshortrangeofworkcomparedto
otherwirelesstechnologies,itcanbewidelyusedforpayments,ticketingandserviceadmittance.
• RFIDismorepopularthannearfieldcommunicationsbecauseithasawiderspectrumofuses.
• OneofthegreatfeaturesofNFCisthatNearfieldcommunicationscanbeinstalledinportabledeviceslikesmartphones.NFCtechnologycanactuallybeembeddedinachip
http://www.differencebetween.com/difference-between-rfid-and-vs-nfc/http://www.create-qr-codes.org/nfc/versus.html
ParallaxRFIFReader
47
RFIDCardReader,Serial PassiveRFIDTags
www.parallax.com - Searchfor28140
SerialInterfaceforusewithamicrocontroller
RaspberryPiSupportfromMATLABhttp://se.mathworks.com/hardware-support/raspberry-pi-matlab.html
WiththeMATLABSupportPackageforRaspberryPiHardware,youcanaccessperipheraldevicesthroughtheRaspberryPi.ThissupportallowsyoutoacquiredatafromsensorsandimagingdevicesconnectedtotheRaspberryPi.Specifically,alibraryofMATLABfunctionsareprovidedforthefollowingRaspberryPiadd-onsandinterfaces:• RaspberryPiCameraBoard• I2Cinterface• SPIinterface• Serialinterface• GPIO
FritzingAopensourcetoolformakingsimplewiringdiagramforyourhardwarewiringhttps://en.wikipedia.org/wiki/Fritzinghttp://fritzing.org
WiringmadewithFritzing
Hans-PetterHalvorsen,M.Sc.
UniversityCollegeofSoutheastNorwaywww.usn.no
E-mail:[email protected]:http://home.hit.no/~hansha/