LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-12-2017, 03:52 AM   #1
kmvtxx
LQ Newbie
 
Registered: Jun 2017
Posts: 4

Rep: Reputation: Disabled
Automatically change audio output??


Good morning,

For a university project I am working with Gigabyte & Linux which I am not used to at all.
I connected several sensors to arduino, and based on the sensor data I have to play several audio/video files.
I have plugged in a "phone", which is the exact same as normal earbuds, and connected in an HDMI cable with a screen + sound boxes to the Gigabyte as well.

The problem is that, with some particular sensor values, I would like to use the phone as audio output, where for other sensor values the sound should go through the boxes.

Being an absolute beginner with linux, I have NO IDEA how I can achieve this, but it's a MUST for my project.

I really hope there is anyone with some piece of advice for me.
Any comment is welcome! Thanks in advance!
 
Old 06-12-2017, 07:35 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Quote:
Originally Posted by kmvtxx View Post
Good morning,

For a university project I am working with Gigabyte & Linux which I am not used to at all.
I connected several sensors to arduino, and based on the sensor data I have to play several audio/video files.
I have plugged in a "phone", which is the exact same as normal earbuds, and connected in an HDMI cable with a screen + sound boxes to the Gigabyte as well.

The problem is that, with some particular sensor values, I would like to use the phone as audio output, where for other sensor values the sound should go through the boxes.

Being an absolute beginner with linux, I have NO IDEA how I can achieve this, but it's a MUST for my project.

I really hope there is anyone with some piece of advice for me.
Any comment is welcome! Thanks in advance!
Hi kmvtxx and welcome to LQ.

Well, how did you come upon this project? Is it assigned "as is" or is it something you selected?

Because my point is that if it is an assigned project, then it should be guided somewhat by your instructor. And even if it is self-chosen, since you're studying Linux, you have an instructor and they should at least give you some guidance as to what is reasonable for you to tackle.

My impression is that you need to have some of these various sound files play, depending on the inputs from any given sensor.

What's missing is the information as to how these sensors are hooked up to your board. Serial/UART, I2C, SPI, GPIO, or other. At the simplest level, for a beginner, each sensor should be on some sort of sample board and hooked up using a very normal interface, such as USB and then use maybe USB serial to communicate. Next it would have a command set for that serial interface. At the more complex levels, these would need to be custom wired to specific interfaces, such as the SPI bus, or the I2C bus, and there are probably more than one of each of these buses or the pins might be dual use to be capable of both types of serial communications.

Perhaps you can share the history of what led to this project selection, and then discuss how these sensors are physically hooked up and how you expect to talk to them via software.
 
1 members found this post helpful.
Old 06-12-2017, 07:50 AM   #3
kmvtxx
LQ Newbie
 
Registered: Jun 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Hi kmvtxx and welcome to LQ.

Well, how did you come upon this project? Is it assigned "as is" or is it something you selected?

Because my point is that if it is an assigned project, then it should be guided somewhat by your instructor. And even if it is self-chosen, since you're studying Linux, you have an instructor and they should at least give you some guidance as to what is reasonable for you to tackle.

My impression is that you need to have some of these various sound files play, depending on the inputs from any given sensor.

What's missing is the information as to how these sensors are hooked up to your board. Serial/UART, I2C, SPI, GPIO, or other. At the simplest level, for a beginner, each sensor should be on some sort of sample board and hooked up using a very normal interface, such as USB and then use maybe USB serial to communicate. Next it would have a command set for that serial interface. At the more complex levels, these would need to be custom wired to specific interfaces, such as the SPI bus, or the I2C bus, and there are probably more than one of each of these buses or the pins might be dual use to be capable of both types of serial communications.

Perhaps you can share the history of what led to this project selection, and then discuss how these sensors are physically hooked up and how you expect to talk to them via software.
Thank you for your comment.
I am not sure if I will be able to answer your questions.
First of all, the setup is my own idea/initiative.
The person who could advice me about linux is currently unavailable.
I do have experience with Arduino and Processing. I hooked up the sensors via arduino, for example a proximity sensor.
If the sensor values pass the set threshold, Processing (processing.org) get's notified and plays a certain sound or video. As far as I'm concerned, processing has no abilities to automatically choose an audio output.
The communication between Arduino and Processing is serial.

When another sensor, for example a PIR movement sensor, senses movement and becomes HIGH, again processing will be notified, and the other audio output should be used to get the effect of having the phone ringing out loud, and then hearing someone talk through the phone.

I must say that the more I think and write about it, the more I am starting to think that I should let the idea go.
I just don't know any alternatives at this certain moment so I hope you still have some advice about making it work.

Thank you again!
 
Old 06-12-2017, 08:42 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Quote:
Originally Posted by kmvtxx View Post
Thank you for your comment.
I am not sure if I will be able to answer your questions.
First of all, the setup is my own idea/initiative.
The person who could advice me about linux is currently unavailable.
I do have experience with Arduino and Processing. I hooked up the sensors via arduino, for example a proximity sensor.
If the sensor values pass the set threshold, Processing (processing.org) get's notified and plays a certain sound or video. As far as I'm concerned, processing has no abilities to automatically choose an audio output.
The communication between Arduino and Processing is serial.

When another sensor, for example a PIR movement sensor, senses movement and becomes HIGH, again processing will be notified, and the other audio output should be used to get the effect of having the phone ringing out loud, and then hearing someone talk through the phone.

I must say that the more I think and write about it, the more I am starting to think that I should let the idea go.
I just don't know any alternatives at this certain moment so I hope you still have some advice about making it work.

Thank you again!
The thing is, you are answering differently than my perception. Not a bad thing, I was just thinking slightly differently about things.

What are you calling "processing"? Is that a service, or just your term for the Linux CPU and the fact that a program is doing something, where this program is something that eventually you'll need to write?

One sensor is hooked up serial. Good, you can open a terminal and talk to it using a serial emulator and then see information come from it. You can use that within a program by attaching to that serial port and then processing this information.

The other sensor since you say High/Low, then seems to be on a GPIO? General Purpose Input/Output? Then you need to access the GPIO pins using a library call from Linux which will help you read or modify the pin values. Plus you may need to configure them to be explicitly either an input or an output. But, is my assumption there correct?

Just to advise, this is not some "one hour" project, it will likely take you a few hours to get some level of results where you learn things. Probably a few days or the better part of a week to get things much farther along. It's not unusual when you are very new to this. Therefore I'd try to learn things in the meantime, but for when you can meet up with your instructor,you can perhaps discuss with them the merits or drawbacks of your project choice.

It may be a fine project for you, just you also may have to put in a significant amount of time to achieve completion.

Or if it was supposed to be a very quick project, then perhaps it is a bit too far reaching.
 
Old 06-12-2017, 09:04 AM   #5
kmvtxx
LQ Newbie
 
Registered: Jun 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
The thing is, you are answering differently than my perception. Not a bad thing, I was just thinking slightly differently about things.

What are you calling "processing"? Is that a service, or just your term for the Linux CPU and the fact that a program is doing something, where this program is something that eventually you'll need to write?

One sensor is hooked up serial. Good, you can open a terminal and talk to it using a serial emulator and then see information come from it. You can use that within a program by attaching to that serial port and then processing this information.

The other sensor since you say High/Low, then seems to be on a GPIO? General Purpose Input/Output? Then you need to access the GPIO pins using a library call from Linux which will help you read or modify the pin values. Plus you may need to configure them to be explicitly either an input or an output. But, is my assumption there correct?

Just to advise, this is not some "one hour" project, it will likely take you a few hours to get some level of results where you learn things. Probably a few days or the better part of a week to get things much farther along. It's not unusual when you are very new to this. Therefore I'd try to learn things in the meantime, but for when you can meet up with your instructor,you can perhaps discuss with them the merits or drawbacks of your project choice.

It may be a fine project for you, just you also may have to put in a significant amount of time to achieve completion.

Or if it was supposed to be a very quick project, then perhaps it is a bit too far reaching.
It's a 5 month project so that's okay. Processing is software that can communicate with Arduino software.
I receive the values from my different sensors in Arduino, and send them to the processing software. I can read those, and I know how to connect an action to those values like playing a video. This is not the problem.
Are you saying that I should access the sensorpins by Linux instead of arduino to be able to be able to change the audio output?
 
Old 06-12-2017, 10:53 AM   #6
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237
Blog Entries: 2

Rep: Reputation: Disabled
MPD + ncmpcpp (popular CLI music player with stereo redirection capabilities)
 
Old 06-12-2017, 11:09 AM   #7
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,937

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Quote:
Originally Posted by kmvtxx View Post
It's a 5 month project so that's okay. Processing is software that can communicate with Arduino software.
I receive the values from my different sensors in Arduino, and send them to the processing software. I can read those, and I know how to connect an action to those values like playing a video. This is not the problem.
Are you saying that I should access the sensorpins by Linux instead of arduino to be able to be able to change the audio output?
Wouldn't it be easier to get the Arduino to do the sensing & then get it to illuminate a LED, if successful?
You could do the Linux thing after you've proved the sensor/Arduino side of things.

I think you will find the Ubuntu biased magazine "Full Circle" to be useful - see http://fullcirclemagazine.org/tag/arduino/ for a selection of issues.
 
1 members found this post helpful.
Old 06-12-2017, 12:07 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Quote:
Originally Posted by kmvtxx View Post
It's a 5 month project so that's okay. Processing is software that can communicate with Arduino software.
I receive the values from my different sensors in Arduino, and send them to the processing software. I can read those, and I know how to connect an action to those values like playing a video. This is not the problem.
Are you saying that I should access the sensorpins by Linux instead of arduino to be able to be able to change the audio output?
I'm better understanding now, which is that you have an Arduino development board where you are writing firmware that you then communicate to the Linux system with. Therefore your connection to Linux is serial UART? If so, then the suggestion here:
Quote:
Originally Posted by JeremyBoden View Post
Wouldn't it be easier to get the Arduino to do the sensing & then get it to illuminate a LED, if successful?
You could do the Linux thing after you've proved the sensor/Arduino side of things.

I think you will find the Ubuntu biased magazine "Full Circle" to be useful - see http://fullcirclemagazine.org/tag/arduino/ for a selection of issues.
I agree with JeremyBoden's advice here, which is to take care of the firmware on the Arduino first and then concentrate on the Linux side to play music files. Since you'd be writing Arduino firmware you can control what you send over the serial port, or accept. Sounds like a simple ASCII readable protocol, one or two characters of information back and forth. Once you define that, and the baud rate, you can then listen on the Linux system or even send data for controls to the Arduino, and all the Linux processing element does is have a receive state machine which says, "When you get 'A', play sound <blah-blah>", and so forth.
 
1 members found this post helpful.
Old 06-12-2017, 01:07 PM   #9
kmvtxx
LQ Newbie
 
Registered: Jun 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks to you both, I hope it will work out! At least your replies have been very helpful.
 
Old 06-12-2017, 01:42 PM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141
I'm a little confused. The OP's question seems to be completely unrelated to the Arduino, its sensors, its comms interface, etc. From what I can tell, he has already done all of that, it's working, it's irrelevant. All he's asking is how to play a music file on Linux through a specific audio interface, right? So why all of the questions about Arduino, serial ports, sensor types and interfaces, etc?

OP - At least some, if not most programs that can play music files on Linux allow you to specify the audio device to use. For example, mplayer has the -ao flag, you just need to know the name of the device to give it. On my laptop, when I want to play a video with the sound going to hdmi instead of the internal speakers, I run "mplayer -ao alsa:device=hw=0.7 <file>".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] change audio output socket Bazzaah Slackware 4 10-09-2014 07:35 AM
Record audio output / audio that is played in a web browser glupa4e Slackware 11 05-21-2013 12:08 AM
[SOLVED] No sound output from audio players but audio from flash exists Janus_Hyperion Linux - Hardware 1 09-27-2012 08:52 AM
audio output device changes to 'dummy output' Joshwaaa Linux - Software 1 04-02-2010 10:03 PM
[SOLVED] Onboard Audio (hda_intel) for Mic Input and Soundcard (ca0106) for Audio Output? snowdonkey Linux - General 1 07-11-2009 03:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration