Skip to content

This repository contains example code useful when using the WaveShare 8-channel relay module for the RaspberryPi. The example code provided by WaveShare is mixed up and doesn't work correctly.

License

Notifications You must be signed in to change notification settings

SimonCahill/waveshare_8ch_relay_examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

waveshare_8ch_relay_examples

This repository contains example code useful when using the WaveShare 8-channel relay module for the RaspberryPi. The example code provided by WaveShare is mixed up and doesn't work correctly.

Bash Script

Contained within this repository is a Bash script, which handles setting the GPIO pins, respective to the selected channel. There are a total of eight relays on the board, which are designated as "channels".

The script takes two arguments:

  • The channel number (1-8)
  • The state (0/1, on/off, true/false)
  • --help

The channel may be prefixed with "ch" or "CH", or may simply be passed to the script. The order in which the arguments are passed does not affect the execution of the script.

If the --help|-h arg is passed, the script will print the help text and exit.

Example usage

# Enable channel 1
./channel_select ch1 on

# Enable channel 3
./channel_select on 3

# Disable channel 8
./channel_select false CH8

# Print help menu
./channel_select --help

C++ Application

Provided with this repository is a simple sample application written in C++, providing the same functionality as the Bash script.

Building

g++ -std=c++17 -o channel_select cpp/channel_select.cpp

Usage

The C++ example provides the same features/functionality and arguments as the Bash script.
They are virtually 1:1 ports of each other.