dredger-iot 0.2.0 → 0.2.1
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/CHANGELOG.md +8 -1
- data/README.md +43 -0
- data/bin/dredger +48 -0
- data/lib/dredger/iot/bus/gpio_label_adapter.rb +14 -4
- data/lib/dredger/iot/pins/raspberry_pi.rb +54 -0
- data/lib/dredger/iot/pins.rb +1 -0
- data/lib/dredger/iot/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6710d17818b007805d0634e65fde9048c5fb191b9a11d4c5ac3d09aeccf9483e
|
|
4
|
+
data.tar.gz: cb7d2e68d335ee490f902b9eaed4b30b6499b8a688336f47678619e862b48cf6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c14e577283263ea3a3674280cf416bde53ce0c172776fe85c2a9bde00835d7b42fd5badf5bcff6e8dc16b041abae9d810ad7fe510f2afbb86a1c7ffcf0b9d35b
|
|
7
|
+
data.tar.gz: bb7fc628012d3f9e26d83a792e24fdf20493de7cf984dee32a17658221aa53a7e5b208c49bbd528bb431320354edec09b3dd4506b52fff1b05ae6b4965de1daf
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1] - 2025-10-05
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Examples: Raspberry Pi GPIO blink script (GPIO17)
|
|
14
|
+
- Docs: Raspberry Pi OS instructions to enable I2C and 1-Wire
|
|
15
|
+
|
|
10
16
|
## [0.2.0] - 2025-10-05
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -64,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
64
70
|
- RuboCop configuration and compliance
|
|
65
71
|
- Comprehensive documentation and usage examples
|
|
66
72
|
|
|
67
|
-
[Unreleased]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.2.
|
|
73
|
+
[Unreleased]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.2.1...HEAD
|
|
74
|
+
[0.2.1]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.2.0...v0.2.1
|
|
68
75
|
[0.2.0]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.2...v0.2.0
|
|
69
76
|
[0.1.2]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.1...v0.1.2
|
|
70
77
|
[0.1.1]: https://github.com/TheMadBotterINC/dredger-iot/compare/v0.1.0...v0.1.1
|
data/README.md
CHANGED
|
@@ -70,6 +70,26 @@ Environment overrides:
|
|
|
70
70
|
- `DREDGER_IOT_GPIO_BACKEND`: `simulation` | `libgpiod`
|
|
71
71
|
- `DREDGER_IOT_I2C_BACKEND`: `simulation` | `linux`
|
|
72
72
|
|
|
73
|
+
## Raspberry Pi GPIO label mapping
|
|
74
|
+
|
|
75
|
+
When the libgpiod backend is selected via Auto, Dredger-IoT resolves Raspberry Pi labels to the corresponding chip:line before accessing the GPIO line. Accepted labels:
|
|
76
|
+
- GPIO17 or BCM17 (Broadcom numbering)
|
|
77
|
+
- PIN11 or BOARD11 (header pin numbers)
|
|
78
|
+
|
|
79
|
+
On most Raspberry Pi boards, GPIO lines are exposed on gpiochip0 and the line offset matches the BCM number. The adapter will translate labels accordingly.
|
|
80
|
+
|
|
81
|
+
Example:
|
|
82
|
+
|
|
83
|
+
```ruby path=null start=null
|
|
84
|
+
require 'dredger/iot'
|
|
85
|
+
|
|
86
|
+
gpio = Dredger::IoT::Bus::Auto.gpio # picks libgpiod on RPi, otherwise simulation
|
|
87
|
+
|
|
88
|
+
# Use Raspberry Pi labels
|
|
89
|
+
gpio.set_direction('GPIO17', :out)
|
|
90
|
+
gpio.write('GPIO17', 1)
|
|
91
|
+
```
|
|
92
|
+
|
|
73
93
|
## Beaglebone P9_XX label mapping
|
|
74
94
|
|
|
75
95
|
When the libgpiod backend is selected via Auto, Dredger-IoT resolves Beaglebone labels like `P9_12` to the corresponding `gpiochipN:line` before accessing the GPIO line. A minimal built-in table is provided and can be extended in future releases.
|
|
@@ -353,6 +373,29 @@ ls /sys/bus/w1/devices/
|
|
|
353
373
|
# Should show devices like: 28-00000xxxxxx
|
|
354
374
|
```
|
|
355
375
|
|
|
376
|
+
#### Raspberry Pi OS: Enable I2C and 1-Wire
|
|
377
|
+
|
|
378
|
+
On Raspberry Pi OS you can enable I2C and 1-Wire via raspi-config or by editing /boot/config.txt.
|
|
379
|
+
|
|
380
|
+
Option A: raspi-config (recommended)
|
|
381
|
+
```bash path=null start=null
|
|
382
|
+
sudo raspi-config
|
|
383
|
+
# Interface Options → I2C → Enable
|
|
384
|
+
# Interface Options → 1-Wire → Enable
|
|
385
|
+
sudo reboot
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Option B: edit /boot/config.txt
|
|
389
|
+
```bash path=null start=null
|
|
390
|
+
# Enable I2C
|
|
391
|
+
sudo sed -i 's/^#\?dtparam=i2c_arm=.*/dtparam=i2c_arm=on/' /boot/config.txt
|
|
392
|
+
# Enable 1-Wire on default BCM4 (PIN7)
|
|
393
|
+
echo 'dtoverlay=w1-gpio,gpiopin=4' | sudo tee -a /boot/config.txt
|
|
394
|
+
sudo reboot
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
Note: Dredger-IoT accepts Raspberry Pi labels like GPIO17, BCM17, and PIN11.
|
|
398
|
+
|
|
356
399
|
#### Beaglebone Black Device Tree
|
|
357
400
|
|
|
358
401
|
For Beaglebone Black, you may need to enable device tree overlays:
|
data/bin/dredger
CHANGED
|
@@ -32,6 +32,8 @@ class DredgerCLI
|
|
|
32
32
|
test_i2c
|
|
33
33
|
when 'info'
|
|
34
34
|
show_info
|
|
35
|
+
when 'doctor'
|
|
36
|
+
doctor
|
|
35
37
|
else
|
|
36
38
|
puts parser
|
|
37
39
|
exit 1
|
|
@@ -53,6 +55,7 @@ class DredgerCLI
|
|
|
53
55
|
opts.separator ' read SENSOR [OPTIONS] Read from a sensor'
|
|
54
56
|
opts.separator ' test-gpio PIN Test GPIO pin'
|
|
55
57
|
opts.separator ' test-i2c Scan I2C bus'
|
|
58
|
+
opts.separator ' doctor Check system prerequisites'
|
|
56
59
|
opts.separator ' info Show system information'
|
|
57
60
|
opts.separator ''
|
|
58
61
|
opts.separator 'Options:'
|
|
@@ -270,6 +273,51 @@ class DredgerCLI
|
|
|
270
273
|
puts " DREDGER_IOT_I2C_BACKEND: #{ENV['DREDGER_IOT_I2C_BACKEND'] || '(not set)'}"
|
|
271
274
|
end
|
|
272
275
|
|
|
276
|
+
def doctor
|
|
277
|
+
puts 'Doctor: checking system prerequisites...'
|
|
278
|
+
puts
|
|
279
|
+
check_device_node('/dev/gpiochip0', 'GPIO (libgpiod) device')
|
|
280
|
+
check_device_node('/dev/i2c-1', 'I2C device (bus 1)')
|
|
281
|
+
check_path('/sys/bus/w1/devices', '1-Wire bus (DS18B20) directory')
|
|
282
|
+
|
|
283
|
+
puts
|
|
284
|
+
puts 'Kernel modules:'
|
|
285
|
+
mods = read_proc_modules
|
|
286
|
+
puts " i2c-dev: #{mods.include?('i2c_dev') ? 'loaded' : 'missing'}"
|
|
287
|
+
puts " w1-gpio: #{mods.include?('w1_gpio') ? 'loaded' : 'missing'}"
|
|
288
|
+
puts " w1-therm: #{mods.include?('w1_therm') ? 'loaded' : 'missing'}"
|
|
289
|
+
|
|
290
|
+
puts
|
|
291
|
+
puts 'Recommendations:'
|
|
292
|
+
puts " sudo apt-get install gpiod i2c-tools"
|
|
293
|
+
puts " sudo usermod -a -G gpio $USER # for GPIO access"
|
|
294
|
+
puts " sudo usermod -a -G i2c $USER # for I2C access"
|
|
295
|
+
puts " sudo modprobe i2c-dev"
|
|
296
|
+
puts " sudo modprobe w1-gpio; sudo modprobe w1-therm"
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def check_device_node(path, desc)
|
|
300
|
+
if File.exist?(path)
|
|
301
|
+
puts " ✔ #{desc}: present (#{path})"
|
|
302
|
+
else
|
|
303
|
+
puts " ✖ #{desc}: missing (#{path})"
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def check_path(path, desc)
|
|
308
|
+
if Dir.exist?(path)
|
|
309
|
+
puts " ✔ #{desc}: present (#{path})"
|
|
310
|
+
else
|
|
311
|
+
puts " ✖ #{desc}: missing (#{path})"
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def read_proc_modules
|
|
316
|
+
File.read('/proc/modules')
|
|
317
|
+
rescue StandardError
|
|
318
|
+
''
|
|
319
|
+
end
|
|
320
|
+
|
|
273
321
|
def setup_backends
|
|
274
322
|
case @options[:backend]
|
|
275
323
|
when 'simulation'
|
|
@@ -5,9 +5,11 @@ module Dredger
|
|
|
5
5
|
module Bus
|
|
6
6
|
# Adapts label strings (e.g. 'P9_12') to PinRef with chip:line for libgpiod backends
|
|
7
7
|
class GPIOLabelAdapter
|
|
8
|
-
|
|
8
|
+
# mapper can be a single mapper module/class or an Array of them.
|
|
9
|
+
# Defaults to both Beaglebone and RaspberryPi mappers.
|
|
10
|
+
def initialize(backend:, mapper: [Dredger::IoT::Pins::Beaglebone, Dredger::IoT::Pins::RaspberryPi])
|
|
9
11
|
@backend = backend
|
|
10
|
-
@
|
|
12
|
+
@mappers = Array(mapper)
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def set_direction(pin, direction)
|
|
@@ -24,16 +26,24 @@ module Dredger
|
|
|
24
26
|
|
|
25
27
|
private
|
|
26
28
|
|
|
29
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
27
30
|
def resolve(pin)
|
|
28
31
|
# Already a PinRef with line
|
|
29
32
|
return pin if pin.respond_to?(:line) && !pin.line.nil?
|
|
33
|
+
|
|
30
34
|
# Numeric line
|
|
31
35
|
return Integer(pin) if pin.is_a?(Integer) || pin.to_s =~ /^\d+$/
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
|
|
37
|
+
# Try all mappers in order
|
|
38
|
+
@mappers.each do |m|
|
|
39
|
+
if m.respond_to?(:resolve_label_to_pinref) && m.respond_to?(:valid_label?) && m.valid_label?(pin)
|
|
40
|
+
return m.resolve_label_to_pinref(pin)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
34
43
|
|
|
35
44
|
raise ArgumentError, 'Unsupported pin format'
|
|
36
45
|
end
|
|
46
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
37
47
|
end
|
|
38
48
|
end
|
|
39
49
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dredger
|
|
4
|
+
module IoT
|
|
5
|
+
module Pins
|
|
6
|
+
# Raspberry Pi header/BCM label mapping.
|
|
7
|
+
# Supports labels like:
|
|
8
|
+
# - GPIO17, BCM17
|
|
9
|
+
# - PIN11 (a.k.a. BOARD11)
|
|
10
|
+
class RaspberryPi
|
|
11
|
+
PinRef = Struct.new(:label, :chip, :line, keyword_init: true) do
|
|
12
|
+
def to_s
|
|
13
|
+
chip && line ? "#{label}(chip#{chip}:#{line})" : label.to_s
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Subset of BOARD pin to BCM mapping for common usable GPIOs on 40-pin header
|
|
18
|
+
BOARD_TO_BCM = {
|
|
19
|
+
3 => 2, 5 => 3, 7 => 4, 8 => 14, 10 => 15, 11 => 17, 12 => 18, 13 => 27,
|
|
20
|
+
15 => 22, 16 => 23, 18 => 24, 19 => 10, 21 => 9, 22 => 25, 23 => 11,
|
|
21
|
+
24 => 8, 26 => 7, 29 => 5, 31 => 6, 32 => 12, 33 => 13, 35 => 19,
|
|
22
|
+
36 => 16, 37 => 26, 38 => 20, 40 => 21
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
# Accept variants like GPIO17, BCM17, PIN11, BOARD11
|
|
26
|
+
def self.valid_label?(label)
|
|
27
|
+
s = label.to_s.upcase
|
|
28
|
+
return true if s.match?(/^(GPIO|BCM)\d+$/)
|
|
29
|
+
return true if s.match?(/^(PIN|BOARD)\d+$/)
|
|
30
|
+
|
|
31
|
+
false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.resolve_label_to_pinref(label)
|
|
35
|
+
s = label.to_s.upcase
|
|
36
|
+
if s =~ /^(GPIO|BCM)(\d+)$/
|
|
37
|
+
bcm = Regexp.last_match(2).to_i
|
|
38
|
+
return PinRef.new(label: label.to_s, chip: 0, line: bcm)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if s =~ /^(PIN|BOARD)(\d+)$/
|
|
42
|
+
board = Regexp.last_match(2).to_i
|
|
43
|
+
bcm = BOARD_TO_BCM[board]
|
|
44
|
+
raise ArgumentError, "Unknown/unsupported board pin: #{label}" if bcm.nil?
|
|
45
|
+
|
|
46
|
+
return PinRef.new(label: label.to_s, chip: 0, line: bcm)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
raise ArgumentError, "Unknown Raspberry Pi pin label: #{label}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/dredger/iot/pins.rb
CHANGED
data/lib/dredger/iot/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dredger-iot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Mad Botter INC
|
|
@@ -49,6 +49,7 @@ files:
|
|
|
49
49
|
- lib/dredger/iot/bus/i2c_linux.rb
|
|
50
50
|
- lib/dredger/iot/pins.rb
|
|
51
51
|
- lib/dredger/iot/pins/beaglebone.rb
|
|
52
|
+
- lib/dredger/iot/pins/raspberry_pi.rb
|
|
52
53
|
- lib/dredger/iot/reading.rb
|
|
53
54
|
- lib/dredger/iot/scheduler.rb
|
|
54
55
|
- lib/dredger/iot/sensors.rb
|
|
@@ -97,7 +98,7 @@ post_install_message: "\n ═════════════════
|
|
|
97
98
|
\ | \n |_____________________________| \n
|
|
98
99
|
\ ~~~ \\ // ~~~ \n \\_______________//
|
|
99
100
|
\ \n ═══════════════════════════════════════════════════════════════════\nHardware
|
|
100
|
-
Integration for Embedded Linux v0.2.
|
|
101
|
+
Integration for Embedded Linux v0.2.1\n ═══════════════════════════════════════════════════════════════════\n\n
|
|
101
102
|
\ \U0001F389 Thanks for installing!\n\n \U0001F4DA Hardware Setup (kernel modules
|
|
102
103
|
& permissions):\n https://github.com/TheMadBotterINC/dredger-iot#hardware-setup\n\n
|
|
103
104
|
\ \U0001F680 Quick Start:\n require 'dredger/iot'\n gpio = Dredger::IoT::Bus::Auto.gpio\n
|