Swift Package Index


LSM303 Accelerometer access through Swift on Raspberry Pi


  • The latest stable release is 1.0.0. Released almost 2 years ago.
  • The last commit to master was almost 2 years ago.

Swift Version Compatibility

  • 1.0.0 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 1.0.0 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

LSM303

A Swift driver for the LSM303DLHC controller over I2C, using SwiftyGPIO. The code has been tested with the FLORA sensor sold by Adafruit (https://www.adafruit.com/product/1247).

import Foundation
import LSM303

print("start")
let lsm303 = LSM303(for: .RaspberryPi3)
lsm303.setAccScale(scale: .G2)
lsm303.setMagGain(gain: .GAIN_1_3)

while (true) {
        lsm303.read()
        print("accel \(lsm303.accel.x) \(lsm303.accel.y) \(lsm303.accel.z) mag \(lsm303.mag.x) \(lsm303.mag.y) \(lsm303.mag.z)")
}