0

I was wondering if I could use the GPIO or breadboard to bring in two stereo audio and have one audio output that would switch between the two inputs depending on the time. So essentially 2 in 1 out... audio A and audio B, if time is 9am then the audio A switches to audio B.

Thanks in advance.

  • Note that the topic of driving relays using RPi GPIO pins was discussed last week. – Dmitry Grigoryev Sep 27 '16 at 14:29
2

Yes if you mean that you would like to select A or B as a pass through device. What I mean is if you are just using the Pi as an On/Off switch you can do this with a simple relay. Use your ground from both stereo inputs as the lead to the relay. Then connect the 'A' channel GND to the normally open side of your relay. Connect the 'B' channel GND to the normally closed side. Your program will go something like @ 9am digitalWrite low to your relay pin (switching to channel B). You can do this with a Bash script or Python and WiringPi. https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

Note: Sharing a GND might introduce noise with 2 sources. So you could use 2 relays and open one while closing when your time triggers the program. You can use a cron job to do this part.
http://www.unixgeeks.org/security/newbie/unix/cron-1.html

0

Yes you can. There are a few steps in doing this. They include setting up a sound card with audio input, constructing a relay board and setting up the software on the Pi to operate the gpio control of the relay board. Below is a more detailed description of each part.

The Raspberry Pi has no input. So firstly, you would need a sound card. There is a non-comprehensive list of available sound cards here, some of which have audio inputs.

You can then use a separate add on board (sandwiched with the GPIO sound card) which operates a double pole relay from a GPIO port. It is quite simple to put together such a system with a Relay (and snubbing diode), and a transistor who's base is operated by the GPIO pin of your choice. Connect the relay coil between the 5V power GPIO pin and the collector of the transistor. Connect the transistor's emitter to GND. For example, the kemmet UA2-5SNU could be a suitable relay which is 5V coil rated and is double throw.

Finally, you can run a cron job. Run "crontab -e" with the following line to execute the task at 9 am : 0 9 * * * /home/pi/relaySwitch.sh

Finally create the relaySwitch.sh script with your bash code to set the GPIO pin high (say GPIO 26) :

#!/bin/sh
echo "26" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio26/direction
echo "1" > /sys/class/gpio/gpio26/value

You should modify this starter script to toggle as you would like.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.