{"id":17483414,"url":"https://github.com/kopera/erlang-gpio","last_synced_at":"2025-04-22T14:24:59.106Z","repository":{"id":65213797,"uuid":"277489472","full_name":"kopera/erlang-gpio","owner":"kopera","description":"An Erlang application for interfacing with GPIOs on Linux systems.","archived":false,"fork":false,"pushed_at":"2023-04-03T04:32:58.000Z","size":40,"stargazers_count":12,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-18T10:53:58.262Z","etag":null,"topics":["embedded","erlang","gpio","linux"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kopera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-06T08:45:55.000Z","updated_at":"2024-09-04T03:42:39.000Z","dependencies_parsed_at":"2025-03-03T19:44:07.506Z","dependency_job_id":null,"html_url":"https://github.com/kopera/erlang-gpio","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kopera%2Ferlang-gpio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kopera%2Ferlang-gpio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kopera%2Ferlang-gpio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kopera%2Ferlang-gpio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kopera","download_url":"https://codeload.github.com/kopera/erlang-gpio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250257044,"owners_count":21400640,"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":["embedded","erlang","gpio","linux"],"created_at":"2024-10-19T00:04:53.975Z","updated_at":"2025-04-22T14:24:59.089Z","avatar_url":"https://github.com/kopera.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gpio\n\nAn Erlang application for interfacing with GPIOs on Linux systems.\n\nThis GPIO application allows for reading and writing to GPIO pins as well as \nmonitoring input GPIO pins.\n\n# Setup\n\nYou need to add `gpio` as a dependency to your project. If you are using\n`rebar3`, you can add the following to your `rebar.config`:\n\n```erlang\n{deps, [\n    {gpio, \"0.6.3\"}\n]}.\n```\n\nAlso ensure that `gpio` is added as a dependency to your application, by\nupdating your `.app.src` file:\n\n```erlang\n{application, my_app, [\n\n    {applications, [\n        kernel,\n        stdlib,\n\n        gpio  % \u003c- You need this in your applications list\n    ]}\n]}.\n```\n\n# Usage\n\n## Opening the gpio chip\n\nThe following will open gpiochip2 (typically called GPIO3):\n\n```erlang\n\u003e {ok, Chip} = gpio:open_chip(\"/dev/gpiochip2\").\n{ok, #Ref\u003c0.3061467712.2848194561.68326\u003e}\n```\n\nOnce the chip is open you need to either use `gpio:open_lines/5` if you want\nto read/write values to/from the lines, or `gpio:open_line_events/5` if you want\nto monitor a line.\n\n## Opening gpio lines\nThe following will open a single line `IO1` from the previously open\nchip (typically this would be `GPIO3_IO1`). The opened line is configured as an\noutput with a default value of `0`. The last parameter is used to communicate\nto the kernel a description of the chip use. If `debugfs` is enabled, this\ninformation is visible in `/sys/kernel/debug/gpio`.\n\n```erlang\n\u003e {ok, SingleLine} = gpio:open_lines(Chip, [1], [output], [0], \"my-application\").\n{ok, #Ref\u003c0.3061467712.2848194561.68334\u003e}\n```\n\nTo write a `0` to the GPIO line, you can use:\n\n```erlang\nok = gpio:write_lines(SingleLine, {0}).\n```\n\nAlternatively, to write a `1` to the GPIO line, you can use:\n```erlang\nok = gpio:write_lines(SingleLine, {1}).\n```\n\nThe `gpio:write_lines/2` function takes a tuple of `0` and `1` values. The arity\nof this tuple must be equal to the width of the lines. Previously, we opened a\nsingle line, which is why we use a single element tuple. If instead, we opened\n2 lines, we would need to provide a 2 element tuple like below:\n\n```erlang\n\u003e {ok, MultiLines} = gpio:open_lines(Chip, [1, 2, 5], [output], [0, 0, 0], \"my-application\").\n{ok, #Ref\u003c0.3061467712.2848194561.68339\u003e}\n\u003e ok = gpio:write_lines(MultiLines, {1, 1, 1}). % Set all pins to 1\nok\n\u003e ok = gpio:write_lines(MultiLines, {1, 0, 1}). % Set IO1 and IO5 to 1, IO2 is set to 0\nok\n```\n\n## Monitoring line events\n\nThe following will monitor the pin `IO10` (`GPIO3_I10`) for rising values\n(changes from 0 to 1).\n\n```erlang\n\u003e {ok, LineEvents} = gpio:open_line_events(Chip, 10, [], [rising_edge], \"my-application\").\n{ok, {#Ref\u003c0.3061467712.2848194561.68344\u003e, \u003c0.340.0\u003e}}\n```\n\nThe monitoring process will then receive messages like the following:\n\n```erlang\n{gpio, LineEvents, {event, Timestamp, Type}}\n```\n\nWhere `Timestamp` is a system timestamp in nanosecond, and `Type` is either\n`rising_edge` or `falling_edge`.\n\nIn case of an error, the process might receive a message like the following:\n\n```erlang\n{gpio, LineEvents, {error, Error}}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkopera%2Ferlang-gpio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkopera%2Ferlang-gpio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkopera%2Ferlang-gpio/lists"}