gpio_rpi v0.2.0 GpioRpi

This is an Elixir interface to Raspberry PI GPIOs. Each GPIO is an independent GenServer.

Summary

Functions

Read the current value of the pin

Free the resources associated with pin and stop the GenServer

Set the input/output direction of the pin. Additionally allows setting :mode and `:interrupt’

Turn on “interrupts” on the input pin. The pin can be monitored for :rising transitions, :falling transitions, or :both. The process that calls this method will receive the messages

Changes the pullup register to :none, :down, or :up

Start and link a new GPIO GenServer. pin should be a valid GPIO pin number on the system and pin_direction should be :input or :output. Optional parameters: :mode set pullup register, see set_mode/2. :interrupt, enable interrupts, see set_int/2 for the different transitions

Write the specified value to the GPIO. The GPIO should be configured as an output. Valid values are 0 or false for logic low and 1 or true for logic high. Other non-zero values will result in logic high being output

Types

int_direction :: :rising | :falling | :both
pin_direction :: :input | :output
pullup_mode :: :none | :down | :up

Functions

read(pid)

Specs

read(pid) :: :ok | {:error, term}

Read the current value of the pin.

release(pid)

Specs

release(pid) :: :ok

Free the resources associated with pin and stop the GenServer.

set_direction(pid, pin_direction, opts \\ [])

Specs

set_direction(pid, pin_direction, [term]) ::
  :ok |
  {:error, term}

Set the input/output direction of the pin. Additionally allows setting :mode and `:interrupt’

set_int(pid, direction)

Specs

set_int(pid, int_direction) :: :ok | {:error, term}

Turn on “interrupts” on the input pin. The pin can be monitored for :rising transitions, :falling transitions, or :both. The process that calls this method will receive the messages.

set_mode(pid, pullup_mode)

Specs

set_mode(pid, pullup_mode) :: :ok | {:error, term}

Changes the pullup register to :none, :down, or :up.

start_link(pin, pin_direction, opts \\ [])

Specs

start_link(integer, pin_direction, [term]) :: {:ok, pid}

Start and link a new GPIO GenServer. pin should be a valid GPIO pin number on the system and pin_direction should be :input or :output. Optional parameters: :mode set pullup register, see set_mode/2. :interrupt, enable interrupts, see set_int/2 for the different transitions.

write(pid, value)

Specs

write(pid, 0 | 1 | true | false) ::
  :ok |
  {:error, term}

Write the specified value to the GPIO. The GPIO should be configured as an output. Valid values are 0 or false for logic low and 1 or true for logic high. Other non-zero values will result in logic high being output.