{"id":18226782,"url":"https://github.com/tokafish/pigpiox","last_synced_at":"2025-04-03T09:30:26.769Z","repository":{"id":55623811,"uuid":"100837264","full_name":"tokafish/pigpiox","owner":"tokafish","description":"An Elixir wrapper around pigpiod for the Raspberry PI","archived":false,"fork":false,"pushed_at":"2022-10-05T17:06:51.000Z","size":29,"stargazers_count":35,"open_issues_count":7,"forks_count":23,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-23T13:09:35.359Z","etag":null,"topics":["elixir","embedded","nerves"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/tokafish.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":"2017-08-20T04:06:35.000Z","updated_at":"2023-09-01T08:49:45.000Z","dependencies_parsed_at":"2022-08-15T04:40:58.397Z","dependency_job_id":null,"html_url":"https://github.com/tokafish/pigpiox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokafish%2Fpigpiox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokafish%2Fpigpiox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokafish%2Fpigpiox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokafish%2Fpigpiox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokafish","download_url":"https://codeload.github.com/tokafish/pigpiox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246975977,"owners_count":20862996,"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":["elixir","embedded","nerves"],"created_at":"2024-11-04T05:03:28.007Z","updated_at":"2025-04-03T09:30:26.491Z","avatar_url":"https://github.com/tokafish.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pigpiox\n\nPigpiox is a wrapper around pigpiod for the Raspberry Pi. For all of pigpio's features, check out its [documentation](http://abyz.me.uk/rpi/pigpio/).\n\n\n# Requirements\n\nTo use Pigpiox, pigpiod must be included in your firmware. Currently, this is included by default on `nerves_system_rpi0`, but not on other Pi systems.\n\nIf you'd like to use Pigpiox on one of those systems, customize the nerves system you're interested in, and add `BR2_PACKAGE_PIGPIO=y` to its `nerves_defconfig`.\n\n# Installation\n\nIn your firmware's `mix.exs`, add `pigpiox` to your deps for your system target:\n\n```elixir\ndef deps(target) do\n  [ system(target),\n    {:pigpiox, \"~\u003e 0.1\"}\n  ]\n```\n\n# Usage\n\nAdding pigpiox as a dependency to your system will automatically launch the pigpio daemon and open a socket to communicate with it. To interact with pigpiod, Pigpiox provides various modules exposing different areas of functionality.\n\nAll documentation available on [hexdocs](https://hexdocs.pm/pigpiox/).\n\n## GPIO\n\n### Basic functionality\n\nThe `Pigpiox.GPIO` provides basic GPIO functionality. Here's an example of reading and writing a GPIO:\n\n```elixir\ngpio = 17\n\nPigpiox.GPIO.set_mode(gpio, :input)\n{:ok, level} = Pigpiox.GPIO.read(gpio)\n\nPigpiox.GPIO.set_mode(gpio, :output)\nPigpiox.GPIO.write(gpio, 1)\n```\n\n### Watching a GPIO\n\nWhen reading a GPIO, often it's useful to know immediately when its level changes, instead of having to constantly poll it. Here's an example:\n\n```elixir\n{:ok, pid} = Pigpiox.GPIO.watch(gpio)\n```\n\nAfter setting up a watch on a GPIO pin, the calling process will receive messages of the format `{:gpio_leveL_change, gpio, level}` as its level change.\n\n## Waveforms\n\nThe `Pigpiox.Waveform` module provides functions that allow you to create and send waveforms on the Raspberry Pi. Here's an example of pulsing a GPIO on and off every 500ms:\n\n```elixir\npulses = [\n  %Pigpiox.Waveform.Pulse{gpio_on: gpio, delay: 500000},\n  %Pigpiox.Waveform.Pulse{gpio_off: gpio, delay: 500000}\n]\n\nPigpiox.Waveform.add_generic(pulses)\n\n{:ok, wave_id} = Pigpiox.Waveform.create()\n\nPigpiox.GPIO.set_mode(gpio, :output)\n\nPigpiox.Waveform.repeat(wave_id)\n```\n\n## Clock\n\nThe `Pigpiox.Clock` module provides functions that allow you to set a clock on reserved pin.\n\n```elixir\nPigpiox.Clock.hardware_clk(gpio, 2_500_000)\n```\n\n## Pulse-width modulation (PWM)\n\nThe [`Pigpiox.Pwm` module](https://hexdocs.pm/pigpiox/Pigpiox.Pwm.html#content) provides functions that allow you to build and send waveforms with pigpiod.\nAccording to [Raspberry Pi's GPIO usage documentation](https://www.raspberrypi.org/documentation/usage/gpio/), here are the pins PWM is avaliable on:\n\n- Software PWM: all pins\n- Hardware PWM: GPIO12, GPIO13, GPIO18, GPIO19\n\n### Software PWM\n\nMax value for `level` is `255`. Here's an example of changing the brightness of an LED using software PWM.\n\n```elixir\ngpio = 12\nPigpiox.Pwm.gpio_pwm(gpio, 255) # 100%\nPigpiox.Pwm.gpio_pwm(gpio, 127) # 50%\nPigpiox.Pwm.gpio_pwm(gpio, 25)  # 10%\nPigpiox.Pwm.gpio_pwm(gpio, 2)   # 1%\n```\n\n### Hardware PWM\n\nMax value for `level` is `1_000_000`. Here's an example of changing the brightness of an LED using hardware PWM.\n\n```elixir\ngpio = 12\nfrequency = 800\nPigpiox.Pwm.hardware_pwm(gpio, frequency, 1_000_000) # 100%\nPigpiox.Pwm.hardware_pwm(gpio, frequency, 500_000)   # 50%\nPigpiox.Pwm.hardware_pwm(gpio, frequency, 100_000)   # 10%\nPigpiox.Pwm.hardware_pwm(gpio, frequency, 10_000)    # 1%\n```\n\n# Contributions\n\nThis library is still in a very early stage, and I'd appreciate any and all contributions. In particular, a short-term goal is getting feature parity with the [python](http://abyz.co.uk/rpi/pigpio/python.html) pigpiod client library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokafish%2Fpigpiox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokafish%2Fpigpiox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokafish%2Fpigpiox/lists"}