• Stars
    star
    208
  • Rank 189,015 (Top 4 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created almost 12 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Erlang Actor Library for Embedded -- An embedded framework from Erlang Solutions

Erlang/ALE -- Erlang Actor Library for Embedded

Build Status

Erlang/ALE provides high level abstractions for interfacing to hardware peripherals through I2C, SPI, and GPIOs on embedded platforms.

Getting started

Erlang/ALE supports both rebar3 and erlang.mk build tools. If you're natively compiling Erlang/ALE, everything should work like any other Erlang library. Normally, you would include erlang_ale as a dependency in your rebar.config or Makefile file. If you just want to try it out, do the following:

git clone https://github.com/esl/erlang_ale.git

Steps for rebar3 build tool:
	rebar3 compile
	rebar3 shell

Steps for erlang.mk build tool:
	make
	make shell

If you're cross-compiling, you'll need to setup your environment so that the right C compiler is called. See the Makefile for the variables that will need to be overridden.

Documentation

It is possible generate HTML documentation from the self documented source.

cd erlang_ale
make docs

The HTML files can be seen in the erlang_ale/doc folder. Open the index.html file, and read.

Examples

The following examples were tested on a Raspberry Pi that was connected to an Erlang Embedded Demo Board. There's nothing special about either the demo board or the Raspberry Pi, so these should work similarly on other embedded Linux platforms.

GPIO

A GPIO is just a wire that you can use as an input or an output. It can only be one of two values, 0 or 1. A 1 corresponds to a logic high voltage like 3.3 V and a 0 corresponds to 0 V. The actual voltage depends on the hardware.

Here's an example setup:

GPIO schematic

To turn on the LED that's connected to the net labelled PI_GPIO18, you can run the following:

1> {ok, Gpio18} = gpio:start_link(18, output).
{ok, <0.96.0>}

2> gpio:write(Gpio18, 1).
ok

Input works similarly:

3> {ok, Gpio17} = gpio:start_link(17, input).
{ok, <0.97.0>}

4> gpio:read(Gpio17).
0

%% Push the button down

5> gpio:read(Gpio17).
1

If you'd like to get a message when the button is pressed or released, register a process using the register_int/1 or register_int/2. Then enable interrupts:

6> gpio:register_int(Gpio17).
ok

7> gpio:set_int(Gpio17, both).
ok

%% Press the button a few times

8> flush().
{gpio_interrupt, 17, rising}
{gpio_interrupt, 17, falling}
{gpio_interrupt, 17, rising}
{gpio_interrupt, 17, falling}
ok

SPI

A SPI bus is a common multi-wire bus used to connect components on a circuit board. A clock line drives the timing of sending bits between components. Bits on the MOSI line go from the master (usually the processor running Linux) to the slave, and bits on the MISO line go the other direction. Bits transfer both directions simultaneously. However, much of the time, the protocol used across the SPI bus has a request followed by a response and in these cases, bits going the "wrong" direction are ignored.

The following shows an example ADC that reads from either a temperature sensor on CH0 or a potentiometer on CH1.

SPI schematic

The protocol for talking to the ADC is described in the MCP3203 Datasheet. Sending a 0x64 first reads the temperature and sending a 0x74 reads the potentiometer.

NOTE: Before you try using SPI, make sure that the proper drivers are loaded. For example, on Raspian be sure to run raspi-config to enable SPI.

1> {ok, MySpi} = spi:start_link("spidev0.0", []).
{ok, <0.124.0>}

%% Read the potentiometer

%% Use binary pattern matching to pull out the ADC counts (low 12 bits)
2> <<_:4, Counts:12>> = spi:transfer(MySpi, <<16#74, 16#00>>).
<<1, 197>>

3> Counts.
453

%% Convert counts to volts (1023 = 3.3 V)
4> Volts = Counts / 1023 * 3.3.
1.461290322580645

I2C

An I2C bus is similar to a SPI bus in function, but uses one less wire. It supports addressing hardware components and bidirectional use of the data line. Be aware that I2C requires some care when hooking up such as making sure to attach the proper pullup resisters to SCL and SDA. If you using a Raspberry Pi, see the clock-stretching bug.

The following shows a bus IO expander connected via I2C to the processor.

I2C schematic

The protocol for talking to the IO expander is described in the MCP23008 Datasheet. Here's a simple example of using it.

NOTE: Before trying the example below, make sure that I2C support has been enabled and that the i2c-dev module has been inserted.

%% On the Raspberry Pi, the IO expander is connected to I2C bus 1 (i2c-1).
%% Its 7-bit address is 0x20. (see datasheet)
1> {ok, IoExpander} = i2c:start_link("i2c-1", 16#20).
{ok, <0.102.0>}

%% By default, all 8 GPIOs are set to inputs. Set the 4 high bits to outputs
%% so that we can toggle the LEDs. (Write 0x0f to register 0x00)
2> i2c:write(IoExpander, <<16#00, 16#0f>>).
ok

%% Turn on the LED attached to bit 4 on the expander. (Write 0x10 to register
%% 0x09)
3> i2c:write(IoExpander, <<16#09, 16#10>>).
ok

%% Read all 11 of the expander's registers to see that the bit 0 switch is
%% the only one on and that the bit 4 LED is on.
4> i2c:write(IoExpander, <<16#00>>).  % Set the next register to be read to 0
ok

5> i2c:read(IoExpander, 11).
<<15, 0, 0, 0, 0, 0, 0, 0, 0, 17, 16>>

%% The 17 in register 9 says that bits 0 and bit 4 are high
%% We could have just read register 9.

6> i2c:write(IoExpander, <<9>>).
ok

7> i2c:read(IoExpander, 1).
<<17>>

%% A simpler way to write the register and read its contents.
8> i2c:write_read(IoExpander, <<9>>, 1).
<<17>>

FAQ

  1. Where did PWM support go?

The original Erlang/ALE implementation supported PWM on the Raspberry Pi. The implementation was platform-specific and not maintained. After a year of bit rot, it was removed.

More Repositories

1

MongooseIM

MongooseIM is Erlang Solutions' robust, scalable and efficient XMPP server, aimed at large installations. Specifically designed for enterprise purposes, it is fault-tolerant and can utilise the resources of multiple clustered machines.
Erlang
1,660
star
2

gradient

Gradient is a static typechecker for Elixir
Elixir
431
star
3

erlang-handbook

A concise reference for Erlang
TeX
296
star
4

escalus

An XMPP client library in Erlang for conveniently testing XMPP servers
Erlang
127
star
5

lhttpc

lhttpc is a lightweight HTTP/1.1 client implemented in Erlang.
Erlang
127
star
6

MongooseICE

STUN/TURN server written in Elixir
Elixir
118
star
7

MongoosePush

MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Elixir
108
star
8

elarm

Erlang
102
star
9

amoc

A load-testing framework for running massively parallel tests
Erlang
96
star
10

ex_rabbit_pool

RabbitMQ connection pooling in Elixir
Elixir
73
star
11

erlang-web

Erlang
50
star
12

parcv

Computer vision demo running on the parallella board
C
38
star
13

mangosta-android

MongooseIM client for Android
Java
31
star
14

mangosta-ios

MongooseIM client for iOS
Swift
30
star
15

sparrow

iOS and Android push notifications for Elixir.
Elixir
30
star
16

mongooseim-docker

Shell
27
star
17

segmented_cache

Modern, performant, and extensible, Erlang in-memory cache
Erlang
27
star
18

ex_docker_build

docker build with support for bind mounts at build time via Docker Remote API
Elixir
25
star
19

ejabberd_tests

Erlang
23
star
20

flex

A simple Elixir InfluxDB client.
Elixir
20
star
21

erl_fuzzy_match

Erlang Fuzzy String Matcher
Erlang
18
star
22

lager_graylog

Lager is a standard logging tool for Erlang, this project crates lager formatter to output messages in gelf format and lager backend to send messages via UDP.
Erlang
17
star
23

arnold

Time series data forecasting tool made in Elixir using Axon library
Elixir
17
star
24

fast_scram

Fastest SCRAM's implementation for Erlang & OTP, aiming at performance and statelessness for ease-of-use
Erlang
17
star
25

tracerl

Dynamic tracing tests and utilities for Erlang/OTP
Erlang
17
star
26

cets

A library to synchronise records from the ETS tables between nodes
Erlang
15
star
27

jerboa

STUN/TURN encoder, decoder and client library in Elixir
Elixir
14
star
28

MongooseHelm

Helm chart definitions for the Mongoose stack (MongooseIM, MongoosePush)
Erlang
11
star
29

rebar3_codecov

A rebar3 plugin which converts .coverdata files to JSON format, compatible with
Erlang
11
star
30

elibcloud

Erlang wrapper for Libcloud
Erlang
10
star
31

packages

Makefile- and Docker-based build system for ESL's erlang and elixir binary packages.
Python
9
star
32

fast_pbkdf2

Erlang's best pbkdf2 implementation
C
9
star
33

rabbitmq-docker

Dockerfile
8
star
34

usec

Convert anything to microseconds and back.
Erlang
8
star
35

c3card

A workshop at CodeBEAM America 2024 showcasing custom hardware and Erlang-based firmware development using AtomVM.
Erlang
8
star
36

esl-rabbitmq-client

RabbitMQ Client for Erlang, built by ESL
Erlang
7
star
37

amoc-arsenal-xmpp

Erlang
7
star
38

erlang-osx-installer

Erlang Installer & Auto-Updater for macOS
Swift
6
star
39

buildex_api

Elixir
6
star
40

mongoose_jid

Erlang
5
star
41

movim-docker

Dockerfiles for movim application
Shell
5
star
42

jaguar

Elixir
5
star
43

wombat_discovery

Erlang
5
star
44

logger_graylog_backend

Elixir's Logger backend for Graylog
Elixir
5
star
45

opuntia

Opuntia is a basic set of tools for traffic shaping for erlang and elixir. Because if you touch it too fast, it stings you.
Erlang
5
star
46

gradient_macros

Slim Gradient compile-time support
Elixir
4
star
47

chirp_cockroach

Demo project: Chris McCord's Twitter clone with a CockroachDB backend
Elixir
4
star
48

buildex_jobs

Buildex service which receives and processes build instructions
Elixir
4
star
49

throttle

Experimental implementation of a simple throttle
Erlang
4
star
50

wombat-discovery

Plugin for Wombat to automatically add nodes
Elixir
4
star
51

buildex_poller

Buildex service which polls github (others to follow) and triggers builds via RabbitMQ
Elixir
4
star
52

release_poller

Elixir
4
star
53

base16

The last time I hexadecimify Erlang binaries...
Erlang
4
star
54

poc_tensorflow_mushrooms

Elixir
3
star
55

beam_olympics_nerves

Getting Beam Olympics to run on a Raspberry Pi through Nerves. Phoenix leaderboard included.
Erlang
3
star
56

erlang-plts

Pregenerated Dialyzer PLTs for a number of Erlang versions
Python
3
star
57

exometer_report_statsd

Erlang
3
star
58

seta

Work-stealing scheduler
JavaScript
3
star
59

ice_demo

Elixir
3
star
60

loadex

simple small open load generator
Elixir
2
star
61

MongooseDocs

Documentation for MongooseIM, in this repo's gh-pages: https://esl.github.io/MongooseDocs/latest/
HTML
2
star
62

buildex_ui

Buildex service which provides Oauth login and build configuration management
2
star
63

rabbitmq-queue-info

Makefile
2
star
64

gapp

Erlang
2
star
65

ex_github_poller

An elixir application to poll github repositories ... wip
Elixir
2
star
66

helm-chart

Shell
2
star
67

elarm_mailer

SMTP reporting for elarm
Erlang
2
star
68

Mercutio

Erlang
2
star
69

percacdat

Persistent Cached Data structures
Erlang
2
star
70

elixirconf-eu-jekyll

HTML
2
star
71

ice

Erlang
2
star
72

jekyll-codesync-global

jekyll version of codesync-global
SCSS
2
star
73

buildex_common

Modules shared by buildex projects
Elixir
2
star
74

cfg

Erlang
2
star
75

foo-phx-cowboy-2.6

phoenix 1.4 / cowboy-2.6 bootstrap project
Elixir
2
star
76

exometer_report_graphite

Erlang
2
star
77

mongooseim-ct-reports

Autogenerated repository for Common Tests reports. Used by MongooseIM team
JavaScript
2
star
78

bryan_cb_sf_2020_talk

bryan hunt codebeam talk
Makefile
2
star
79

amoc-swarm

Dockerfile
2
star
80

node-with-build-tools

node with build tools pre-installed
Dockerfile
2
star
81

release_tasks

Elixir
2
star
82

graphql-erlang

Erlang
2
star
83

amoc_rest

The generated server code for AMOC REST API
Erlang
2
star
84

elixometer

Elixir
2
star
85

observability

Examples for the Erlang and Elixir Observability tutorial
Erlang
1
star
86

jekyll-codesync-global-2

CSS
1
star
87

erlangusergroup

1
star
88

circleci-mim-results

JavaScript
1
star
89

sappan

Erlang
1
star
90

virtual-elixirconf-eu-jekyll

HTML
1
star
91

tanka-alpine

devops docker image with tanka, jsonnet, and jsonnet-package pre-installed
Dockerfile
1
star
92

ml-hackathon

Python
1
star
93

circleci-kubernetes-deployer

docker image with helm, kubectl, google cloud tools, etc baked in
Dockerfile
1
star
94

code-beam-america

HTML
1
star
95

plantproxy

Elixir
1
star
96

lambdadays-jekyll

convert lambdadays from custom webserver to jekyll
HTML
1
star