All Projects → peterschwarz → Clj Gpio

peterschwarz / Clj Gpio

Licence: epl-1.0
A basic library for reading, writing and watching GPIO signals on a Raspberry PI, in a REPL-friendly way.

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Clj Gpio

Homeassistant Config
My personal Home Assistant config
Stars: ✭ 66 (-7.04%)
Mutual labels:  raspberry-pi
Nowify
A Spotify 'Now Playing' screen designed for Raspberry Pi
Stars: ✭ 68 (-4.23%)
Mutual labels:  raspberry-pi
Homekitcam
A project to make a Raspberry Pi driven, HomeKit Enabled camera.
Stars: ✭ 69 (-2.82%)
Mutual labels:  raspberry-pi
Openframeworks
openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
Stars: ✭ 8,652 (+12085.92%)
Mutual labels:  raspberry-pi
Client
An Opensource Alternative to the Elgato Stream Deck for the Raspberry Pi
Stars: ✭ 67 (-5.63%)
Mutual labels:  raspberry-pi
Chromium os Raspberry pi
Build your Chromium OS for Raspberry Pi 3B/3B+/4B and Pi400
Stars: ✭ 1,156 (+1528.17%)
Mutual labels:  raspberry-pi
Guitar
Git GUI Client
Stars: ✭ 1,136 (+1500%)
Mutual labels:  raspberry-pi
Yin Yang Ranch
Distributed Computer Vision Software & Raspberry Pis to help manage a farm
Stars: ✭ 71 (+0%)
Mutual labels:  raspberry-pi
Raztot
A simple DIY, browser controlled, RPi + WebRTC video streaming rover
Stars: ✭ 67 (-5.63%)
Mutual labels:  raspberry-pi
Mic hat
2 Mic Array for Raspberry Pi
Stars: ✭ 69 (-2.82%)
Mutual labels:  raspberry-pi
Awesome Raspberry Pi
📝 A curated list of awesome Raspberry Pi tools, projects, images and resources
Stars: ✭ 9,343 (+13059.15%)
Mutual labels:  raspberry-pi
Bthidhub
Bluetooth HID hub
Stars: ✭ 65 (-8.45%)
Mutual labels:  raspberry-pi
Rpi Vk Driver
VK driver for the Raspberry Pi (Broadcom Videocore IV)
Stars: ✭ 1,160 (+1533.8%)
Mutual labels:  raspberry-pi
Raspi Overlayroot
Protect your SD card against wear and tear
Stars: ✭ 66 (-7.04%)
Mutual labels:  raspberry-pi
Raspberry Pi Diy Projects
Collection of Do-It-Yourself Projects on Raspberry Pi 2 / 3 & Zero W with diverse HATs and pHATs.
Stars: ✭ 70 (-1.41%)
Mutual labels:  raspberry-pi
Ultimatemrz Sdk
Machine-readable zone/travel document (MRZ / MRTD) detector and recognizer using deep learning
Stars: ✭ 66 (-7.04%)
Mutual labels:  raspberry-pi
Pi ina219
This Python library supports the INA219 voltage, current and power monitor from Texas Instruments with a Raspberry Pi using the I2C bus. The intent of the library is to make it easy to use the quite complex functionality of this sensor.
Stars: ✭ 68 (-4.23%)
Mutual labels:  raspberry-pi
Dspi
Digital Signal Processing (or Pi). Adventures in making my Raspberry Pi 3 realtime, and running audio DSP.
Stars: ✭ 71 (+0%)
Mutual labels:  raspberry-pi
Batterymonitor
Python code to monitor and log battery data
Stars: ✭ 70 (-1.41%)
Mutual labels:  raspberry-pi
Computer Vision Raspberrypi
Sample projects for Computer Vision with Raspberry Pi and Movidius Neural Compute Stick
Stars: ✭ 69 (-2.82%)
Mutual labels:  raspberry-pi

Build Status

clj-gpio

A basic library for reading, writing and watching GPIO signals on a Raspberry Pi, in a Clojure REPL-friendly way. Now, also targets ClojureScript.

Usage

Add the following to your project.clj

[clj-gpio 0.2.0]

Fire up a REPL, and require gpio.core.

GPIO Read/Write

We can open a basic read/write gpio port as follows (let's say we have an LED conncted to GPIO 17):

user=> (require '[gpio.core :refer :all] :reload)
nil
user=> (def port (open-port 17))
#'user/port

To read the value of the port, we can do the following:

user=> (read-value port)
:low

To set values on the port, The port needs to be configured for out mode:

user=> (set-direction! port :out)

This also works with 'out and "out". A value can be written to the port as follows:

user=> (write-value! port :high)

With our LED connected to gpio 17, we should see it turned on. We can also read back the value and see that (= :high @port).

We can also toggle the state, for convenience:

user=> (toggle! port)

which will flip the state from :low to :high or vice versa.

GPIO Listening.

We can also pull events off of a gpio port by using open-channel-port. In addition to setting directions, values etc, we set the edge change that we'll listen for, and we can create a core.async channel from which can receive values.

For example (if we have a push button on GPIO 18):

user=> (def ch-port (open-channel-port 18))
#'user/ch-port
user=> (set-direction! ch-port :in)
...
user=> (set-edge! ch-port :both) ; or :falling, :rising, and :none to disable 
...

We'll also set the bit to :high when the button pressed:

user=> (set-active-low! ch-port true) 

Let's turn on the LED we defined in the Read/Write example above when our button is pressed:

user=> (def ch (create-edge-channel ch-port))
#'user/ch
user=>  (require '[clojure.core.async :as a :refer [go <!]])
nil
user=> (go (loop []
         (when-let [value (<! ch)]
            (write-value! port value)
            (recur))))
#<ManyToManyChannel [email protected]>

When we're finished with the channel, we call:

 user=> (a/close! ch)
 nil

And clean up our ports:

user=> (close! port)
nil
user=> (close! ch-port)
nil

Development

First compile the java sources:

lein javac

then fire up your REPL and require gpio.core as usual.

Note, the edge channel will only operate on the Raspberry PI platform.

License

Copyright © 2014 Peter Schwarz

Distributed under the Eclipse Public License, the same as Clojure.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].