pi_piper 2.0.beta.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +10 -0
  5. data/Gemfile +3 -3
  6. data/Gemfile.lock +39 -26
  7. data/LICENCE.md +23 -0
  8. data/README.md +53 -16
  9. data/Rakefile +4 -22
  10. data/examples/2_bit_counter/2_bit_counter.rb +21 -0
  11. data/examples/7-segment/7-segment.rb +37 -0
  12. data/examples/dsl_switch/dsl_switch.rb +15 -0
  13. data/examples/elro/README.md +75 -0
  14. data/examples/elro/docs/elro-dips.jpg +0 -0
  15. data/examples/elro/docs/elro-switch.jpg +0 -0
  16. data/examples/elro/docs/setup.jpg +0 -0
  17. data/examples/elro/docs/wireplan.jpg +0 -0
  18. data/examples/elro/docs/wrl10534.jpg +0 -0
  19. data/examples/elro/elro.rb +15 -0
  20. data/examples/elro/lib/elro_switch.rb +51 -0
  21. data/examples/elro/lib/elro_util.rb +64 -0
  22. data/examples/elro/spec/elro_spec.rb +35 -0
  23. data/examples/elro/spec/elro_util_spec.rb +51 -0
  24. data/examples/elro/spec/spec_helper.rb +6 -0
  25. data/examples/mcp3008/circuit.png +0 -0
  26. data/examples/mcp3008/mcp3008.rb +55 -0
  27. data/examples/mcp3008_spi/mcp3008_spi.rb +24 -0
  28. data/examples/morse_code/circuit.png +0 -0
  29. data/examples/morse_code/morse_code.rb +49 -0
  30. data/examples/simple_switch/circuit.png +0 -0
  31. data/examples/simple_switch/simple_switch.rb +10 -0
  32. data/lib/pi_piper.rb +5 -3
  33. data/lib/pi_piper/bcm2835.rb +84 -14
  34. data/lib/pi_piper/i2c.rb +0 -1
  35. data/lib/pi_piper/libbcm2835.so +0 -0
  36. data/lib/pi_piper/pin.rb +102 -63
  37. data/lib/pi_piper/pin_error.rb +3 -0
  38. data/lib/pi_piper/pin_values.rb +35 -0
  39. data/lib/pi_piper/platform.rb +5 -5
  40. data/lib/pi_piper/pwm.rb +95 -0
  41. data/lib/pi_piper/spi.rb +30 -45
  42. data/lib/pi_piper/stub_driver.rb +124 -0
  43. data/lib/pi_piper/version.rb +3 -0
  44. data/pi_piper.gemspec +24 -29
  45. data/spec/bcm2835_spec.rb +132 -0
  46. data/spec/i2c_spec.rb +62 -0
  47. data/spec/pin_spec.rb +140 -0
  48. data/spec/pwm_spec.rb +83 -0
  49. data/spec/spec_helper.rb +7 -0
  50. data/spec/spi_spec.rb +38 -0
  51. data/spec/stub_driver_spec.rb +140 -0
  52. metadata +100 -26
  53. data/Manifest +0 -14
  54. data/lib/pi_piper/libbcm2835.img +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4db33bd67174aa5889959cf3eddcb2e8b7a6ac7e
4
- data.tar.gz: 2a9d53cc16b42c4642f99f15cfaa5600a990cd96
3
+ metadata.gz: ffd03a04567c42e342dab56e8e0630f39c6bf210
4
+ data.tar.gz: f15579a5bf7b6de3b764046b69a6fbf879c64b7e
5
5
  SHA512:
6
- metadata.gz: 33caeb1cc9c76871be9c7ea6c49bf2f738eff563bac9bc41bbb5febfbaeb6161a1bb3740cfa15b673f92da2b299a601a332fbd717481706fe6e2534a23d0987c
7
- data.tar.gz: 3feece4a4633c52ad6ea15c6acbfd596cdc2ab1ee5c558002c2e934682f985a73419e2d9a861387a25a142438134d9b06386d1a9f724f87f824d6cdff8cb9943
6
+ metadata.gz: 64ac8f84c2c77027d832e1654af96a09da38c373162b94aa289448f2904e0683e889cf1712906297f7d518b8cfa5bf56edd68f54698bd226f9e0a2c11d9e1dc5
7
+ data.tar.gz: 61049ba1ab09545ac764980170d3c3e154b1127cfa5a23a1b688a60fcf294f9f2429da5a36ecd4583024674f9a26b1e237f81fddcf7d8e73e11b4fe58c202a99
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.swp
3
+ *.gem
4
+ coverage/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.2
7
+
8
+ before_install:
9
+ - gem install bundler
10
+ - gem update
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'echoe'
4
3
  gem 'rake'
5
4
  gem 'ffi'
6
- gem 'rspec'
7
- gem "eventmachine", "~> 1.0.3"
5
+ gem "eventmachine", "~> 1.0.9"
6
+
7
+ gemspec
@@ -1,37 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pi_piper (1.9.9)
5
+ eventmachine (= 1.0.9)
6
+ ffi
7
+
1
8
  GEM
2
9
  remote: https://rubygems.org/
3
10
  specs:
4
- allison (2.0.3)
5
11
  diff-lcs (1.2.4)
6
- echoe (4.6.3)
7
- allison (>= 2.0.3)
8
- gemcutter (>= 0.7.0)
9
- rake (>= 0.9.2)
10
- rdoc (>= 3.6.1)
11
- rubyforge (>= 2.0.4)
12
- eventmachine (1.0.3)
13
- ffi (1.4.0)
14
- gemcutter (0.7.1)
15
- json_pure (1.7.7)
16
- rake (10.0.3)
17
- rdoc (4.0.0)
18
- rspec (2.14.1)
19
- rspec-core (~> 2.14.0)
20
- rspec-expectations (~> 2.14.0)
21
- rspec-mocks (~> 2.14.0)
22
- rspec-core (2.14.5)
23
- rspec-expectations (2.14.2)
24
- diff-lcs (>= 1.1.3, < 2.0)
25
- rspec-mocks (2.14.3)
26
- rubyforge (2.0.4)
27
- json_pure (>= 1.1.7)
12
+ eventmachine (1.0.9)
13
+ ffi (1.9.0)
14
+ metaclass (0.0.1)
15
+ mocha (0.14.0)
16
+ metaclass (~> 0.0.1)
17
+ multi_json (1.8.2)
18
+ rake (10.1.0)
19
+ rspec (3.4.0)
20
+ rspec-core (~> 3.4.0)
21
+ rspec-expectations (~> 3.4.0)
22
+ rspec-mocks (~> 3.4.0)
23
+ rspec-core (3.4.1)
24
+ rspec-support (~> 3.4.0)
25
+ rspec-expectations (3.4.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.4.0)
28
+ rspec-mocks (3.4.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.4.0)
31
+ rspec-support (3.4.1)
32
+ simplecov (0.7.1)
33
+ multi_json (~> 1.0)
34
+ simplecov-html (~> 0.7.1)
35
+ simplecov-html (0.7.1)
28
36
 
29
37
  PLATFORMS
30
38
  ruby
31
39
 
32
40
  DEPENDENCIES
33
- echoe
34
- eventmachine (~> 1.0.3)
41
+ eventmachine (~> 1.0.9)
35
42
  ffi
43
+ mocha
44
+ pi_piper!
36
45
  rake
37
- rspec
46
+ rspec (~> 3.0)
47
+ simplecov
48
+
49
+ BUNDLED WITH
50
+ 1.11.2
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013-2016, Jason Whitehorn, Zshawn Syed and contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/jwhitehorn/pi_piper.png)](https://travis-ci.org/jwhitehorn/pi_piper)
4
4
 
5
- Pi Piper brings event driven programming to the Raspberry Pi's GPIO pins. Pi Piper works with all revisions of the Raspberry Pi,
5
+ Pi Piper brings event driven programming to the Raspberry Pi's GPIO pins. Pi Piper works with all revisions of the Raspberry Pi,
6
6
  and has been tested with Ruby 1.9.3 & 2.0 under both [Raspbian "wheezy"](http://www.raspberrypi.org/downloads) and [Occidentalis v0.2](http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/occidentalis-v0-dot-2).
7
7
 
8
8
  To get started:
9
9
 
10
10
  If you do not already have Ruby installed, first you'll need to:
11
-
12
- sudo apt-get install ruby ruby1.9.1-dev
13
-
11
+
12
+ sudo apt-get install ruby ruby1.9.1-dev libssl-dev
13
+
14
14
  Despite one of the packages being titled "ruby1.9.1-dev", the above command will install Ruby 1.9.3 (as of January 2013) and the Ruby dev tools.
15
15
 
16
16
  To install Pi Piper:
@@ -40,7 +40,7 @@ PiPiper.wait
40
40
 
41
41
  Your block will be called when a change to the pin's state is detected.
42
42
 
43
- When using pins as input, you can use internal resistors to pull the pin
43
+ When using pins as input, you can use internal resistors to pull the pin
44
44
  up or pull down. This is important if you use open-collector sensors
45
45
  which have floating output in some states.
46
46
 
@@ -51,7 +51,7 @@ You can set resistors when creating a pin passing a :pull parameter
51
51
  pin = PiPiper::Pin.new(:pin => 17, :direction => :in, :pull => :up)
52
52
  ```
53
53
 
54
- This way, the pin will always return 'on' if it is unconnected or of the
54
+ This way, the pin will always return 'on' if it is unconnected or if the
55
55
  sensor has an open collector output.
56
56
 
57
57
  You can later alter the pulling resistors using PiPiper#pull!
@@ -65,15 +65,44 @@ sleep 1
65
65
  pin.off
66
66
  ```
67
67
 
68
+ _please note, in the above context "pin" refers to the GPIO number of the Raspberry Pi._
69
+
68
70
  ### SPI
69
- Starting with version 1.2, Pi Piper offers SPI support.
71
+ Starting with version 1.2, Pi Piper offers SPI support.
70
72
 
71
73
  ```ruby
72
- PiPiper::Spi.begin do
73
- puts write [0x01, 0x80, 0x00]
74
+ PiPiper::Spi.begin do
75
+ puts write [0x01, 0x80, 0x00]
74
76
  end
75
77
  ```
76
78
 
79
+ If you are using an operating system that supports `/dev/spidev0.0` like the [adafruit
80
+ distro][adafruit-linux] you can also write to the spi using `PiPiper::Spi.spidev_out`
81
+
82
+ ```ruby
83
+ # Example writing red, green, blue to a string of WS2801 pixels
84
+ PiPiper::Spi.spidev_out([255,0,0,0,255,0,0,0,255])
85
+ ```
86
+ [adafruit-linux]:http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/overview
87
+
88
+ ### Pulse Width Modulation (PWM)
89
+
90
+ what is it !? https://en.wikipedia.org/wiki/Pulse-width_modulation
91
+
92
+ PiPiper allow to use the hardware PWM channel of the bcm2835.....
93
+ value should be between 0 and 1, clock between 0 and 19.2MHz, mode blaanced or markspace and range something greater than 0.
94
+ Supported pin are : 12, 13, 18, 19, 40, 41, 45, 52, 53
95
+ but only 18 is on the header..
96
+
97
+ ```ruby
98
+ pwm = PiPiper::Pwm.new pin: 18 #, range: 1024, clock: 19.2.megahertz, mode: :markspace, value: 1, start: false
99
+ pwm.value= 0.5
100
+ pwm.off # works with stop
101
+ pwm.on # aliased start
102
+ ```
103
+
104
+ apparently the clock is rounded to the next 2^n divider of 19.2MHz
105
+
77
106
  ## Documentation
78
107
 
79
108
  API documentation for Pi Piper can be found at [rdoc.info](http://rdoc.info/github/jwhitehorn/pi_piper/frames/).
@@ -87,19 +116,27 @@ Looking for more examples/sample code for Pi Piper? Then check out the following
87
116
  * [Project 3: 2-bit counter](https://github.com/jwhitehorn/pi_piper/wiki/Project-3:-2-bit-counter)
88
117
  * [Project 4: MCP3008](https://github.com/jwhitehorn/pi_piper/wiki/Project-4:-MCP3008)
89
118
 
90
- ## License
119
+ ## Under the hood
91
120
 
92
- Copyright (c) 2013, [Jason Whitehorn](https://github.com/jwhitehorn)
93
- All rights reserved.
121
+ PiPiper use the libbcm2835 library from Mike McCauley at airspayce. (distributed with Open Source Licensing GPL V2)
94
122
 
95
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
123
+ http://www.airspayce.com/mikem/bcm2835/index.html
96
124
 
97
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
98
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
125
+ if you want to upgrade or downgrade the library for compatibility reason, get it and make it a shared object library :
99
126
 
100
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
127
+ ```script
128
+ wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.49.tar.gz
129
+ tar zxvf bcm2835-1.49.tar.gz && cd bcm2835-1.49
130
+ ./configure && make
131
+ sudo make check
132
+ sudo make install
133
+ cd src && cc -shared bcm2835.o -o libbcm2835.so
134
+ cp libbcm2835.so ~/pi_piper/lib/pi_piper
135
+ ```
101
136
 
137
+ ## License
102
138
 
139
+ Distributed in accordance with the BSD licence, see LICENCE.md file.
103
140
 
104
141
  ***
105
142
  <img src="http://www.raspberrypi.org/wp-content/uploads/2012/03/Raspi_Colour_R.png" width="90" />
data/Rakefile CHANGED
@@ -1,24 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
- require 'rake/testtask'
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
5
3
 
6
- #rake manifest
7
- #rake build_gemspec
8
- #gem build pi_piper.gemspec
9
- #gem push xxx.gem
4
+ RSpec::Core::RakeTask.new(:spec)
10
5
 
11
- Echoe.new('pi_piper', '2.0.beta.4') do |p|
12
- p.description = "Event driven Raspberry Pi GPIO library"
13
- p.url = "http://github.com/jwhitehorn/pi_piper"
14
- p.author = "Jason Whitehorn"
15
- p.email = "jason.whitehorn@gmail.com"
16
- p.ignore_pattern = ["examples/**/*", "spec/**/*"]
17
- p.dependencies = ['ffi', 'eventmachine 1.0.3']
18
- end
19
-
20
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
21
-
22
- Rake::TestTask.new do |t|
23
- t.pattern = 'spec/**/*_spec.rb'
24
- end
6
+ task :default => :spec
@@ -0,0 +1,21 @@
1
+ require 'pi_piper'
2
+
3
+ puts "Press the switch to get started"
4
+ pin17 = PiPiper::Pin.new(:pin => 17, :direction => :out)
5
+ pin27 = PiPiper::Pin.new(:pin => 27, :direction => :out)
6
+
7
+ pin17.off
8
+ pin27.off
9
+
10
+ sum = 0
11
+
12
+ PiPiper.watch :pin => 22, :trigger => :rising do |pin|
13
+ sum += 1
14
+ puts sum
15
+
16
+ # get single bits of sum
17
+ pin17.update_value(sum & 0b01 == 0b01)
18
+ pin27.update_value(sum & 0b10 == 0b10)
19
+ end
20
+
21
+ PiPiper.wait
@@ -0,0 +1,37 @@
1
+ require 'pi_piper'
2
+
3
+ s1 = PiPiper::Pin.new(:direction => :out, :pin => 27)
4
+ s2 = PiPiper::Pin.new(:direction => :out, :pin => 24)
5
+ s3 = PiPiper::Pin.new(:direction => :out, :pin => 23)
6
+ s4 = PiPiper::Pin.new(:direction => :out, :pin => 25)
7
+ s5 = PiPiper::Pin.new(:direction => :out, :pin => 18)
8
+ s6 = PiPiper::Pin.new(:direction => :out, :pin => 22)
9
+ s7 = PiPiper::Pin.new(:direction => :out, :pin => 17)
10
+
11
+
12
+ pins = [s1, s2, s3, s4, s5, s6, s7]
13
+
14
+ zero = Proc.new { s1.on; s2.on; s3.on; s4.on; s5.on; s6.on; s7.off; }
15
+ one = Proc.new { s1.off; s2.off; s3.on; s4.on; s5.off; s6.off; s7.off; }
16
+ two = Proc.new { s1.off; s2.on; s3.on; s4.off; s5.on; s6.on; s7.on; }
17
+ three = Proc.new { s1.off; s2.on; s3.on; s4.on; s5.on; s6.off; s7.on; }
18
+ four = Proc.new { s1.on; s2.off; s3.on; s4.on;; s5.off; s6.off; s7.on; }
19
+ five = Proc.new { s1.on; s2.on; s3.off; s4.on; s5.on; s6.off; s7.on; }
20
+ six = Proc.new { s1.on; s2.on; s3.off; s4.on; s5.on; s6.on; s7.on; }
21
+ seven = Proc.new { s1.off; s2.on; s3.on; s4.on; s5.off; s6.off; s7.off; }
22
+ eight = Proc.new { s1.on; s2.on; s3.on; s4.on; s5.on; s6.on; s7.on; }
23
+ nine = Proc.new { s1.on; s2.on; s3.on; s4.on; s5.off; s6.off; s7.on; }
24
+
25
+ numbers = [zero, one, two, three, four, five, six, seven, eight, nine]
26
+
27
+ pins.each { |p| p.off }
28
+
29
+ PiPiper.watch :pin => 4, :trigger => :rising do
30
+ (0..250).each do
31
+ pins.each { |p| p.update_value(Random.rand(2) == 1) }
32
+ end
33
+ number = Random.rand(10)
34
+ numbers[number].call
35
+ end
36
+
37
+ PiPiper.wait
@@ -0,0 +1,15 @@
1
+ require 'pi_piper'
2
+ include PiPiper
3
+
4
+ puts "Press the switch to get started"
5
+
6
+ watch :pin => 17, :invert => true do
7
+ puts "Pin changed from #{last_value} to #{value}"
8
+ end
9
+
10
+ after :pin => 17, :goes => :high do
11
+ puts "ouch!"
12
+ end
13
+
14
+ PiPiper.wait
15
+
@@ -0,0 +1,75 @@
1
+ # Project: Elro-Switches
2
+
3
+ In this sample project, we want to be able to use our RaspberryPi to switch the lights on and off.
4
+ We will be using
5
+
6
+ * a Elro-RF-Remote-Switch, which operates at 433 MHz
7
+ * a little RF-Link-Transmitter, to send the signals
8
+ * some code that knows how to send the correct signals
9
+
10
+ ## Elro Switch
11
+
12
+ First we need a RF-remote-switch. Here in Europe Elro sells a lot of [these things](https://www.google.de/search?q=elro+ab440). We will be using a switch from the ab440-series, since they have dip-switches on the back, which will be used to specify a `key` and a `device` (think of it as IDs to select which lights to switch). Both will be parameters to our script.
13
+
14
+ ![elro switch](docs/elro-switch.jpg)
15
+ ![elro dips](docs/elro-dips.jpg)
16
+
17
+ This switch will be connected to an outlet and to a lamp (or what ever you want to switch).
18
+
19
+ ![elro dips](docs/setup.jpg)
20
+
21
+
22
+ ## RF Link Transmitter
23
+
24
+ To send signals from our RaspberryPi to the remote switch, we will be using a RF Link Transmitter that goes by the name `WRL-10534`. These can be [purchased](https://www.google.de/search?q=wrl10534) for little money.
25
+
26
+ ![wrl10534](docs/wrl10534.jpg)
27
+
28
+ This little guy sports four pins: `GND`, `Data in`, `Vcc` and `ANT`.
29
+
30
+ ## Wire Plan
31
+
32
+ Wiring up the rf transmitter is no big deal.
33
+
34
+ ![wire plan](docs/wireplan.jpg)
35
+
36
+
37
+ ## Code
38
+
39
+ To send the signals we will be using the great pi-piper interface to the raspberry's GPIO.
40
+
41
+ Since the elro-switches are triggered through quite complex sequences (*1280 signals for one switch*) we will be using a little library called `ElroSwitch` that calculates and sends these sequences via a pi-piper pin.
42
+
43
+ ```ruby
44
+ device = [1,0,0,0,0] # according to the dip-switches
45
+ key = [0,0,0,0,1] # according to the dip-switches
46
+
47
+ pin = PiPiper::Pin.new(:pin => 17, :direction => :out)
48
+ elro = ElroSwitch.new(device, key, pin)
49
+
50
+ elro.switch(true) # switch on
51
+ elro.switch(false) # switch off
52
+ ```
53
+
54
+ ## Warning
55
+
56
+ The Raspberry is not build to be the fastest hardware in the world.
57
+ Ruby (MRI) is not fastest programming language (but still the best).
58
+ The Elro Switch expects the 1280 signals for each switch-event to be
59
+ transmitted with a frequency of 300 microseconds (but as I have observed
60
+ will still operate while using frequencies from ≈100 to ≈600 microseconds
61
+ per signal).
62
+
63
+ This implementation (using PiPiper) reaches a frequency of around
64
+ 500 microseconds on an RaspberryPi without any wait or sleep.
65
+
66
+ Other implementation (in python or C) need to time their signals to
67
+ not be too fast.
68
+
69
+ Keep that in mind, if this code will run on faster hardware or faster Rubies.
70
+
71
+ ## Credits
72
+
73
+ The `ElroSwitch` library is mostly a (heavily refactored) port from [this python script](http://pastebin.com/aRipYrZ6) by Heiko H.,
74
+ which is a port from a [C++ snippet](http://www.jer00n.nl/433send.cpp) written by J. Lukas,
75
+ and influenced by this [Arduino source](http://gathering.tweakers.net/forum/view_message/34919677) code written by Piepersnijder.