Git Product home page Git Product logo

arduino-erlang's Introduction

arduino-erlang

Goals

  • Provide Arduino controller from Erlang/OTP Application.

Getting Started

Fetch the latest version of arduino-erlang using git.

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

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

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

and get deps

$ ./rebar get-deps

Running

You can read write Arduino I/O throuh the Firmata protocol. You need to send sketch 'Standard Firmata' to your Arduino or implementation Firmata Protocol your own, before start up the arduino-erlang.

In sample setting, gpio 0,1,2,3,4,5,6,7 is digital input mode, 8, 9 is digital output mode, 10,11 is pwm, 12,13 is servo.

Start Erlang/OTP node.

$ erl  -boot start_sasl -pa ebin deps/*/ebin
1> application:load(arduino).
2> arduino_sup:start_link().

When application started, receive analog values (pin 0 - 5) every 290msec, and When digital status changed, you receive digital change report like:

digital changed(port:0): [1,1,1,0,1,1,1,1]

arduino_sup:start_link/0 is start with sample setting, If you want to start supervisor with your setting, you can start supervisor with your own setting like:

Config = [{speed, 57600},
          {device, "/dev/ttyACM0"},
          {sampling_interval, 290},
          {digital_port_reporting, [1, 0]},
          {digital_port_offset, 1},
          {analog_offset, 0},
          {analog, [0, 1, 2, 3, 4, 5] },
          {digital, [
                     { 0, in, [{pull, up} ]},
                     { 1, in, [{pull, up} ]},
                     { 2, in, [{pull, up} ]},
                     { 3, in, [{pull, up} ]},
                     { 4, in, [{pull, up} ]},
                     { 5, in, [{pull, up} ]},
                     { 6, in, [{pull, up} ]},
                     { 7, in, [{pull, up} ]},
                     { 8, out},
                     { 9, out},
                     {10, pwm},
                     {11, pwm},
                     {12, servo},
                     {13, servo}
                    ]
          }
         ],

EventHandlers = [ {your_handler, []} ],

arduino_sup:start_link(Config, EventHandlers).

Get all digital state.

1> arduino:all_digital()
[1,1,0,0,0,0,0,1]

Get all analog value.

1> arduino:all_analog().
[343, 211, 375, 111, 0, 343]

Write digital state.

PortNO is unit number of every 8 bit digital status.

1> arduino:digital_write(0, [1,1,1,1,1,1,1,1]).
ok

Add event handler of arduino

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

The sample_event_handler is event handler befavior of gen_event. sample_event_handler.erl

arduino-erlang's People

Contributors

hiroeorz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.