rpi_workshop 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rpi_workshop (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ rpi_workshop!
data/Manifest ADDED
@@ -0,0 +1,15 @@
1
+ Gemfile
2
+ Gemfile.lock
3
+ Manifest
4
+ README.md
5
+ Rakefile
6
+ lib/pi_piper.rb
7
+ lib/pi_piper/bcm2835.rb
8
+ lib/pi_piper/frequency.rb
9
+ lib/pi_piper/i2c.rb
10
+ lib/pi_piper/libbcm2835.img
11
+ lib/pi_piper/pin.rb
12
+ lib/pi_piper/platform.rb
13
+ lib/pi_piper/spi.rb
14
+ lib/pi_piper/pin_values.rb
15
+ pi_piper.gemspec
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ ## Overview
2
+
3
+ [![Build Status](https://travis-ci.org/jwhitehorn/pi_piper.png)](https://travis-ci.org/jwhitehorn/pi_piper)
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,
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
+
8
+ To get started:
9
+
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
+
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
+
16
+ To install Pi Piper:
17
+
18
+ sudo gem install pi_piper
19
+
20
+ ### GPIO
21
+
22
+ The GPIO pins (or General Purpose I/O pins) are the primary "do anything" pins on the Raspberry Pi. Reading inputs from them is as simple as:
23
+
24
+ ```ruby
25
+ require 'pi_piper'
26
+ include PiPiper
27
+
28
+ watch :pin => 23 do
29
+ puts "Pin changed from #{last_value} to #{value}"
30
+ end
31
+
32
+ #Or
33
+
34
+ after :pin => 23, :goes => :high do
35
+ puts "Button pressed"
36
+ end
37
+
38
+ PiPiper.wait
39
+ ```
40
+
41
+ Your block will be called when a change to the pin's state is detected.
42
+
43
+ When using pins as input, you can use internal resistors to pull the pin
44
+ up or pull down. This is important if you use open-collector sensors
45
+ which have floating output in some states.
46
+
47
+ You can set resistors when creating a pin passing a :pull parameter
48
+ (which can be :up, :down or :off, which is the default).
49
+
50
+ ```ruby
51
+ pin = PiPiper::Pin.new(:pin => 17, :direction => :in, :pull => :up)
52
+ ```
53
+
54
+ This way, the pin will always return 'on' if it is unconnected or of the
55
+ sensor has an open collector output.
56
+
57
+ You can later alter the pulling resistors using PiPiper#pull!
58
+
59
+ Additionally you can use pins as output too:
60
+
61
+ ```ruby
62
+ pin = PiPiper::Pin.new(:pin => 17, :direction => :out)
63
+ pin.on
64
+ sleep 1
65
+ pin.off
66
+ ```
67
+
68
+ _please note, in the above context "pin" refers to the GPIO number of the Raspberry Pi._
69
+
70
+ ### SPI
71
+ Starting with version 1.2, Pi Piper offers SPI support.
72
+
73
+ ```ruby
74
+ PiPiper::Spi.begin do
75
+ puts write [0x01, 0x80, 0x00]
76
+ end
77
+ ```
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
+ ## Documentation
89
+
90
+ API documentation for Pi Piper can be found at [rdoc.info](http://rdoc.info/github/jwhitehorn/pi_piper/frames/).
91
+
92
+ ## Example projects
93
+
94
+ Looking for more examples/sample code for Pi Piper? Then check out the following example projects, complete with circuit diagrams:
95
+
96
+ * [Project 1: Morse Code](https://github.com/jwhitehorn/pi_piper/wiki/Project-1:-Morse-Code)
97
+ * [Project 2: Simple Switch](https://github.com/jwhitehorn/pi_piper/wiki/Project-2:-Simple-Switch)
98
+ * [Project 3: 2-bit counter](https://github.com/jwhitehorn/pi_piper/wiki/Project-3:-2-bit-counter)
99
+ * [Project 4: MCP3008](https://github.com/jwhitehorn/pi_piper/wiki/Project-4:-MCP3008)
100
+
101
+ ## License
102
+
103
+ Copyright (c) 2013, [Jason Whitehorn](https://github.com/jwhitehorn)
104
+ All rights reserved.
105
+
106
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
107
+
108
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
109
+ * 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.
110
+
111
+ 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.
112
+
113
+
114
+
115
+ ***
116
+ <img src="http://www.raspberrypi.org/wp-content/uploads/2012/03/Raspi_Colour_R.png" width="90" />
117
+
118
+ Proudly developed exclusively on a [Raspberry Pi](http://www.raspberrypi.org)
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+ require 'rspec/core/rake_task'
5
+
6
+ #rake manifest
7
+ #rake build_gemspec
8
+ #gem build pi_piper.gemspec
9
+ #gem push xxx.gem
10
+
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
+ RSpec::Core::RakeTask.new(:spec)
23
+
24
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ class Button
2
+
3
+ def initialize(gpio)
4
+ @gpio = gpio
5
+ `gpio -g mode #{gpio} in`
6
+ puts "gpio mode #{gpio} in"
7
+ `gpio -g mode #{gpio} up`
8
+ puts "gpio mode #{gpio} up"
9
+ end
10
+
11
+ def status
12
+ return `gpio -g read #{@gpio}`
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "rpi_workshop"
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Marcus Schappi"]
9
+ s.date = "2015-03-27"
10
+ s.description = "A simple Raspberry Pi GPIO Library for Raspberry Pi Workshops"
11
+ s.email = "team@littlebirdelectronics.com"
12
+ s.files = ["Gemfile", "Gemfile.lock", "Manifest", "README.md", "Rakefile", "lib/rpi_workshop.rb", "rpi_workshop.gemspec"]
13
+ s.homepage = "http://github.com/schappim/rpi_workshop"
14
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pi_piper", "--main", "README.md"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = "rpi_workshop"
17
+ s.rubygems_version = "0.0.1"
18
+ s.summary = "Ultra Basic Raspberry Pi GPIO Library"
19
+
20
+ if s.respond_to? :specification_version
21
+ s.specification_version = 4
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpi_workshop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marcus Schappi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple Raspberry Pi GPIO Library for Raspberry Pi Workshops
15
+ email: team@littlebirdelectronics.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - Gemfile.lock
22
+ - Manifest
23
+ - README.md
24
+ - Rakefile
25
+ - lib/rpi_workshop.rb
26
+ - rpi_workshop.gemspec
27
+ homepage: http://github.com/schappim/rpi_workshop
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options:
31
+ - --line-numbers
32
+ - --inline-source
33
+ - --title
34
+ - Pi_piper
35
+ - --main
36
+ - README.md
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '1.2'
51
+ requirements: []
52
+ rubyforge_project: rpi_workshop
53
+ rubygems_version: 1.8.23
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Ultra Basic Raspberry Pi GPIO Library
57
+ test_files: []