Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5359

Python • Script for waveshare relay module

$
0
0
Hi all, Just a little problem I am hoping someone can solve for me. I am new to all this, so please bear with me. I have a pi3B with a 3 relay hat fitted above a a pi DAC HAT. I want to control my monitor, Amplifier, and Lights with the relay board. The relays are rated at 10amp 250v so I assume they are OK with this set up. The idea being that when I power up the pi the relays will close and everything will come on, and when I power down, the relays will open, and everything will go off. My problem is that I have adapted a python script to do this, but only the first relay operates. I am sure I am missing something in the script. Any help? The script is below.

#!/usr/bin/env python3

import RPi.GPIO as GPIO

relay_ch1 = 26
relay_ch2 = 20
relay_ch3 = 21

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)

GPIO.setup(relay_ch1, GPIO.OUT)
GPIO.setup(relay_ch2, GPIO.OUT)
GPIO.setup(relay_ch3, GPIO.OUT)

GPIO.output(relay_ch1, GPIO.LOW)
GPIO.output(relay_ch2, GPIO.LOW)
GPIO.output(relay_ch3, GPIO.LOW)

GPIO.output(relay_ch1, GPIO.HIGH)
GPIO.output(relay_ch2, GPIO.HIGH)
GPIO.output(relay_ch3, GPIO.HIGH)

GPIO.cleanup()

Statistics: Posted by barrychilds — Fri Jun 21, 2024 8:51 am



Viewing all articles
Browse latest Browse all 5359

Trending Articles