Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sephiroth87/smbus-swift
Swift library for SMBus access through the i2c /dev interface on Linux
https://github.com/sephiroth87/smbus-swift
Last synced: about 7 hours ago
JSON representation
Swift library for SMBus access through the i2c /dev interface on Linux
- Host: GitHub
- URL: https://github.com/sephiroth87/smbus-swift
- Owner: Sephiroth87
- License: gpl-2.0
- Created: 2016-01-13T23:09:06.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-10T00:12:25.000Z (over 7 years ago)
- Last Synced: 2024-10-31T02:33:33.978Z (8 days ago)
- Language: Swift
- Size: 14.6 KB
- Stars: 32
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SMBus-swift is a linux library to communicate with SMBus/I2C devices through /dev/i2c.
##Requirements
Before beign able to use SMBus in your Swift code, you should install some Linux C libraries.On a Debian-like distro:
sudo apt-get install i2c-tools libi2c-dev
Then you have to make sure the i2c module is active. So check or add `i2c-dev` to `/etc/modules`. Like:# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
i2c-dev##Installation
The library is being written for/on a Raspberry Pi where the Package Manager is not functional yet, so I couldn't really figure out a way to make it work with that, and you'll have to do it manually for now.
After cloning, compile your program adding the 2 system dependencies and the main file, like
```
swiftc -o MyProgram -I ./SMBus-swift/Packages/Ci2c -I ./SMBus-swift/Packages/CioctlHelper ./SMBus-swift/Sources/SMBus.swift main.swift
```
You can look [here](https://github.com/Sephiroth87/scroll-phat-swift) for some examples on how to include the library in your program.##Usage
No need to import anything since the library is built together with your other sources.
To open the connection create an SMBus object:
```
try bus = SMBus(busNumber: 1) // opens /dev/i2c-1
```
and then send your commands:
```
try bus.writeI2CBlockData(0x60, command: UInt8(0x01), values: [UInt8(2)])
```##TODO
- [x] Add missing functions
- [ ] Add documentation
- [ ] Support Package Manager