Upload
buitram
View
314
Download
13
Embed Size (px)
Citation preview
Hans-PetterHalvorsen,M.Sc.
RaspberryPi
RaspberryPi
Hans-PetterHalvorsen,M.Sc.
https://www.raspberrypi.org https://dev.windows.com/iot
A900MHzquad-coreARMCortex-A7CPU,1GBRAM
Windows10IoTCore
Small-ScaleComputer
RaspberryPi- OverviewTheRaspberryPi2isalowcost,credit-cardsizedcomputerthatplugsintoacomputermonitororTV,andusesastandardkeyboardandmouse.TheRaspberryPi2canrunWindows10IoTCore.
13x- GPIOpins2x- SPIbuses1x- I2Cbus2x- 5Vpowerpins2x- 3.3Vpowerpins8x- Groundpins
3.5mmaudiojack/compositevideo
RaspberryPi3TheRaspberryPi3isthethirdgenerationRaspberryPi.ItreplacedtheRaspberryPi2ModelBinFebruary2016.ComparedtotheRaspberryPi2ithas:• A1.2GHz64-bitquad-coreARMv8CPU• 802.11nWirelessLAN• Bluetooth4.1• BluetoothLowEnergy(BLE)
RaspberryPi- ConnectorsTheRaspberryPi2typeBrunsaquad-coreARMCortex-A7CPUand1GBRAM.ItoffersthefollowingConnectors:• 4xUSB2.0sockets• 10/100BaseTEthernetsocket• HDMIvideosocket• RCAcompositevideosocket• microSDcardsocket• PoweredfrommicroUSBsocket• 3.5mmaudiooutjack• HeaderforGPIOandserialbuses(I2CandSPI)• DisplaySerialInterface(DSI)15wayflatflexcableconnectorwithtwodata
lanesandaclocklane• Cameraconnector15-pinMIPICameraSerialInterface(CSI-2)
RaspberryPi- PinMappings
RaspberryPi– 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:GeneralPurposeInput/Output
ThesePinscanbeusedforDigitalInput/Output
ThisExampleopensGPIO5 asanoutputandwritesadigital‘1’outonthepin
Hans-PetterHalvorsen,M.Sc.
RaspberryPiWindows10IoTCoreforRaspberryPi
Windows10IoT Core• Windows10IoT CoreisasmallscaledversionofWindowsrunningonsmalldevicessuchasRaspberryPi2
• https://dev.windows.com/iot
IoT– InternetofThings
Hans-PetterHalvorsen,M.Sc.
RaspberryPiCommunicationProtocols
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
http://www.byteparadigm.com/applications/introduction-to-i2c-and-spi-protocols
RaspberryPi– SPIBus• SerialPeripheralInterface(SPI)isasynchronousserialdataprotocolusedby
microcontrollersforcommunicatingwithoneormoreperipheraldevicesquicklyovershortdistances.
• WithanSPIconnectionthereisalwaysonemasterdevice(usuallyamicrocontroller)whichcontrolstheperipheraldevices.
• SPIdevicescommunicateinfullduplexmodeusingamaster-slavearchitecturewithasinglemaster.
• TheinterfacewasdevelopedbyMotorolaandhasbecomeadefactostandard.• Typicalapplicationsincludesensors,SecureDigitalcards,andliquidcrystaldisplays
(LCD).
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
SCLK:SerialClock(outputfrommaster)MOSI:MasterOutput,SlaveInput(outputfrommaster)MISO:MasterInput,SlaveOutput(outputfromslave)SS(orSC):SlaveSelect(activelow,outputfrommaster)
https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi
RaspberryPi– 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);
RaspberryPi- 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
RaspberryPi- I2CBusThereisoneI2CcontrollerI2C1 exposedonthepinheaderwithtwolinesSDA andSCL.1.8KΩinternalpull-upresistorsarealreadyinstalledontheboardforthisbus.
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
DigitalTemperatureSensorwithI²CInterface
http://home.hit.no/~hansha/documents/lab/Lab%20Equipment/iot_sensors.htm
HoneywellHumiditySensorwithI²C/SPIInterface
HoneywellHIH-6120-021-0014-PinSIPTemperature&HumiditySensor
http://home.hit.no/~hansha/documents/lab/Lab%20Equipment/iot_sensors.htm
Hans-PetterHalvorsen,M.Sc.
RaspberryPiRaspberryPiCamera
RaspberryPiCameraTheRaspberryPiCameraisidealforHomeSecurityApplications
ConnectitdirectlytotheCameraInterfaceontheRaspberryPi
https://www.raspberrypi.org/help/camera-module-setup/
5megapixelresolutionStillimages2592x1944Video:1080p30
Note!Thismoduleisonlycapableoftakingpicturesandvideo,notsound
Hans-PetterHalvorsen,M.Sc.
UniversityCollegeofSoutheastNorwaywww.usn.no
E-mail:[email protected]:http://home.hit.no/~hansha/