You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-18Lines changed: 63 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,68 @@
2
2
This repository contains example code useful when using the WaveShare 8-channel relay module for the RaspberryPi.
3
3
The example code provided by WaveShare is mixed up and doesn't work correctly.
4
4
5
+
# C++ Application
6
+
7
+
Included with this repository is a C++ application, which is now the recommended use of this repository!
8
+
The C++ application uses libgpiod, which is bundled in this repository. Regardless of whether or not libgpiod is found on your system,
9
+
the Makefile generator will always download the correct version of the library and link against it.
10
+
11
+
## Building the Application
12
+
13
+
Unlike in previous versions, the application has been refactored to use CMake as its Makefile generator and build system, instead of using raw compiler commands.
14
+
Building the application is very easy nonetheless.
15
+
16
+
```sh
17
+
# Ensure you're in the `cpp` directory!
18
+
19
+
# Create build directory
20
+
mkdir -p build &&cd build
21
+
22
+
# It doesn't really matter which platform you're on; because of the fallback logic, this should work on both RPi5 and older models
23
+
24
+
cmake .. [-Dchannelselect_RASPI5] # Add the value in brackets if you're planning on running on RPi5.
25
+
26
+
make -j$(($(nproc)-1))# Build with nproc - 1
27
+
```
28
+
29
+
## Usage
30
+
31
+
Using the app is fairly simple, and it provides a simple help text to get you started.
32
+
Some examples are included below:
33
+
34
+
```
35
+
waveshare_channel_select v1.1.0 - A simple application for controlling GPIO pins on modern Linux OSs on RasPi
36
+
37
+
Usage:
38
+
waveshare_channel_select -h
39
+
waveshare_channel_select -e -123 # enable channels 1, 2, and 3
40
+
waveshare_channel_select -d -528 # disable channels 5, 2, and 8 and read the state of channel 7
41
+
waveshare_channel_select -L # read the states of all channels
42
+
43
+
Troubleshooting:
44
+
Permission denied? Is your user in the gpio group? # usermod -aG gpio <myuser>
45
+
Library not found? Try installing lgpiod
46
+
47
+
Options:
48
+
Channel selection:
49
+
--channel1, -1 Channel 1
50
+
--channel2, -2 Look, it's the same up until -8
51
+
...
52
+
--channel8, -8 I'm sure it's self-explanatory at this point
53
+
--all, -a All channels
54
+
55
+
Channel options:
56
+
--enable, -e Enable channel(s)
57
+
--disable, -d Disable channel(s)
58
+
--read, -r Read the channel state
59
+
60
+
General options:
61
+
--list-all, -L List all channels and their current state
62
+
63
+
--help, -h Displays this text and exits
64
+
--version, -v Displays the version information and exits
65
+
```
66
+
5
67
# Bash Script
6
68
7
69
Contained within this repository is a Bash script, which handles setting the GPIO pins, respective to the selected channel.
@@ -32,21 +94,4 @@ If the --help|-h arg is passed, the script will print the help text and exit.
32
94
33
95
# Print help menu
34
96
./channel_select --help
35
-
```
36
-
37
-
# C++ Application
38
-
39
-
Provided with this repository is a simple sample application written in C++, providing the same functionality as the Bash script.
auto line = gpioChip.prepare_request().add_line_settings(gpioChip.get_line_offset_from_name(fmt::format("GPIO{0:d}", channel)), lineSettings).do_request();
auto line = gpioChip.prepare_request().add_line_settings(gpioChip.get_line_offset_from_name(fmt::format("GPIO{0:d}", channel)), lineSettings).do_request();
constexprconstchar* GPIO_CHIP = "/dev/gpiochip0"; //!< This is the chip required for controlling the relay board
18
-
17
+
constexprconstchar* GPIO_CHIP = "/dev/@DEFAULT_GPIOCHIP@"; //!< This is the chip required for controlling the relay board
18
+
constexprconstchar* FALLBACK_GPIO_CHIP = "/dev/@FALLBACK_GPIOCHIP@"; //!< This is the fallback chip required for controlling the relay board on a RaspberrFALLBACK
0 commit comments