Pro Yearly is on sale from $80 to $50! »

SwiftyPi

 SwiftyPi

A short introduction on how to create a full project from Mobile App Development, to a Server application and Embedded code with the RaspberryPi and Swift

88a181294b46ef874498cb8be470f895?s=128

Khaterine Castellano

March 01, 2018
Tweet

Transcript

  1. SwiftyPi Taking Swift to the NEXT frontier

  2. Who am I? Informatics Engineer Senior iOS Developer @

  3. Agenda → Swift in Embedded Systems → How to setup

    your RaspberryPi → Adding Swift to your Pi → Swift with Pins → Demo → Lessons learned
  4. Swift in Embedded Systems

  5. Evolution of Swift

  6. Enter... the Raspberry Pi

  7. How to setup your RaspberryPi

  8. Choosing the Operating System

  9. Adding Swift to your Pi

  10. !

  11. Setting up Swift → Download the Swift 3.1.1 binaries →

    Check the Swift version using swift —-version
  12. Swift with pins

  13. How to lay out our circuit?

  14. ⚠ → 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
  15. Disclaimer

  16. SwiftyGPIO // swift-tools-version:3.1 import PackageDescription let package = Package( name:

    "TestProject", dependencies: [ .Package(url: "https://github.com/uraimo/SwiftyGPIO.git", majorVersion: 0) ] )
  17. 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 } }
  18. Switching ON/OFF func switchLed(status: String) -> Int { if status

    == "ON" { selectedPin.value = 1 } else { selectedPin.value = 0 } return selectedPin.value }
  19. Led on/off

  20. Berlin Train System

  21. Setting up Vapor

  22. Demo !

  23. What have we done?

  24. 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΁ګᴴͫ΢ͼ͚Ρ
  25. 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ኾݩΨႰͲ΀͚Ξ͜΁ͭͼͥ Ͷ͚ͫ
  26. Thank you! @katecastellano GitHub: https://github.com/kcastellano/ SwiftyPi