Using Erlang on the RaspberryPi to interact with the physical world
-
Upload
brian-chamberlain -
Category
Technology
-
view
4.018 -
download
0
description
Transcript of Using Erlang on the RaspberryPi to interact with the physical world
![Page 1: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/1.jpg)
Have some Erlang on your RaspberryPi
(Using Erlang in embedded linux systems)
Friday, June 21, 13
![Page 2: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/2.jpg)
But first, some context(i.e. Why running Erlang on the
RaspberryPi might be interesting...)
Friday, June 21, 13
![Page 3: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/3.jpg)
nowyears agodecades agoa long time ago
(in a galaxy far, far away...)
The progression
mainframe
desktop
laptop
smartphone
tablet
?
We all are aware of the inevitable progression towards more diverse, smaller, and powerful software enabled devices. It is pretty obvious. In addition to this, it’s clear that devices are designed around certain modes of interactions and interaction duration. However, there is a new space in consumer devices which allows for entirely different ways of interaction (and in some cases no interaction at all).
Friday, June 21, 13
![Page 4: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/4.jpg)
The quantified self/internet of things?
FitBit/Fuel Band
WiThings BodyScale
ScoutAlarm
SmartThings
Pebble Watch
Philips Hue/ Blink(1)
NinjaBlocks
Belkin WeMoSwitch
This new space is based on the idea that devices can be passive observers of human behavior, the environment, or other sources of data. This is the central idea of the quantified self/internet of things. Initially devices are focused around health and activity. There will be an increasing growth in other areas.
Friday, June 21, 13
![Page 5: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/5.jpg)
Games
Information
Environment
Security
Health
The quantified self is part of the “Internet of Things”
There are more and more devices entering the market every month. To date, a large number have been focused on health (e.g. FitBit, Nike Fuel) and security (e.g. ScoutAlarm). Over time these devices will enter other aspects of human activity. Some sense and control the home environment (e.g. Nest), others provide information from internet services (e.g. Philips Hue), and some might be purely for entertainment and a platform for games.
Friday, June 21, 13
![Page 6: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/6.jpg)
In addition to lots of interesting consumer products. There are lots of new and interesting hardware platforms. Almost all run embedded linux.
Friday, June 21, 13
![Page 7: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/7.jpg)
What are people doing with these boards?
Friday, June 21, 13
![Page 8: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/8.jpg)
Friday, June 21, 13
![Page 9: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/9.jpg)
Friday, June 21, 13
![Page 10: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/10.jpg)
Build your own Google Glass perhaps?...
Friday, June 21, 13
![Page 11: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/11.jpg)
Ok, but what does this have to do with Erlang?
Friday, June 21, 13
![Page 12: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/12.jpg)
Small, cheap hardware
Linux
=
Lots of internet connected, linux
powered, small, cheap, embedded devices
+Expensive, big hardware
Erlang
=
A massively scaleable, fault tolerant system
which runs on embedded systems
+
The Internet+
The phone network+
Well, there are some parallels between these “internet of” devices and Erlang
Friday, June 21, 13
![Page 13: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/13.jpg)
What is Erlang?(hint: It’s pronounced “Air-lang” not “Errr-lang”)
Friday, June 21, 13
![Page 14: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/14.jpg)
• Creating and destroying processes is very fast
• Sending messages between processes is very fast
• Processes behave the same way on all operating systems
• We can have very large numbers of processes (1,000’s to 100,000’s)
• Processes share no memory and are completely independent
• The ONLY way for processes to interact is through message passing
Like some languages are object oriented, Erlang is “process oriented”. For example, in Erlang:
Erlang is a general purpose concurrent programming language and runtime system. It is a functional language which has strict evaluation, single assignment, and dynamic typing. Originally designed by Ericsson to support distributed, fault-tolerant, soft-real time, non-stop applications. [from wikipedia]
Friday, June 21, 13
![Page 15: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/15.jpg)
This is a sample of code from the demo portion of this presentation. It defines a module called “net_led” which controls an LED over the local network. Erlang code is composed into modules which expose certain functions via the “export” directive. In this module, I export methods to spawn the LED light process on one machine. Then have a switch function which controls the light via a different process running on a separate machine. In the sample below there are two functions defined, “decouple” and “switch.” These take parameters about the LED light process and then send messages to that process. The “!” is the message send operator.
Full source can be found here: https://gist.github.com/breakpointer/5799847
Friday, June 21, 13
![Page 16: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/16.jpg)
What does Erlang look like?
Friday, June 21, 13
![Page 17: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/17.jpg)
Object Oriented Process Oriented
Ruby Erlang
class Foo
def bar puts “hello!”end
end
Definition
-module(foo).
-export([bar/0]).
bar() -> io:format(‘hello!~n’,[]).
Instantiation >f = Foo.new>f.bar #=> hello!
>foo:bar().hello!>F = spawn(foo, bar, []). hello!<0.34.0>
Simple comparison of Ruby to Erlang
Orientation
Friday, June 21, 13
![Page 18: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/18.jpg)
How does one use Erlang?
Friday, June 21, 13
![Page 19: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/19.jpg)
process processspawn
receive
Erlang VM
process
process
spawn
spaw
n
{messages}
receive
A typical application will use many processes, and message passing for inter-process communications
Friday, June 21, 13
![Page 20: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/20.jpg)
How is Erlang used on the RaspberryPi?
Friday, June 21, 13
![Page 21: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/21.jpg)
The components of the RaspberryPi
Your interface to the world!
Friday, June 21, 13
![Page 22: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/22.jpg)
Friday, June 21, 13
![Page 23: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/23.jpg)
Accessing the GPIO pins through Linux SysFs
OS mapping location of pins:
Exporting a pin for use:
Reading the value of a pin as that pin is toggled high/low:
Friday, June 21, 13
![Page 24: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/24.jpg)
Imagine a product called The Baconator*
How might this system be modeled?
(*patent/trademark/startup pending...)
Friday, June 21, 13
![Page 25: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/25.jpg)
SysFs
Dispenseprocess
{messages}
receive
MakeBacon
process
Buttonprocess{message
s}
receive
GPIO
io:Read
io:Write
The Baconator! A.K.A. the most awesome bacon dispensing machine in the world!
Baconsupervisor Instructions:
Step 1) Push buttonStep 2) Receive bacon Step 3) NomNomNom
software hardware
Friday, June 21, 13
![Page 26: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/26.jpg)
Demo: Erlang powered LED light and “switch”
(Sorry, no bacon will be auto-dispensed tonight)
Friday, June 21, 13
![Page 27: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/27.jpg)
erl shellprocess
switch process
spawnreceive
Erlang VM
erl shellprocess
LED light
process
spawnreceive
Erlang VM{messages}
{messages}Laptop
RaspberryPi
{{
local network
Friday, June 21, 13
![Page 28: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/28.jpg)
Next steps for the Erlang and embedded systems
Friday, June 21, 13
![Page 29: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/29.jpg)
A website to watch for progress on embedded erlang
Friday, June 21, 13
![Page 30: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/30.jpg)
Side Project: Dash-dot-com(a sass-talking web controlled animatronic puppet)
Friday, June 21, 13
![Page 31: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/31.jpg)
How to get Erlang running on the RaspberryPi?(It’s incredibly easy, I swear)
Friday, June 21, 13
![Page 32: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/32.jpg)
deb http://binaries.erlang-solutions.com/debian wheezy contrib
If you have the latest Raspbian distro...
add the package location to /etc/apt/sources.list
add the public key for apt-secure
Install the package
wget -O - http://binaries.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -
sudo apt-get updatesudo apt-get install esl-erlang
From the console, fire up the Erlang REPLerl
Friday, June 21, 13
![Page 33: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/33.jpg)
Resources
Friday, June 21, 13
![Page 34: Using Erlang on the RaspberryPi to interact with the physical world](https://reader033.fdocuments.net/reader033/viewer/2022052321/5552de45b4c905014c8b4c1a/html5/thumbnails/34.jpg)
• http://www.adafruit.com or http://www.sparkfun.com
• http://www.erlang-embedded.com/
• http://www.erlang-solutions.com/section/132/download-erlang-otp
• https://github.com/omerk/erl-hw/
• http://www.infoq.com/interviews/kilic-erlang-embedded
• http://www.erlang-factory.com/upload/presentations/451/Wiger-erlangforembedded.pdf
• http://www.1011ltd.com/web/blog/post/embedded_erlang
Friday, June 21, 13