Difference between revisions of "Install RPi relay board"
(→WiringPi) |
|||
Line 7: | Line 7: | ||
* python scripts | * python scripts | ||
− | = | + | = Access the switches = |
− | Ckeck the [http://www.waveshare.com/wiki/Libraries_Installation_for_RPi#Install_WiringPi_Library download link] | + | Ckeck the [http://www.waveshare.com/wiki/Libraries_Installation_for_RPi#Install_WiringPi_Library download link] |
− | + | for the following <code>wget</code> command and install the library: | |
− | + | ||
su | su | ||
cd /tmp/ | cd /tmp/ | ||
Line 19: | Line 18: | ||
chmod 777 build | chmod 777 build | ||
./build | ./build | ||
+ | which gpio | ||
Check the installation: | Check the installation: | ||
Line 35: | Line 35: | ||
sleep 1 | sleep 1 | ||
done | done | ||
+ | |||
+ | = Install xPL switches controller = | ||
+ | |||
+ | Download the [http://www.dspc.ch/xPL/Downloads/xpl-piSwitch.pl switches controller] script. | ||
+ | |||
+ | Move the script to xPL scripts directory: | ||
+ | SCRIPTS_BASE_DIR=/home/control/Documents/Controls | ||
+ | mv xpl-piSwitch.pl $SCRIPTS_BASE_DIR | ||
+ | chown control:users $SCRIPTS_BASE_DIR/*.pl | ||
+ | chmod 775 $SCRIPTS_BASE_DIR/*.pl | ||
+ | |||
+ | = Test xPL switches controller = | ||
+ | |||
+ | Test it on a [[install BeagleBone|BeagleBone]]: | ||
+ | su control | ||
+ | SCRIPTS_BASE_DIR=/home/control/Documents/Controls | ||
+ | $SCRIPTS_BASE_DIR/xpl-piSwitch.pl -vn loungeAmps | ||
+ | |||
+ | Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol: | ||
+ | SCRIPTS_BASE_DIR=/home/control/Documents/Controls | ||
+ | $SCRIPTS_BASE_DIR/xpl-monitor.pl -vf | ||
+ | |||
+ | Open a 3rd terminal window (on any machine with xPL installed) and control the switches: | ||
+ | SCRIPTS_BASE_DIR=/home/control/Documents/Controls | ||
+ | $SCRIPTS_BASE_DIR/xpl-send.pl -v -d dspc-switch.loungeAmps -c control.request command=request | ||
+ | $SCRIPTS_BASE_DIR/xpl-send.pl -v -d dspc-switch.loungeAmps -c control.basic outlet=1 command=on | ||
+ | $SCRIPTS_BASE_DIR/xpl-send.pl -v -d dspc-switch.loungeAmps -c control.basic outlet=1 command=off | ||
+ | |||
+ | The first <code>xpl-send</code> command asks for the status of the switches. | ||
+ | The answer is seen in the xPL traffic monitor. | ||
+ | |||
+ | = Launch the xPL switches controller at startup = | ||
+ | |||
+ | The xPL switches controller is to be launched after the xPL hub. | ||
+ | |||
+ | == Ubuntu == | ||
+ | |||
+ | On Ubuntu, the xPL switches controller starts-up once <code>xpl-hub_started</code> has been emitted. | ||
+ | |||
+ | Edit <code>/etc/init/xpl-piSwitch.conf</code>: | ||
+ | ################################################################################ | ||
+ | # xPL Raspberry Pi switch, controls 3 relays | ||
+ | # | ||
+ | description "xPL RPi switch" | ||
+ | version "1.0" | ||
+ | author "Francois Corthay" | ||
+ | |||
+ | #------------------------------------------------------------------------------- | ||
+ | # Configuration variables | ||
+ | # | ||
+ | env SCRIPTS_DIR='/home/control/Documents/Controls' | ||
+ | env SCRIPT_NAME='xpl-piSwitch.pl' | ||
+ | env PARAMETERS='-n loungeAmps' | ||
+ | |||
+ | #------------------------------------------------------------------------------- | ||
+ | # Start and stop conditions | ||
+ | # | ||
+ | start on xpl-hub_started | ||
+ | stop on shutdown | ||
+ | respawn | ||
+ | setuid control | ||
+ | setgid users | ||
+ | |||
+ | #------------------------------------------------------------------------------- | ||
+ | # Start daemon | ||
+ | # | ||
+ | exec $SCRIPTS_DIR/$SCRIPT_NAME $PARAMETERS | ||
+ | |||
+ | Start the device and test it: | ||
+ | su root | ||
+ | service xpl-piSwitch start | ||
+ | service xpl-piSwitch status | ||
+ | initctl list | grep xpl | ||
+ | ps aux | grep -i xpl | grep -v grep | sed 's/.*\/Controls\///' | ||
[[Category: all]] [[Category: install]] [[Category: xPL]] | [[Category: all]] [[Category: install]] [[Category: xPL]] |
Revision as of 14:31, 31 March 2017
The Waveshare RPi Relay Board houses 3 relays controlled by Raspberry Pi General-Purpose Input/Outputs (GPIOs).
They can be controlled by:
- shell commands built from the WiringPi libraries
- C-programs compiled with the C library for Raspberry Pi
- python scripts
Contents
Access the switches
Ckeck the download link
for the following wget
command and install the library:
su cd /tmp/ wget http://www.waveshare.com/w/upload/f/f3/WiringPi.tar.gz tar -xvzf WiringPi.tar.gz cd wiringPi/ chmod 777 build ./build which gpio
Check the installation:
gpio -v
Test the relays:
PIN=25 gpio mode $PIN output ; gpio write $PIN 0 ; sleep 1 ; gpio write $PIN 1 for PIN in 25 28 29; do echo driving pin $PIN gpio mode $PIN output gpio write $PIN 0 sleep 1 gpio write $PIN 1 sleep 1 done
Install xPL switches controller
Download the switches controller script.
Move the script to xPL scripts directory:
SCRIPTS_BASE_DIR=/home/control/Documents/Controls mv xpl-piSwitch.pl $SCRIPTS_BASE_DIR chown control:users $SCRIPTS_BASE_DIR/*.pl chmod 775 $SCRIPTS_BASE_DIR/*.pl
Test xPL switches controller
Test it on a BeagleBone:
su control SCRIPTS_BASE_DIR=/home/control/Documents/Controls $SCRIPTS_BASE_DIR/xpl-piSwitch.pl -vn loungeAmps
Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol:
SCRIPTS_BASE_DIR=/home/control/Documents/Controls $SCRIPTS_BASE_DIR/xpl-monitor.pl -vf
Open a 3rd terminal window (on any machine with xPL installed) and control the switches:
SCRIPTS_BASE_DIR=/home/control/Documents/Controls $SCRIPTS_BASE_DIR/xpl-send.pl -v -d dspc-switch.loungeAmps -c control.request command=request $SCRIPTS_BASE_DIR/xpl-send.pl -v -d dspc-switch.loungeAmps -c control.basic outlet=1 command=on $SCRIPTS_BASE_DIR/xpl-send.pl -v -d dspc-switch.loungeAmps -c control.basic outlet=1 command=off
The first xpl-send
command asks for the status of the switches.
The answer is seen in the xPL traffic monitor.
Launch the xPL switches controller at startup
The xPL switches controller is to be launched after the xPL hub.
Ubuntu
On Ubuntu, the xPL switches controller starts-up once xpl-hub_started
has been emitted.
Edit /etc/init/xpl-piSwitch.conf
:
################################################################################ # xPL Raspberry Pi switch, controls 3 relays # description "xPL RPi switch" version "1.0" author "Francois Corthay" #------------------------------------------------------------------------------- # Configuration variables # env SCRIPTS_DIR='/home/control/Documents/Controls' env SCRIPT_NAME='xpl-piSwitch.pl' env PARAMETERS='-n loungeAmps' #------------------------------------------------------------------------------- # Start and stop conditions # start on xpl-hub_started stop on shutdown respawn setuid control setgid users #------------------------------------------------------------------------------- # Start daemon # exec $SCRIPTS_DIR/$SCRIPT_NAME $PARAMETERS
Start the device and test it:
su root service xpl-piSwitch start service xpl-piSwitch status initctl list | grep xpl ps aux | grep -i xpl | grep -v grep | sed 's/.*\/Controls\///'