circuits_gpio v0.1.0 Circuits.GPIO View Source

Link to this section Summary

Functions

Release the resources associated with the GPIO

Return info about the low level GPIO interface

Open a GPIO for use. pin should be a valid GPIO pin number on the system and pin_direction should be :input or :output

Get the GPIO pin number

Read the current value on a pin

Change the direction of the pin

Enable or disable pin value change notifications. The notifications are sent based on the trigger parameter

Enable or disable internal pull-up or pull-down resistor to GPIO pin

Set the value of a pin. The pin should be configured to an output for this to work

Link to this section Types

Link to this type

pin_direction() View Source
pin_direction() :: :input | :output

Link to this type

pull_mode() View Source
pull_mode() :: :not_set | :none | :pullup | :pulldown

Link to this type

trigger() View Source
trigger() :: :rising | :falling | :both | :none

Link to this type

value() View Source
value() :: 0 | 1

Link to this section Functions

Release the resources associated with the GPIO.

This is optional. The garbage collector will free GPIO resources that aren't in use, but this will free them sooner.

Return info about the low level GPIO interface

This may be helpful when debugging issues.

Link to this function

open(pin_number, pin_direction) View Source
open(pin_number(), pin_direction()) :: {:ok, reference()} | {:error, atom()}

Open a GPIO for use. pin should be a valid GPIO pin number on the system and pin_direction should be :input or :output.

Get the GPIO pin number

Read the current value on a pin.

Link to this function

set_direction(gpio, pin_direction) View Source
set_direction(reference(), pin_direction()) :: :ok | {:error, atom()}

Change the direction of the pin.

Link to this function

set_interrupts(gpio, trigger, opts \\ []) View Source
set_interrupts(reference(), trigger(), list()) :: :ok | {:error, atom()}

Enable or disable pin value change notifications. The notifications are sent based on the trigger parameter:

  • :none - No notifications are sent
  • :rising - Send a notification when the pin changes from 0 to 1
  • :falling - Send a notification when the pin changes from 1 to 0
  • :both - Send a notification on all changes

Available Options:

  • suppress_glitches - It is possible that the pin transitions to a value and back by the time that Circuits GPIO gets to process it. This controls whether a notification is sent. Set this to false to receive notifications.
  • receiver - Process which should receive the notifications. Defaults to the calling process (self())

Notifications look like:

{:gpio, pin_number, timestamp, value}

Where pin_number is the pin that changed values, timestamp is roughly when the transition occurred in nanoseconds, and value is the new value.

Link to this function

set_pull_mode(gpio, pull_mode) View Source
set_pull_mode(reference(), pull_mode()) :: :ok | {:error, atom()}

Enable or disable internal pull-up or pull-down resistor to GPIO pin

Link to this function

write(gpio, value) View Source
write(reference(), value()) :: :ok

Set the value of a pin. The pin should be configured to an output for this to work.