denko-piboard 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bd44c89b18336b4d540b81e6fd7e74cf3dd51a733f148e9acd8278795942249
4
- data.tar.gz: 02d317de93789676488866e9560ca4d5da91014f47509029991b4be31ab20c9f
3
+ metadata.gz: 5677a479b94e8352c42dee06a389339b95fe1adcf897fa7ce871a0d7ca394aaf
4
+ data.tar.gz: 355ce56cafe97d3511cd60b3cc7f91d75167b3485d06f1e162308347d11471c2
5
5
  SHA512:
6
- metadata.gz: c8bb78c2b3e62273b21ec520d35ba54465d3edf8f2e93811f7aaca0aca1e089152a7a0479715754d77301bc8ad938a39086a8bb1cb127566b5ac9c126946956d
7
- data.tar.gz: d305d28242a97dd14c546516c5ba4b5853e249822981c59ed55e1fb949573524c3744e1a1b2f7889658de8afcedeb469b018acc5dc233fb0e29798a923827e33
6
+ metadata.gz: d9010b4a8acd2172d1f19c8c666b76c1240b79b9f9cb814d495138235433a588e35e3b3e262d95875e5baedd84f13c40274913adb882cb968bb5637fad811390
7
+ data.tar.gz: 3dfc780aa00dbae71df4308f7e73aa721e5fd6cbcc4b70159206115166f21ece1827a337920fead04b6892ab7283378facaed7d0eeae450d6dfa1da0f2e7bc25
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # denko-piboard 0.13.0
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
 
@@ -23,13 +23,13 @@ led = Denko::LED.new(board: board, pin: 4)
23
23
  # Momentary button connected to GPIO17, using internal pullup.
24
24
  button = Denko::DigitalIO::Button.new(board: board, pin: 17, pullup: true)
25
25
 
26
- # Led on when button is down (0)
26
+ # Callback runs when button is down (0)
27
27
  button.down do
28
28
  puts "Button down"
29
29
  led.on
30
30
  end
31
31
 
32
- # Led is off when button is up (1)
32
+ # Callback runs when button is up (1)
33
33
  button.up do
34
34
  puts "Button up"
35
35
  led.off
@@ -43,8 +43,9 @@ Run it:
43
43
  ```shell
44
44
  ruby led_button.rb
45
45
  ```
46
+
46
47
  #### More Examples
47
- Some Pi-specific code is shown in this gem's [examples](examples) folder, but most examples are in the [main gem](https://github.com/denko-rb/denko/tree/master/examples). They must be modified to work with the Pi's GPIO:
48
+ Pi-specific examples will be in this gem's [examples](examples) folder, but most examples are in the [main gem](https://github.com/denko-rb/denko/tree/master/examples). They must be modified to work with the Pi's GPIO:
48
49
 
49
50
  1. Replace setup code:
50
51
  ```ruby
@@ -66,7 +67,17 @@ Some Pi-specific code is shown in this gem's [examples](examples) folder, but mo
66
67
  **Note:** Not all features from all examples are implemented yet, nor can be implemented. See [Features](#features) below.
67
68
 
68
69
  ## 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
+
71
+ #### System Requirements
72
+ - Tested on a Pi Zero W and Pi 3B, but should work on others.
73
+ - Tested on DietPi and Raspberry Pi OS, both based on Debian 11 (Bullseye), with kernel version 6.1 or higher.
74
+ - Tested Ruby versions:
75
+ - Ruby 2.7.4 (incldued with OS)
76
+ - Ruby 3.2.2+YJIT
77
+ - TruffleRuby 22.3.1 :man_shrugging: (Not available on ARMv6 Pis: Zero W, Pi 1. Not recommended in general)
78
+
79
+ #### Dependencies
80
+ This gem depends on [pigpio](https://github.com/joan2937/pigpio), the [pigpio gem](https://github.com/nak1114/ruby-extension-pigpio) to provide Ruby bindings, and [libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git).
70
81
 
71
82
  #### 1. Install pigpio and libgpiod packages
72
83
  ```shell
@@ -74,56 +85,47 @@ sudo apt install pigpio libgpiod-dev
74
85
  ```
75
86
 
76
87
  #### 2. Install pigpio gem
77
- The `pigpio` gem has a couple bugs. Until fixes are merged, please install from [this fork](https://github.com/vickash/ruby-extension-pigpio):
88
+ A bug in the current `pigpio` gem release prevents it from installing on Ruby 3.2+. You can safely ignore this step if using a lower Ruby version, or install it from [this fork](https://github.com/vickash/ruby-extension-pigpio) until fixes are merged and released:
78
89
  ```shell
79
- git clone https://github.com/vickash/ruby-extension-pigpio.git
90
+ git clone https://github.com/denko-rb/ruby-extension-pigpio.git
80
91
  cd ruby-extension-pigpio
81
92
  gem build
82
93
  gem install ruby-extension-pigpio-0.1.11.gem
83
94
  ```
84
95
 
85
- #### 3. Install denko gem
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:
96
+ #### 3. Install denko-piboard gem
87
97
  ```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
98
+ gem install denko-piboard
94
99
  ```
100
+ This will automatically install the main `denko` gem and any other dependencies.
101
+
102
+ **Note:** `sudo` may be needed before `gem install` if using the preinstalled Ruby on a Pi.
95
103
 
96
- #### 4. Install denko/piboard gem
97
- Again, since this gem is so new, install from the latest master branch:
104
+ ## Pi Setup
105
+
106
+ #### pigpiod
107
+ The `pigpio` package installs `pigpiod`, which needs to be running 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
108
  ```shell
99
- git clone https://github.com/denko-rb/denko-piboard.git
100
- cd denko-piboard
101
- gem build
102
- gem install denko-piboard-0.13.0.gem
109
+ sudo pigpiod -s 10
103
110
  ```
111
+ **Note:** `-s 10` sets tick interval to 10 microseconds, lowering CPU use. Valid values are: 1, 2, 4, 5, 8, 10 (5 default).
104
112
 
105
- **Note:** `sudo` may be needed before `gem install` if using the preinstalled Ruby on a Raspberry Pi.
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.
113
+ #### libgpiod
114
+ Depending on your Pi and OS, `libgpiod` may limit GPIO access. If this is the case, some scripts will fail with a `libgpiod` error. It is only used for low-level digital read/write operations, so check using a simple script like blinking an LED. To get `libgpiod` permission, add your user account to the `gpio` group:
109
115
  ```
110
- sudo usermod -a -G gpio YOUR_USERNAME
116
+ sudo usermod -a -G gpio $(whoami)
111
117
  ```
112
118
 
113
- I2C, SPI and the hardware UART are disabled on the Pi by default. Enable them with the built in utility:
119
+ #### Features
120
+ I2C, SPI and the hardware UART may be disabled on the Pi by default. Enable them with the built-in utility:
114
121
  ```shell
122
+ # On Raspberry Pi OS:
115
123
  sudo raspi-config
116
- ```
117
-
118
- Select "Interfacing Options" from the menu and enable as needed. More info in the [Features](#features) section.
119
124
 
120
- #### pigpiod
121
- The `pigpio` package includes `pigpiod`, which runs in the background as root, providing GPIO access. Ruby scripts won't work if it isn't running. You should only need to start it once per boot. You can automate it, or start manually with:
122
- ```shell
123
- sudo pigpiod -s 10
125
+ # On DietPi:
126
+ sudo dietpi-config
124
127
  ```
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).
128
+ Select "Interfacing Options" (Raspberry Pi OS), or "Advanced Options" (DietPi) and enable features as needed.
127
129
 
128
130
  ## Features
129
131
 
@@ -131,22 +133,32 @@ sudo pigpiod -s 10
131
133
  - Internal Pull Down/Up
132
134
  - Digital Out
133
135
  - Digital In
134
- - PWM Out (use on any pin disables PCM out, cancels Servo on same pin)
135
- - Servo (use on any pin disables PCM out, cancels PWM Out on same pin)
136
- - ToneOut (uses waves, one at a time per board, cancels any Infrared Out)
137
- - Infrared Out (uses waves, one at a time per board, cancels any Tone Out)
136
+ - Listeners are polled in a thread, similar to a microcontroller, but always at 1ms.
137
+ - `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.
138
+ - PWM Out
139
+ - Servo
140
+ - Tone Out
141
+ - Infrared Out
138
142
  - DHT Class Temperature + Humidity Sensors
139
143
  - I2C
140
- - Must enable with `raspi-config` before use. Instructions [here](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c).
141
- - I2C hardware clock cannot be set dynamically, like a microcontroller. Must set in `/boot/config.txt`. Default is 100 kHz. 400 kHz recommended if transferring a lot of data, like with SSD1306 OLED. See [here](https://www.raspberrypi-spy.co.uk/2018/02/change-raspberry-pi-i2c-bus-speed/) for instructions.
144
+ - Always uses I2C1 interface.
145
+ - Must enable before use. Instructions [here](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c).
146
+ - 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
147
 
143
148
  ### Partially Implemented
144
- - SPI
145
- - Must enable with `raspi-config` before use. Insturctions [here](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-spi).
146
- - Only Uses SPI1 interface, not SPI0.
147
- - Does not bind CE pins according to GPIO pinout. Any pin can be used for chip enable.
148
- - SPI modes 1 and 3 may not work.
149
- - No listeners yet.
149
+ - SPI
150
+ - Always uses SPI1 interface.
151
+ - Must enable before use. Instructions [here](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-spi).
152
+ - Does not bind CE pins according to GPIO pinout. Any pin can be used for chip enable.
153
+ - SPI modes 1 and 3 may not work.
154
+ - No listeners yet.
155
+
156
+ ### Feature Exclusivity
157
+ - PWM Out / Servo Out
158
+ - Using either of these on **any** pin disables the Pi's PCM audio output globally.
159
+
160
+ - Tone Out / Infrared Out
161
+ - 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
162
 
151
163
  ### To Be Implemented
152
164
  - OneWire
@@ -156,10 +168,6 @@ sudo pigpiod -s 10
156
168
  - BitBang UART
157
169
  - WS2812
158
170
 
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
171
  ### Incompatible
164
172
  - EEPROM (Use the filesystem for persistence instead)
165
173
  - Analog IO (No analog pins on Raspberry Pi. Use ADC or DAC over I2C or SPI)
@@ -2,6 +2,9 @@ module Denko
2
2
  class PiBoard
3
3
  # CMD = 0
4
4
  def set_pin_mode(pin, mode=:input, glitch_time=nil)
5
+ # Validate pin
6
+ # Validate output type
7
+
5
8
  # Close the line in libgpiod, if was already open.
6
9
  Denko::GPIOD.close_line(pin)
7
10
 
@@ -157,6 +160,7 @@ module Denko
157
160
 
158
161
  # Target 1 millisecond.
159
162
  @listen_sleep = 0.001 - active_time_per_loop
163
+ @listen_sleep = 0 if @listen_sleep < 0
160
164
  end
161
165
  end
162
166
  end
@@ -1,5 +1,5 @@
1
1
  module Denko
2
2
  class PiBoard
3
- VERSION = '0.13.0'
3
+ VERSION = '0.13.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denko-piboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - vickash