{"id":25436658,"url":"https://github.com/peterschwarz/clj-gpio","last_synced_at":"2025-08-20T15:34:21.611Z","repository":{"id":16825219,"uuid":"19584488","full_name":"peterschwarz/clj-gpio","owner":"peterschwarz","description":"A basic library for reading, writing and watching GPIO signals on a Raspberry PI, in a REPL-friendly way.","archived":false,"fork":false,"pushed_at":"2016-01-05T20:49:28.000Z","size":66,"stargazers_count":76,"open_issues_count":0,"forks_count":5,"subscribers_count":7,"default_branch":"development","last_synced_at":"2024-12-15T13:39:53.283Z","etag":null,"topics":["clojure","gpio-port","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterschwarz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-08T18:35:23.000Z","updated_at":"2024-10-04T18:33:16.000Z","dependencies_parsed_at":"2022-08-27T00:11:49.423Z","dependency_job_id":null,"html_url":"https://github.com/peterschwarz/clj-gpio","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterschwarz%2Fclj-gpio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterschwarz%2Fclj-gpio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterschwarz%2Fclj-gpio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterschwarz%2Fclj-gpio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterschwarz","download_url":"https://codeload.github.com/peterschwarz/clj-gpio/tar.gz/refs/heads/development","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239136876,"owners_count":19587896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","gpio-port","raspberry-pi"],"created_at":"2025-02-17T08:21:24.070Z","updated_at":"2025-02-17T08:21:24.828Z","avatar_url":"https://github.com/peterschwarz.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/peterschwarz/clj-gpio.svg)](https://travis-ci.org/peterschwarz/clj-gpio)\n\n# clj-gpio\n\nA basic library for reading, writing and watching GPIO signals on a Raspberry\nPi, in a Clojure REPL-friendly way. Now, also targets ClojureScript.\n\n## Usage\n\nAdd the following to your `project.clj`\n\n    [clj-gpio 0.2.0]\n\nFire up a REPL, and require `gpio.core`.\n\n### GPIO Read/Write \n\nWe can open a basic read/write gpio port as follows (let's say we have an LED\nconncted to GPIO 17):\n\n    user=\u003e (require '[gpio.core :refer :all] :reload)\n    nil\n    user=\u003e (def port (open-port 17))\n    #'user/port\n\nTo read the value of the port, we can do the following:\n\n    user=\u003e (read-value port)\n    :low\n\nTo set values on the port, The port needs to be configured for `out` mode:\n\n    user=\u003e (set-direction! port :out)\n\nThis also works with `'out` and `\"out\"`.  A value can be written to the port\nas follows:\n\n    user=\u003e (write-value! port :high)\n\nWith our LED connected to gpio 17, we should see it turned on.  We can also\nread back the value and see that `(= :high @port)`.\n\nWe can also toggle the state, for convenience:\n\n    user=\u003e (toggle! port)\n\nwhich will flip the state from `:low` to `:high` or vice versa.\n\n### GPIO Listening.\n\nWe can also pull events off of a gpio port by using `open-channel-port`.  In\naddition to setting directions, values etc, we set the edge change that we'll\nlisten for, and we can create a `core.async` channel from which can receive\nvalues. \n\nFor example (if we have a push button on GPIO 18):\n\n    user=\u003e (def ch-port (open-channel-port 18))\n    #'user/ch-port\n    user=\u003e (set-direction! ch-port :in)\n    ...\n    user=\u003e (set-edge! ch-port :both) ; or :falling, :rising, and :none to disable \n    ...\n\n We'll also set the bit to :high when the button pressed:\n\n    user=\u003e (set-active-low! ch-port true) \n\nLet's turn on the LED we defined in the Read/Write example above when our\nbutton is pressed: \n\n    user=\u003e (def ch (create-edge-channel ch-port))\n    #'user/ch\n    user=\u003e  (require '[clojure.core.async :as a :refer [go \u003c!]])\n    nil\n    user=\u003e (go (loop []\n             (when-let [value (\u003c! ch)]\n                (write-value! port value)\n                (recur))))\n    #\u003cManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@1197ad0\u003e\n\n\nWhen we're finished with the channel, we call:\n\n     user=\u003e (a/close! ch)\n     nil\n\nAnd clean up our ports:\n\n    user=\u003e (close! port)\n    nil\n    user=\u003e (close! ch-port)\n    nil\n\n## Development\n\nFirst compile the java sources:\n\n    lein javac\n\nthen fire up your REPL and require `gpio.core` as usual.\n\nNote, the edge channel will only operate on the Raspberry PI platform.\n\n## License\n\nCopyright © 2014 Peter Schwarz\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterschwarz%2Fclj-gpio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterschwarz%2Fclj-gpio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterschwarz%2Fclj-gpio/lists"}