Giter VIP home page Giter VIP logo

gpio-erlang's Introduction

gpio-erlang

Goals

  • Provide GPIO controller from Erlang/OTP Application.

CAUTION

Now, gpio-erlang supported RaspberryPi only, I will support other devices, that running general GNU/Linux operating system.

Getting Started

Log in your RaspberryPi and fetch the latest version of gpio-erlang using git.

$ git clone https://github.com/hiroeorz/gpio-erlang.git
$ cd gpio-erlang
$ make

Or add "deps" line to your app's rebar.conf.

{gpio, ".*", {git, "https://github.com/hiroeorz/gpio-erlang.git",
   {branch, "master"}}},

and get deps

$ ./rebar get-deps

Running

check default setting of gpio.

In default setting, gpio 25,27 is output pin, other is input pin.

You can change pin setting by modifing above file, if you need.

Start application.

You must run gpio-erlang as root. Because gpio-erlang access to /dev/mem. /dev/mem is allowed writable access from root only.

$ sudo ./start-dev

or start erlang mode as root

$ sudo erl -pa ebin deps/*/ebin -boot start_sasl -sname gpio -setcookie gpio

and start gpio in erl shell.

1> application:start(gpio).

General Purpose I/O

Read gpio value

1> gpio_pin:read(18).
0

Write value to gpio

1> gpio_pin:write(25, 1).
ok
3> gpio_pin:write(25, 0).
ok

Change Pin mode

1> gpio_pin:set_pin_mode(18, out).
ok
2> gpio_pin:set_pin_mode(25, in).
ok

Pullup or pulldown

1> gpio_pin:pullup(18).
ok
2> gpio_pin:pulldown(18).
ok
3> gpio_pin:pullnone(18).
ok

Set interrupt

1> gpio_pin:set_int(18, rising).
ok
2> gpio_pin:set_int(18, falling).
ok
3> gpio_pin:set_int(18, both).
ok
4> gpio_pin:set_int(18, none).
ok

Get active low

1> gpio_pin:get_active_low(4).
0

Set active low

1> gpio_pin:set_active_low(25, 1).

example:

1> gpio_pin:write(25, 1).
ok
2> gpio_pin:read(25).
1
3> gpio_pin:set_active_low(25, 1).
ok
2> gpio_pin:read(25).
0

Add event handler of gpio pin

1> gpio_pin_event:add_event_handler(sample_module, []).
ok
  • First argument is module name.
  • Second argument is arguments of sample_module:init/1.

The sample_module is event handler befavior of gen_event. If gpio18 set interrupt rising and pin status changed 0 to 1 , called event handler.

This is sample event handler. gpio_pin_event_logger.erl

gpio-erlang's People

Contributors

hiroeorz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gusbremri

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.