Giter VIP home page Giter VIP logo

gpio's Introduction

πGPIO

A simple, pure erlang implementation of a module for Raspberry Pi's General Purpose Input/Output (GPIO), using the standard Linux kernel interface for user-space, sysfs, available at /sys/class/gpio/.

This module was created to try robotics on raspberry Pi using erlang and have not tests, error checking or fancy outputs. It was created for my own use and I'm releasing as it may be useful for someone.
I hope you enjoy!

Requirements

  • Raspbian GNU/Linux;
  • erlang 17+, apt-get install erlang solve it;
  • root, to access "/sys/class/gpio/" files.
  • rebar, to speed things up (wget https://raw.github.com/wiki/rebar/rebar/rebar && chmod u+x rebar)

Usage

on projects

  • add to dependencies of your rebar.config:
{deps, [
    {gpio, "", {git, "git://github.com/paoloo/gpio.git"}},
    ... % other dependencies goes here
]}.
  • then just compile:
$ rebar compile

on REPL

$ sudo erl
Erlang/OTP 17 [erts-6.2] [source] [async-threads:10] [kernel-poll:false]

Eshell V6.2  (abort with ^G)
1> c(gpio).
{ok,gpio}
2> L0 = gpio:init(23, out).
<0.43.0>
3> L1 = gpio:init(22, in).
<0.48.0>
4> gpio:write(L0, 1).
ok
5> gpio:read(L1).
"1"

Documentation

  • init(Pin, Direction) Initialize a pin as output or input, according to Direction(an atom). It returns a Reference to Pin.
  • init(Pin) A shortcut to initialize pin as output. It, also, returns a Reference to Pin.
  • stop(Ref) Stop using and release th pin referenced as Ref. It returns an atom, ok.
  • write(Ref, Val) Writes Val, 1 or 0, into the pin initialized and referenced as Ref.
  • read(Ref) Reads a value(1 or 0) from pin referenced as Ref and returns it.

For the official erlang-style documentation, run:

$ erl -noshell -run edoc_run application 'gpio' '"."' '[]'

Tested on

  • Erlang/OTP 17 erts-6.2 in GNU/Linux Raspian 8.0 (jessie) kernel 4.1.19+ armv61 on Raspberry B+
  • Erlang R15B01 erts-5.9.1 in GNU/Linux Raspian 7 (wheezy) kernel 4.1.13+ armv6l on Raspberry B.

License

MIT License © 2015-2016 Paolo Oliveira.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.