Slide 1

Slide 1 text

SwiftyPi Taking Swift to the NEXT frontier

Slide 2

Slide 2 text

Who am I? Informatics Engineer Senior iOS Developer @

Slide 3

Slide 3 text

Agenda → Swift in Embedded Systems → How to setup your RaspberryPi → Adding Swift to your Pi → Swift with Pins → Demo → Lessons learned

Slide 4

Slide 4 text

Swift in Embedded Systems

Slide 5

Slide 5 text

Evolution of Swift

Slide 6

Slide 6 text

Enter... the Raspberry Pi

Slide 7

Slide 7 text

How to setup your RaspberryPi

Slide 8

Slide 8 text

Choosing the Operating System

Slide 9

Slide 9 text

Slide 10

Slide 10 text

Adding Swift to your Pi

Slide 11

Slide 11 text

!

Slide 12

Slide 12 text

Setting up Swift → Download the Swift 3.1.1 binaries → Check the Swift version using swift —-version

Slide 13

Slide 13 text

Swift with pins

Slide 14

Slide 14 text

How to lay out our circuit?

Slide 15

Slide 15 text

⚠ → To verify your connection use sudo apt-get install wiringpi → To setup the pin as an output we do gpio mode 13 out → To switch it on we do gpio write 13 1

Slide 16

Slide 16 text

Disclaimer

Slide 17

Slide 17 text

SwiftyGPIO // swift-tools-version:3.1 import PackageDescription let package = Package( name: "TestProject", dependencies: [ .Package(url: "https://github.com/uraimo/SwiftyGPIO.git", majorVersion: 0) ] )

Slide 18

Slide 18 text

Setting up the Led import SwiftyGPIO import Foundation class PinService: NSObject { private let gpios: [GPIOName: GPIO] private let selectedPin: GPIO override init() { self.gpios = SwiftyGPIO.GPIOs(for: .RaspberryPi3) guard let pin = gpios[.P27] else { fatalError("Unable to initialise the GPIO pin") } self.selectedPin = pin self.selectedPin.direction = .OUT } }

Slide 19

Slide 19 text

Switching ON/OFF func switchLed(status: String) -> Int { if status == "ON" { selectedPin.value = 1 } else { selectedPin.value = 0 } return selectedPin.value }

Slide 20

Slide 20 text

Led on/off

Slide 21

Slide 21 text

Berlin Train System

Slide 22

Slide 22 text

Setting up Vapor

Slide 23

Slide 23 text

Demo !

Slide 24

Slide 24 text

What have we done?

Slide 25

Slide 25 text

Lessons learned → You can connect your RPi to your computer and share the internet via Ethernet cable. RPiΨπЀϡϲЄό΁婲͚ͽ̵EthernetξЄϣϸΨͺ ͡͹ͼαЀόЄϚϐϕ΁وํͽͣΡΞ͜΁΀͹͵̶ → The RaspberryPi is constrained to Swift 3.1.1 because there is no ARMv7 support for Swift 4 Swift 4΄ARMv7ςϪЄϕ͢΀͚͵Η̵RaspberryPi΅ Swift 3.1.1΁ګᴴͫ΢ͼ͚Ρ

Slide 26

Slide 26 text

Lessons learned part II → If the led does not turn on, CHECK YOUR CONNECTION LED͢ᅩᅌͭ΀͚;ͣ΅̵ള姆Ψ嘦扯ͭͼͥͶ͚ͫ → Try not to mix the physical PIN number and the GPIO number ᇔቘPINኾݩ;GPIOኾݩΨႰͲ΀͚Ξ͜΁ͭͼͥ Ͷ͚ͫ

Slide 27

Slide 27 text

Thank you! @katecastellano GitHub: https://github.com/kcastellano/ SwiftyPi