Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Khaterine Castellano

March 01, 2018
Tweet

Other Decks in Technology

Transcript

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

    your RaspberryPi → Adding Swift to your Pi → Swift with Pins → Demo → Lessons learned
  2. !

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

    Check the Swift version using swift —-version
  4. ⚠ → 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
  5. SwiftyGPIO // swift-tools-version:3.1 import PackageDescription let package = Package( name:

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

    == "ON" { selectedPin.value = 1 } else { selectedPin.value = 0 } return selectedPin.value }
  8. 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΁ګᴴͫ΢ͼ͚Ρ
  9. 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ኾݩΨႰͲ΀͚Ξ͜΁ͭͼͥ Ͷ͚ͫ