Easily use I2C and its subset SMBus from Clojure JVM.
Based on linux-i2c.java which provides an API around the standard Linux interface for talking to slave devices.
This is a small overview, the full API is available on Cljdoc.
In short, without error checking :
(require '[helins.linux.i2c :as i2c]
'[helins.linux.i2c.smbus :as smbus])
;; Selects the relevant "/dev/i2c-X" bus from the filesystem.
;;
(with-open [bus (i2c/bus "/dev/i2c-1")]
;; Selects a slave device.
;;
(i2c/select-slave bus
0x24)
;; Reads 8 bytes.
;;
(i2c/read bus
8)
;; => [...]
;; Writes a few bytes
;;
(i2c/write bus
[42 1 2 3])
;; Does a transactions, several messages without interruption.
;;
(i2c/transaction bus
[{::i2c/slave-address 0x24
::i2c/write [42 1 2 3]}
{::i2c/slave-address 0x24
::i2c/read 4
::i2c/tag :some-read}])
;; => {:some-read [...]}
;; A few SMBus operations.
(smbus/quick-write bus)
(smbus/read-byte bus
42)
(smbus/write-block bus
43
[1 2 3])
)
Here are examples of libraries leveraging theses utilities for targetting specific I2C slave devices:
Copyright © 2017 Adam Helinski
Licensed under the term of the Mozilla Public License 2.0, see LICENSE.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close