denko-piboard 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +81 -65
- data/denko_piboard.gemspec +1 -1
- data/examples/pi_system_monitor.rb +14 -5
- data/lib/denko/piboard_core.rb +1 -0
- data/lib/denko/piboard_version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bad42203be8c858270403900ba28c58f7a63eaf616151975e7b5d61a471a472
|
4
|
+
data.tar.gz: ad86f14e2d91a644ea1ccc8f7d599b4bbfa095d55b5f07fc734dd741447811ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aceaac910ced26a348b5a22da0d3729c6cf0b91c66c7bac417d0a96877b531407a2ff56e7fa1aa1c30cde3b8709eea7d9a44b2d07cd1628f315591b0c7477594
|
7
|
+
data.tar.gz: ea5a92edc491447c75417b3e9787fcd785a86e7f15e27c18b92e97b4969ff30dcb1c913bc4fc10b81c09ecbe079859b7a5cd10d9cd744865680d1fd643b842fe
|
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
# denko-piboard 0.13.
|
1
|
+
# denko-piboard 0.13.1
|
2
2
|
|
3
3
|
### Raspberry Pi GPIO in Ruby
|
4
4
|
|
5
5
|
This gem adds support for the Raspberry Pi GPIO interface to the [`denko`](https://github.com/denko-rb/denko) gem. Unlike the main gem, which requires an external microcontroller, this lets you to connect peripherals directly to the Pi.
|
6
6
|
|
7
|
-
`Denko::PiBoard` is a drop-in replacement for `Denko::Board`, which would represent a connected micrcontroller. Everything maps to the Pi's built-in GPIO pins instead.
|
7
|
+
`Denko::PiBoard` is a drop-in replacement for `Denko::Board`, which would represent a connected micrcontroller. Everything maps to the Pi's built-in GPIO pins instead, and Ruby runs on the Pi itself.
|
8
8
|
|
9
9
|
**Note:** This is not for the Raspberry Pi Pico (W) / RP2040. That microcontroller works with the main gem.
|
10
10
|
|
11
11
|
## Example
|
12
|
-
Create a script, `led_button.rb`:
|
13
|
-
|
14
12
|
```ruby
|
15
13
|
require 'denko/piboard'
|
16
14
|
|
@@ -23,13 +21,13 @@ led = Denko::LED.new(board: board, pin: 4)
|
|
23
21
|
# Momentary button connected to GPIO17, using internal pullup.
|
24
22
|
button = Denko::DigitalIO::Button.new(board: board, pin: 17, pullup: true)
|
25
23
|
|
26
|
-
#
|
24
|
+
# Callback runs when button is down (0)
|
27
25
|
button.down do
|
28
26
|
puts "Button down"
|
29
27
|
led.on
|
30
28
|
end
|
31
29
|
|
32
|
-
#
|
30
|
+
# Callback runs when button is up (1)
|
33
31
|
button.up do
|
34
32
|
puts "Button up"
|
35
33
|
led.off
|
@@ -39,12 +37,8 @@ end
|
|
39
37
|
sleep
|
40
38
|
```
|
41
39
|
|
42
|
-
Run it:
|
43
|
-
```shell
|
44
|
-
ruby led_button.rb
|
45
|
-
```
|
46
40
|
#### More Examples
|
47
|
-
|
41
|
+
Pi-specific examples are in this gem's [examples](examples) folder, but examples from the [main gem](https://github.com/denko-rb/denko/tree/master/examples) can be modified to work on the Pi:
|
48
42
|
|
49
43
|
1. Replace setup code:
|
50
44
|
```ruby
|
@@ -65,65 +59,81 @@ Some Pi-specific code is shown in this gem's [examples](examples) folder, but mo
|
|
65
59
|
|
66
60
|
**Note:** Not all features from all examples are implemented yet, nor can be implemented. See [Features](#features) below.
|
67
61
|
|
62
|
+
## Support
|
63
|
+
|
64
|
+
#### Hardware
|
65
|
+
|
66
|
+
:green_heart: Support verified
|
67
|
+
:question: Should work, but not verified
|
68
|
+
|
69
|
+
| Chip | Status | Products | Notes |
|
70
|
+
| :-------- | :------: | :--------------- |------ |
|
71
|
+
| BCM2835 | :green_heart: | Pi 1, Pi Zero (W) |
|
72
|
+
| BCM2836/7 | :question: | Pi 2 |
|
73
|
+
| BCM2837A0/B0 | :green_heart: | Pi 3 |
|
74
|
+
| BCM2711 | :green_heart: | Pi 4, Pi 400 |
|
75
|
+
| BCM2710A1 | :question: | Pi Zero 2W |
|
76
|
+
|
77
|
+
#### Software
|
78
|
+
|
79
|
+
- Operating Systems:
|
80
|
+
- Raspberry Pi OS
|
81
|
+
- DietPi
|
82
|
+
|
83
|
+
Note: Both with kernel version 6.1 or higher.
|
84
|
+
|
85
|
+
- Rubies:
|
86
|
+
- Ruby 2.7.4 (system Ruby on some Raspberry Pi OS installs)
|
87
|
+
- Ruby 3.2.2 (with and without YJIT)
|
88
|
+
- TruffleRuby 22.3.1 :man_shrugging: (Not available on ARMv6 Pis: Zero W, Pi 1. Not recommended in general)
|
89
|
+
|
90
|
+
#### Dependencies
|
91
|
+
|
92
|
+
- [pigpio](https://github.com/joan2937/pigpio)
|
93
|
+
- [libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git)
|
94
|
+
- [pigpio gem](https://github.com/nak1114/ruby-extension-pigpio) (Ruby bindings for pigpio)
|
95
|
+
- [denko](https://github.com/denko-rb/denko) (peripheral implementations from main gem)
|
96
|
+
|
68
97
|
## Installation
|
69
|
-
This gem depends on the [pigpio library](https://github.com/joan2937/pigpio) and [pigpio gem](https://github.com/nak1114/ruby-extension-pigpio), which provides Ruby bindings, as well as [libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git).
|
70
98
|
|
71
99
|
#### 1. Install pigpio and libgpiod packages
|
72
100
|
```shell
|
73
101
|
sudo apt install pigpio libgpiod-dev
|
74
102
|
```
|
75
103
|
|
76
|
-
#### 2. Install
|
77
|
-
The `pigpio` gem has a couple bugs. Until fixes are merged, please install from [this fork](https://github.com/vickash/ruby-extension-pigpio):
|
104
|
+
#### 2. Install denko-piboard gem
|
78
105
|
```shell
|
79
|
-
|
80
|
-
cd ruby-extension-pigpio
|
81
|
-
gem build
|
82
|
-
gem install ruby-extension-pigpio-0.1.11.gem
|
106
|
+
gem install denko-piboard
|
83
107
|
```
|
108
|
+
This automatically installs dependency gems: `denko` and `pigpio`.
|
84
109
|
|
85
|
-
|
86
|
-
This gem is very new. It __will not__ work with the version of `denko` (0.11.3) currently available from RubyGems. Install the latest version (future 0.13.0) from the master branch instead:
|
87
|
-
```shell
|
88
|
-
git clone https://github.com/denko-rb/denko.git
|
89
|
-
cd denko
|
90
|
-
git submodule init
|
91
|
-
git submodule update
|
92
|
-
gem build
|
93
|
-
gem install denko-0.13.0.gem
|
94
|
-
```
|
110
|
+
**Note:** `sudo` may be needed before `gem install` if using the Pi's system ruby.
|
95
111
|
|
96
|
-
|
97
|
-
|
112
|
+
## Pi Setup
|
113
|
+
|
114
|
+
#### pigpiod
|
115
|
+
The `pigpio` package installs `pigpiod`, which must run in the background (as root) for Ruby scripts to work. You should only need to start it once per boot. Automate it, or start manually with:
|
98
116
|
```shell
|
99
|
-
|
100
|
-
cd denko-piboard
|
101
|
-
gem build
|
102
|
-
gem install denko-piboard-0.13.0.gem
|
117
|
+
sudo pigpiod -s 10
|
103
118
|
```
|
119
|
+
**Note:** `-s 10` sets tick interval to 10 microseconds, lowering CPU use. Valid values are: 1, 2, 4, 5, 8, 10 (5 default).
|
104
120
|
|
105
|
-
|
106
|
-
|
107
|
-
## Pi Setup
|
108
|
-
Depending on your Pi setup, libgpiod may limit GPIO access to the `root` user. If this is the case, Ruby scripts will fail with a `libgpiod` error. To give your user account permission to access GPIO, add it to the `gpio` group.
|
121
|
+
#### libgpiod
|
122
|
+
Depending on your Pi and OS, `libgpiod` may limit GPIO access. If this happens, some scripts will fail. It is only used for digital read/write operations, so test with a simple script like blinking an LED. To get permission, add your user account to the `gpio` group:
|
109
123
|
```
|
110
|
-
sudo usermod -a -G gpio
|
124
|
+
sudo usermod -a -G gpio $(whoami)
|
111
125
|
```
|
112
126
|
|
113
|
-
|
127
|
+
#### Enable Features
|
128
|
+
I2C, SPI and the hardware UART may be disabled on the Pi by default. Enable them with the built-in utility:
|
114
129
|
```shell
|
130
|
+
# On Raspberry Pi OS:
|
115
131
|
sudo raspi-config
|
116
|
-
```
|
117
|
-
|
118
|
-
Select "Interfacing Options" from the menu and enable as needed. More info in the [Features](#features) section.
|
119
132
|
|
120
|
-
|
121
|
-
|
122
|
-
```shell
|
123
|
-
sudo pigpiod -s 10
|
133
|
+
# On DietPi:
|
134
|
+
sudo dietpi-config
|
124
135
|
```
|
125
|
-
|
126
|
-
**Note:** `-s 10` sets `pigpiod` to tick every 10 microseconds, lowering CPU use. Valid values are: 1, 2, 4, 5, 8, 10 (5 default).
|
136
|
+
Select "Interfacing Options" (Raspberry Pi OS), or "Advanced Options" (DietPi) and enable features as needed.
|
127
137
|
|
128
138
|
## Features
|
129
139
|
|
@@ -131,22 +141,32 @@ sudo pigpiod -s 10
|
|
131
141
|
- Internal Pull Down/Up
|
132
142
|
- Digital Out
|
133
143
|
- Digital In
|
134
|
-
|
135
|
-
|
136
|
-
-
|
137
|
-
-
|
144
|
+
- Listeners are polled in a thread, similar to a microcontroller, but always at 1ms.
|
145
|
+
- `pigpio` supports even faster polling (1-10 microseconds), but events are not received in a consistent order across pins. Won't work for MultiPin components, but may implement for SinglePin.
|
146
|
+
- PWM Out
|
147
|
+
- Servo
|
148
|
+
- Tone Out
|
149
|
+
- Infrared Out
|
138
150
|
- DHT Class Temperature + Humidity Sensors
|
139
151
|
- I2C
|
140
|
-
-
|
141
|
-
-
|
152
|
+
- Always uses I2C1 interface.
|
153
|
+
- Must enable before use. Instructions [here](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c).
|
154
|
+
- I2C clock cannot be set dynamically. It is set at boot time from `/boot/config.txt`. Default is 100 kHz. 400 kHz is recommended if higher data rate is needed, eg. using OLED screen. Instructions [here](https://www.raspberrypi-spy.co.uk/2018/02/change-raspberry-pi-i2c-bus-speed/).
|
142
155
|
|
143
156
|
### Partially Implemented
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
157
|
+
- SPI
|
158
|
+
- Always uses SPI1 interface.
|
159
|
+
- Must enable before use. Instructions [here](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-spi).
|
160
|
+
- Does not bind CE pins according to GPIO pinout. Any pin can be used for chip enable.
|
161
|
+
- SPI modes 1 and 3 may not work.
|
162
|
+
- No listeners yet.
|
163
|
+
|
164
|
+
### Feature Exclusivity
|
165
|
+
- PWM Out / Servo Out
|
166
|
+
- Using either of these on **any** pin disables the Pi's PCM audio output globally.
|
167
|
+
|
168
|
+
- Tone Out / Infrared Out
|
169
|
+
- Both of these use pigpio's wave interface, which only has a single instance. Calling either on **any** pin automatically stops any running instance that exists. Both features can co-exist in a script, but cannot happen at the same time.
|
150
170
|
|
151
171
|
### To Be Implemented
|
152
172
|
- OneWire
|
@@ -156,10 +176,6 @@ sudo pigpiod -s 10
|
|
156
176
|
- BitBang UART
|
157
177
|
- WS2812
|
158
178
|
|
159
|
-
### Differences
|
160
|
-
- Listeners are still polled in a thread, but always at 1ms.
|
161
|
-
- pigpio has very fast native input callbacks available, but events are not received in order on a global basis, only per pin. This creates issues where event order between pins is important (like a RotaryEncoder). May expose this functionality for SinglePin components later.
|
162
|
-
|
163
179
|
### Incompatible
|
164
180
|
- EEPROM (Use the filesystem for persistence instead)
|
165
181
|
- Analog IO (No analog pins on Raspberry Pi. Use ADC or DAC over I2C or SPI)
|
data/denko_piboard.gemspec
CHANGED
@@ -21,9 +21,18 @@ i2c = Denko::I2C::Bus.new(board: board, pin: :SDA)
|
|
21
21
|
oled = Denko::Display::SSD1306.new(bus: i2c, rotate: true)
|
22
22
|
canvas = oled.canvas
|
23
23
|
|
24
|
+
# Helper to convert free output to nearest integer in MiB units.
|
25
|
+
def ram_integer_from_string(string)
|
26
|
+
if string.match("Gi")
|
27
|
+
return (string.gsub("Gi", "").to_f * 1024).round
|
28
|
+
else
|
29
|
+
return string.gsub("Mi", "").to_i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
24
33
|
# Only do this once since total RAM won't change.
|
25
|
-
|
26
|
-
total_ram =
|
34
|
+
total_ram_string = `free -h | awk 'NR==2 {print $2}'`
|
35
|
+
total_ram = ram_integer_from_string(total_ram_string)
|
27
36
|
ram_bar_factor = total_ram / 25.0
|
28
37
|
|
29
38
|
loop do
|
@@ -39,11 +48,11 @@ loop do
|
|
39
48
|
(cpu_percent / 4).ceil.times { canvas.raw_char(BAR_ELEMENT) }
|
40
49
|
|
41
50
|
# RAM Usage
|
42
|
-
|
43
|
-
ram_usage =
|
51
|
+
ram_string = `free -h | awk 'NR==2 {print $3}'`
|
52
|
+
ram_usage = ram_string.to_i
|
44
53
|
|
45
54
|
canvas.text_cursor = [0, 40]
|
46
|
-
ram_string = "#{ram_usage}/#{total_ram}
|
55
|
+
ram_string = "#{ram_usage}/#{total_ram}M"
|
47
56
|
canvas.print "RAM Usage:#{ram_string.rjust(11, ' ')}"
|
48
57
|
|
49
58
|
canvas.text_cursor = [0, 48]
|
data/lib/denko/piboard_core.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: denko-piboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vickash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pigpio
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.1.12
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.1.12
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: denko
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|