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.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rspec +3 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +39 -26
- data/LICENCE.md +23 -0
- data/README.md +53 -16
- data/Rakefile +4 -22
- data/examples/2_bit_counter/2_bit_counter.rb +21 -0
- data/examples/7-segment/7-segment.rb +37 -0
- data/examples/dsl_switch/dsl_switch.rb +15 -0
- data/examples/elro/README.md +75 -0
- data/examples/elro/docs/elro-dips.jpg +0 -0
- data/examples/elro/docs/elro-switch.jpg +0 -0
- data/examples/elro/docs/setup.jpg +0 -0
- data/examples/elro/docs/wireplan.jpg +0 -0
- data/examples/elro/docs/wrl10534.jpg +0 -0
- data/examples/elro/elro.rb +15 -0
- data/examples/elro/lib/elro_switch.rb +51 -0
- data/examples/elro/lib/elro_util.rb +64 -0
- data/examples/elro/spec/elro_spec.rb +35 -0
- data/examples/elro/spec/elro_util_spec.rb +51 -0
- data/examples/elro/spec/spec_helper.rb +6 -0
- data/examples/mcp3008/circuit.png +0 -0
- data/examples/mcp3008/mcp3008.rb +55 -0
- data/examples/mcp3008_spi/mcp3008_spi.rb +24 -0
- data/examples/morse_code/circuit.png +0 -0
- data/examples/morse_code/morse_code.rb +49 -0
- data/examples/simple_switch/circuit.png +0 -0
- data/examples/simple_switch/simple_switch.rb +10 -0
- data/lib/pi_piper.rb +5 -3
- data/lib/pi_piper/bcm2835.rb +84 -14
- data/lib/pi_piper/i2c.rb +0 -1
- data/lib/pi_piper/libbcm2835.so +0 -0
- data/lib/pi_piper/pin.rb +102 -63
- data/lib/pi_piper/pin_error.rb +3 -0
- data/lib/pi_piper/pin_values.rb +35 -0
- data/lib/pi_piper/platform.rb +5 -5
- data/lib/pi_piper/pwm.rb +95 -0
- data/lib/pi_piper/spi.rb +30 -45
- data/lib/pi_piper/stub_driver.rb +124 -0
- data/lib/pi_piper/version.rb +3 -0
- data/pi_piper.gemspec +24 -29
- data/spec/bcm2835_spec.rb +132 -0
- data/spec/i2c_spec.rb +62 -0
- data/spec/pin_spec.rb +140 -0
- data/spec/pwm_spec.rb +83 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/spi_spec.rb +38 -0
- data/spec/stub_driver_spec.rb +140 -0
- metadata +100 -26
- data/Manifest +0 -14
- data/lib/pi_piper/libbcm2835.img +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffd03a04567c42e342dab56e8e0630f39c6bf210
|
4
|
+
data.tar.gz: f15579a5bf7b6de3b764046b69a6fbf879c64b7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ac8f84c2c77027d832e1654af96a09da38c373162b94aa289448f2904e0683e889cf1712906297f7d518b8cfa5bf56edd68f54698bd226f9e0a2c11d9e1dc5
|
7
|
+
data.tar.gz: 61049ba1ab09545ac764980170d3c3e154b1127cfa5a23a1b688a60fcf294f9f2429da5a36ecd4583024674f9a26b1e237f81fddcf7d8e73e11b4fe58c202a99
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rspec-
|
22
|
-
rspec-
|
23
|
-
|
24
|
-
|
25
|
-
rspec-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
data/LICENCE.md
ADDED
@@ -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
|
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
|
-
##
|
119
|
+
## Under the hood
|
91
120
|
|
92
|
-
|
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
|
-
|
123
|
+
http://www.airspayce.com/mikem/bcm2835/index.html
|
96
124
|
|
97
|
-
|
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
|
-
|
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 '
|
2
|
-
require '
|
3
|
-
require 'echoe'
|
4
|
-
require 'rake/testtask'
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
5
3
|
|
6
|
-
|
7
|
-
#rake build_gemspec
|
8
|
-
#gem build pi_piper.gemspec
|
9
|
-
#gem push xxx.gem
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
5
|
|
11
|
-
|
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.
|