I am having a few problems with my script, on a fresh boot of my pi, the GPIO Port goes High and switches my relay when I run this script, however, it doesn't do it after I initially run the script, why would this be?

>>import pygame.mixer
>>from time import sleep
>>import RPi.GPIO as GPIO
>>from sys import exit

GPIO.setup(23, GPIO.IN)
GPIO.setup(18, GPIO.OUT)


sndA = pygame.mixer.Sound("/home/pi/soundboard/EctoSirenStart.wav")
sndB = pygame.mixer.Sound("/home/pi/soundboard/Ectoloop.wav")
sndC = pygame.mixer.Sound("/home/pi/soundboard/EctoStop.wav")
sndD = pygame.mixer.Sound("Ghostbusters.ogg")

soundChannelA = pygame.mixer.Channel(1)
soundChannelB = pygame.mixer.Channel(2)
soundChannelC = pygame.mixer.Channel(1)

print "Siren Ready."

while True:
        if (GPIO.input(23)):
            (GPIO.output(18, False),soundChannelA.play(sndA))
            while (GPIO.input(23)):
            (GPIO.output(18, True),soundChannelA.queue(sndC))
    except KeyboardInterrupt:
  • Does the relay have anything to do with the code? Is the relay connected to the Pi? If it is connected then how is it connected? The code appears to have syntax errors - does it compile? – joan Jul 17 '14 at 7:24
  • my mistake, there was an error in that code, (I have corrected it now), basically what im tring to achieve is turn on a siren (made of three separate wav files) -Working! and also open 4 relays that are connected to 4 separate sets of flashing lights on the top of my ghostbuster ECTO 1 car. the relay is connected to 5v, grd, and GPIO 18. the switch is connected to 3.3v, and the ground is connected to a 10k resistor going to the switch grd and GPIO 23 – Ian Solway Jul 17 '14 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.