dino-piboard 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +99 -0
- data/dino_piboard.gemspec +18 -0
- data/lib/dino/piboard.rb +99 -0
- data/lib/dino/piboard_version.rb +5 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c818f293ae8e78640d008dea2a231c80bbff914ac04bb940ff7776eeb63cee5
|
4
|
+
data.tar.gz: b6af65be62e98f36c54f61530a06be17724c50b081b3d692b46ff07ec8c80bbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44b41a354d3f7596c3a31026729bf692c0316f0b88f8984b7202227623aca58761475731741e58c9b81049e5bd48465e10545bc2fa285c72c5385a5783b03b53
|
7
|
+
data.tar.gz: b6bc39739b03253c8a5811cf9c44521a3afc119f73e8466f099cf06e8700dba2cd2b270827e012f8c20c794492d90d78c8c54ffa4836915ebe44344de0a9a38d
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 dino-rb
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# dino-piboard 0.13.0
|
2
|
+
|
3
|
+
This is an add-on to the [`dino`](https://github.com/austinbv/dino) gem. It adds support for the GPIO interface on Raspberry Pi single board computers. Unlike the main `dino` gem, which connects a computer running Ruby to an external microcontroller, this requires only a Pi.
|
4
|
+
|
5
|
+
`Dino::PiBoard` gives access to the Pi's own GPIO, and is a drop-in replacement for `Dino::Board`, which would represent an external microcontroller.
|
6
|
+
|
7
|
+
**Note:** This is not for the Raspberry Pi Pico (W) / RPP2040. That microcontroller is covered by the main gem.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
**Note:** This gem is very new. It WILL NOT work with the version of `dino` (0.11.3) currently available on rubygems.org. Before installing `dino-piboard`, make sure to install the latest dino version (future 0.13.0) from the master branch source.
|
11
|
+
|
12
|
+
Install dino from source:
|
13
|
+
```shell
|
14
|
+
sudo gem uninstall dino
|
15
|
+
git clone https://github.com/austinbv/dino.git
|
16
|
+
cd dino
|
17
|
+
gem build
|
18
|
+
sudo gem install dino-0.13.0.gem
|
19
|
+
```
|
20
|
+
|
21
|
+
Install the pigpo C library:
|
22
|
+
```shell
|
23
|
+
sudo apt-get install pigpio
|
24
|
+
```
|
25
|
+
|
26
|
+
Install this gem:
|
27
|
+
```shell
|
28
|
+
sudo gem install dino-piboard
|
29
|
+
```
|
30
|
+
|
31
|
+
## Example
|
32
|
+
Create a script, `led_button.rb`:
|
33
|
+
```ruby
|
34
|
+
require 'dino/piboard'
|
35
|
+
|
36
|
+
# Create a board instance for the Raspberry Pi.
|
37
|
+
board = Dino::PiBoard.new
|
38
|
+
|
39
|
+
# LED connected to GPIO4.
|
40
|
+
led = Dino::LED.new(board: board, pin: 4)
|
41
|
+
|
42
|
+
# Momentary button connected to GPIO17, using internal pullup.
|
43
|
+
button = Dino::DigitalIO::Button.new(board: board, pin: 17, pullup: true)
|
44
|
+
|
45
|
+
# Led on when button is down (0)
|
46
|
+
button.down do
|
47
|
+
puts "Button down"
|
48
|
+
led.on
|
49
|
+
end
|
50
|
+
|
51
|
+
# Led is off when button is up (1)
|
52
|
+
button.up do
|
53
|
+
puts "Button up"
|
54
|
+
led.off
|
55
|
+
end
|
56
|
+
|
57
|
+
# Sleep main thread. Ctrl+C to quit.
|
58
|
+
sleep
|
59
|
+
```
|
60
|
+
|
61
|
+
Run the script as root (pigpio can only be used as root):
|
62
|
+
```shell
|
63
|
+
sudo ruby led_button.rb
|
64
|
+
```
|
65
|
+
|
66
|
+
See [`examples`](https://github.com/austinbv/dino/tree/master/examples) in the main gem for more. Remove any `Dino::Board::Connection` and `Dino::Board` objects that the script sets up, and do `board = Dino::PiBoard.new` instead. Not all features are implemented yet though, nor can be implemented. See [Feautres](#features) below.
|
67
|
+
|
68
|
+
## How It Works
|
69
|
+
|
70
|
+
This gem uses the [`pigpio_ffi`](https://github.com/dino-rb/pigpio_ffi) gem, which in turn uses [`ffi`](https://github.com/ffi/ffi) to map the functions of the [`pigpio`](https://github.com/joan2937/pigpio) C library. `pigpio` provides low-level access to the Raspberry Pi's GPIO interface.
|
71
|
+
|
72
|
+
Building on that, `Dino::PiBoard` plugs in as a (mostly) seamless replacement for `Dino::Board`. This allows `dino` features and component classes to be used directly on a Raspberry Pi, without an external microcontroller.
|
73
|
+
|
74
|
+
## Features
|
75
|
+
|
76
|
+
### Already Implemented
|
77
|
+
- Internal Pull Down/Up
|
78
|
+
- Digital Out
|
79
|
+
- Digital In
|
80
|
+
- PWM Out
|
81
|
+
|
82
|
+
### To Be Implemented
|
83
|
+
- Tone Out
|
84
|
+
- Servo
|
85
|
+
- I2C
|
86
|
+
- SPI
|
87
|
+
- OneWire
|
88
|
+
- Infrared Out
|
89
|
+
|
90
|
+
### Won't Be Implemented
|
91
|
+
- UART. It would wrap a [`rubyserial`](https://github.com/hybridgroup/rubyserial) instance. Use that directly instead.
|
92
|
+
|
93
|
+
### Might Be Different
|
94
|
+
- Variable Digital Listen Timing (pigpio doesn't have a real way to do this, but glitch filter might be even better?)
|
95
|
+
|
96
|
+
### Incompatible
|
97
|
+
- Handshake (no need, since running on the same board)
|
98
|
+
- EEPROM (can't mess with that. Use the filesystem instead)
|
99
|
+
- Analog IO (No analog pins on Raspberry Pi. Use an ADC or DAC over I2C or SPI)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'lib/dino/piboard_version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'dino-piboard'
|
5
|
+
s.version = Dino::PiBoard::VERSION
|
6
|
+
s.licenses = ['MIT']
|
7
|
+
s.summary = "Use a Raspberry Pi's built-in GPIO as a board with the dino gem"
|
8
|
+
s.description = "Dino::PiBoard plugs in as a (mostly) seamless replacement for Dino::Board. This allows dino features and component classes to be used directly on a Raspberry Pi, without an external microcontroller."
|
9
|
+
|
10
|
+
s.authors = ["vickash"]
|
11
|
+
s.email = 'vickashmahabir@gmail.com'
|
12
|
+
s.files = Dir['**/*'].reject { |f| f.match /.gem\z/}
|
13
|
+
s.homepage = 'https://github.com/dino-rb/dino-piboard'
|
14
|
+
s.metadata = { "source_code_uri" => "https://github.com/dino-rb/dino-piboard" }
|
15
|
+
|
16
|
+
s.add_dependency 'pigpio_ffi'
|
17
|
+
s.add_dependency 'dino'
|
18
|
+
end
|
data/lib/dino/piboard.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'pigpio_ffi'
|
2
|
+
require 'dino'
|
3
|
+
|
4
|
+
module Dino
|
5
|
+
class PiBoard
|
6
|
+
attr_reader :components, :high, :low
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@components = []
|
10
|
+
|
11
|
+
# Sample every 10us, using PCM peripheral. Keeps CPU usage down.
|
12
|
+
PiGPIO.gpioCfgClock(10, 1, 0)
|
13
|
+
PiGPIO.gpioInitialise
|
14
|
+
|
15
|
+
@low = 0
|
16
|
+
@high = 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def finish_write
|
20
|
+
PiGPIO.gpioTerminate
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(pin, message, time)
|
24
|
+
update_component(pin, message)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_component(pin, message)
|
28
|
+
@components.each do |part|
|
29
|
+
part.update(message) if part.pin.to_i == pin
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_component(component)
|
34
|
+
@components << component
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_component(component)
|
38
|
+
# component.stop if component.methods.include? :stop
|
39
|
+
@components.delete(component)
|
40
|
+
end
|
41
|
+
|
42
|
+
# CMD = 0
|
43
|
+
def set_pin_mode(pin, mode=:input)
|
44
|
+
# Output
|
45
|
+
if mode.to_s.match /output/
|
46
|
+
PiGPIO.gpioSetMode(pin, 1)
|
47
|
+
|
48
|
+
# Input
|
49
|
+
else
|
50
|
+
PiGPIO.gpioSetMode(pin, 0)
|
51
|
+
# Only respond if level has been stable for 90us.
|
52
|
+
PiGPIO.gpioGlitchFilter(pin, 90)
|
53
|
+
|
54
|
+
# Pull down/up/none
|
55
|
+
if mode.to_s.match /pulldown/
|
56
|
+
PiGPIO.gpioSetPullUpDown(pin, 1)
|
57
|
+
elsif mode.to_s.match /pullup/
|
58
|
+
PiGPIO.gpioSetPullUpDown(pin, 2)
|
59
|
+
else
|
60
|
+
PiGPIO.gpioSetPullUpDown(pin, 0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# CMD = 1
|
66
|
+
def digital_write(pin, value)
|
67
|
+
PiGPIO.gpioWrite(pin, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
# CMD = 2
|
71
|
+
def digital_read(pin)
|
72
|
+
update(pin, PiGPIO.gpioRead(pin))
|
73
|
+
end
|
74
|
+
|
75
|
+
# CMD = 3
|
76
|
+
def pwm_write(pin, value)
|
77
|
+
PiGPIO.gpioPWM(pin, value)
|
78
|
+
end
|
79
|
+
|
80
|
+
# CMD = 6
|
81
|
+
def set_listener(set_pin, state=:off, options={})
|
82
|
+
if state == :on
|
83
|
+
PiGPIO.gpioSetAlertFunc(set_pin) do |pin, message, time|
|
84
|
+
update(pin, message, time)
|
85
|
+
end
|
86
|
+
else
|
87
|
+
PiGPIO._gpioSetAlertFunc(pin, nil)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def digital_listen(pin, divider=4)
|
92
|
+
set_listener(pin, :on, {})
|
93
|
+
end
|
94
|
+
|
95
|
+
def stop_listener(pin)
|
96
|
+
set_listener(pin, :off)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dino-piboard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.13.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- vickash
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pigpio_ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dino
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Dino::PiBoard plugs in as a (mostly) seamless replacement for Dino::Board.
|
42
|
+
This allows dino features and component classes to be used directly on a Raspberry
|
43
|
+
Pi, without an external microcontroller.
|
44
|
+
email: vickashmahabir@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- dino_piboard.gemspec
|
52
|
+
- lib/dino/piboard.rb
|
53
|
+
- lib/dino/piboard_version.rb
|
54
|
+
homepage: https://github.com/dino-rb/dino-piboard
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
source_code_uri: https://github.com/dino-rb/dino-piboard
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.4.8
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Use a Raspberry Pi's built-in GPIO as a board with the dino gem
|
78
|
+
test_files: []
|