Difference between revisions of "ECE497 Project - Andriod App to Speaker"

From eLinux.org
Jump to: navigation, search
(Installation Instructions)
m (Removed ece497)
 
(39 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:ECE497 |PA]]
 
 
[[Category:ECE497Fall2018 |PA]]
 
[[Category:ECE497Fall2018 |PA]]
 
{{YoderHead}}
 
{{YoderHead}}
Line 29: Line 28:
 
== Executive Summary ==
 
== Executive Summary ==
  
The goal of this project is to interface a simple android application with the BeagleBone. Songs will be able to be chosen and controlled from the Android App and played through a speaker connected to the bone either directly or through Bluetooth. We are working to support possibly having the option to choose either through the headphones or through a  
+
The goal of this project is to interface a simple android application with the BeagleBone. Songs will be able to be chosen/downloaded and controlled from the Android App and played through a speaker connected to the bone via a USB dongle. We had some features in mind that we were unable to implement due to various roadblocks in the project. One feature was the option to play through a Bluetooth speaker connected to the Bone. Another feature that would be neat to include is playing songs through YouTube so you can have a wider range of options to play.
Bluetooth speaker. Another feature that would be neat to include is playing songs through YouTube so you can have a wider range of options to play.
 
  
During the project we have run in various roadblocks. The first roadblock was trying to get a Bluetooth speaker to connect. This is a problem we are still investigating. The Bluetooth dongle will connect once to the speaker but after that it will 'connect' for a second then disconnect. Another roadblock we encounter was the music playback was choppy and skipped at some points. This was solved by manually setting the sampling rate.
+
== Installation Instructions ==
  
== Packaging ==
+
* Link to GitHub project:  [https://github.com/boxetham/EmbeddedLinuxMusicAppProject https://github.com/boxetham/EmbeddedLinuxMusicAppProject].
If you have hardware, consider [http://cpprojects.blogspot.com/2013/07/small-build-big-execuition.html Small Build, Big Execuition] for ideas on the final packaging.
 
  
== Installation Instructions ==
+
* To get the app you will need to:
 +
** Have an Android device
 +
** Enable applications from unknown sources on that device (this can be done in the settings - settings -> applications -> enable unknown sources)
 +
** Navigate to the 'AppToSpeaker' directory of our project
 +
** Get the 'app-debug.apk' file from the PC onto the device, either through direct transfer or email
 +
** Once the app is on the device, in the file system navigate to the folder containing the .apk file, click on it, and hit 'install'
 +
** The app will then be downloaded installed on the device
 +
 
 +
* USB Audio Dongle to connect the speaker to the bone
 +
**[https://smile.amazon.com/Sabrent-External-Sound-Box-USB-SBCV/dp/B002R33VWW/ref=sr_1_16?ie=UTF8&qid=1542089412&sr=8-16&keywords=sabrent+usb+audio+adapter Sound Adapter on Amazon]
  
Give step by step instructions on how to install your project. 
 
  
* Link to GitHub project:  [https://github.com/boxetham/EmbeddedLinuxMusicAppProject https://github.com/boxetham/EmbeddedLinuxMusicAppProject].
+
Here are some things we found when trying to implement Bluetooth (ultimately we were not able to get the Bluetooth working but here are some things to check if you are working on Bluetooth):
* Be sure your README.md is includes an up-to-date and clear description of your project so that someone who comes across you git repository can quickly learn what you did and how they can reproduce it.
 
* Include any additional packages installed via '''apt'''.  Include '''install.sh''' and '''setup.sh''' files.
 
* Include kernel mods.
 
* If there is extra hardware needed, include links to where it can be obtained.
 
  
 +
* Bluetooth module to connect to the Bluetooth speaker
 +
** [https://www.amazon.com/gp/product/B009ZIILLI/ref=oh_aui_detailpage_o00_s01?ie=UTF8&psc=1 Bluetooth Module on Amazon]
  
* If bluetoothctl gives you waiting to connect to bluetoothd:  
+
* If bluetoothctl gives you "waiting to connect to bluetoothd":  
 
** sudo modprobe btusb
 
** sudo modprobe btusb
 
** sudo systemctl start bluetooth
 
** sudo systemctl start bluetooth
 +
** Also try restarting the device
  
* To get the app you will need to download Android Studio: [https://developer.android.com/studio/ https://developer.android.com/studio/]
+
* Commands to run to install various packages you will need:  
** We recommend doing that part on a Windows machine
+
** Run the install.sh script (./install.sh) to install all the necessary programs, libraries, and packages.
** You will also need to make sure your Android device has USB debugging enabled. [https://www.makeuseof.com/tag/what-is-usb-debugging-mode-on-android-makeuseof-explains/ Instructions about enabling USB debugging here]
 
  
* Bluetooth module to connect to the Bluetooth speaker
+
* Commands to run to pair and connect to a Bluetooth device:
** [https://www.amazon.com/gp/product/B009ZIILLI/ref=oh_aui_detailpage_o00_s01?ie=UTF8&psc=1 Bluetooth Module on Amazon]
+
** bluetoothctl
 +
** agent on
 +
** default-agent
 +
** scan on (wait until you see the device you want to connect to)
 +
** scan off
 +
** trust XX:XX:XX:XX:XX:XX
 +
** pair XX:XX:XX:XX:XX:XX
 +
** connect XX:XX:XX:XX:XX:XX
  
 
== User Instructions ==
 
== User Instructions ==
  
Once everything is installed, how do you use the program?  Give details here, so if you have a long user manual, link to it here.
+
Everything in this program is controlled from the Android device. Insert the USB Audio Dongle into one of the USB ports on the BeagleBone. Connect a speaker to the dongle using an auxiliary cable. Run the setup.sh file (./setup.sh) to make the BeagleBone discoverable via Bluetooth. The BeagleBone must be discoverable for the phone to find it. If the phone is unable to find the BeagleBone, the discoverable mode may have timed out, simply run setup.sh again. The BeagleBone should be running the perky_blue.py (may have to run as root, 'sudo ./perky_blue.py') program found in the Git repo under the AppToSpeaker folder. Open the Android app. Start by selecting "discover" and then selecting your BeagleBone device to Bluetooth connect to. Select the song to play once the BeagleBone is connected to the device. You can also manually input a file to play that is not one of the songs listed. To do this, hit the "Play Custom Song" button, then enter the file name without the extension and press enter. If entered correctly, the song should begin playing and can be controlled from the app. If you want to download a new song onto the bone to play, press the "Download Song" button and enter the link to download the mp3 file. The bone must have an internet connection for this feature to work properly. Once the song is downloaded, you can use the "Play Custom Song" button to input the file name and play the song. Once songs are playing, they can be controlled by the buttons at the bottom of the application. From left to right, the buttons are: Pause, Play, Stop, Volume Down, and Volume Up. Closing the Android Application will end the program on the bone.
  
Use the program by building the Android application onto an Android device. Everything in this program is controlled from the Android device. The BeagleBone should be running the perky_blue.py program found in the Git repo under the AppToSpeaker folder. Start by selecting "discover" and then selecting your BeagleBone device to Bluetooth connect to. Select the song to play once the BeagleBone is connected to the device.
+
== Highlights ==
  
== Highlights ==
+
Our project lets you control music on the Bone from your phone. This uses a Bluetooth connect to send commands to the Beagle from your phone. You have all the commands of a basic stereo with the additional ability to choose new music to download.
  
Here is where you brag about what your project can do.
+
Note: The app was designed on a phone with a 6 inch display, devices with smaller displays may have a more compact layout.
 +
<div><ul>
 +
<li style="display: inline-block;"> [[File:Screenshot 20181107-124103.png|thumb|none|180px|Basic screen when you open the app]] </li>
 +
<li style="display: inline-block;"> [[File:Screenshot 20181107-124110.png|thumb|none|180px|Trying to discover Bluetooth devices]] </li>
 +
<li style="display: inline-block;"> [[File:Screenshot 20181107-124257.png|thumb|none|180px|Connected to the BeagleBone via Bluetooth]] </li>
 +
<li style="display: inline-block;"> [[File:Screenshot 20181107-124310.png|thumb|none|180px|Playing a song]] </li>
 +
<li style="display: inline-block;"> [[File:Screenshot 20181107-124649.png|thumb|none|180px|Playing custom music file]] </li>
 +
<li style="display: inline-block;"> [[File:Screenshot 20181107-124926.png|thumb|none|180px|Choose file to download]] </li>
 +
<li style="display: block;"> [[File:Buttonsad.jpg|thumb|none|180px|This is the new button layout at the bottom of the app]] </li>
 +
<li style="display: block;"> [[File:46221938 1945675722195161 5834422474128752640 n.jpg|thumb|none|180px|This is what the basic set up is]] </li>
 +
</ul></div>
  
Include a [http://www.youtube.com/ YouTube] demo the audio description.
+
Here is a [https://www.youtube.com/watch?v=ummQGmSH-D0 YouTube] demo the app.
  
 
== Theory of Operation ==
 
== Theory of Operation ==
  
Give a high level overview of the structure of your software.  Are you using GStreamer?  Show a diagram of the pipeline.  Are you running multiple tasks?  Show what they do and how they interact.
+
The basic structure of our program is an Android app sends instructions to an application running on the BeagleBone which controls the music. The app first 'discovers' the BeagleBone and connects to it via Bluetooth. Then, the user can select to play, pause, resume, or stop playing different songs. The user can also control the volume. The BeagleBone controls the music according to the command using mplayer. The audio output plays through a headset. Below you can see a diagram on the interaction of different parts of the system.  
 
 
The basic structure of our program is an Android app sends instructions to an application running on the BeagleBone. The app first 'discovers' the BeagleBone and connects to it via Bluetooth. Then, the user can select to play, pause, resume, or stop playing different songs. The BeagleBone controls the music according to the command using mplayer. The audio output plays through the Bluetooth speaker or a headset, whichever one is currently selected by the mplayer audio driver. Below you can see a diagram on the interaction of different parts of the system.  
 
 
[[File:SequenceDiagram2.png|thumb|This is the basic flow of the program.]]
 
[[File:SequenceDiagram2.png|thumb|This is the basic flow of the program.]]
  
Line 83: Line 101:
 
* Wrote App - Trey
 
* Wrote App - Trey
 
* Using mplayer to play, pause, resume, and stop music, in python script - Anne
 
* Using mplayer to play, pause, resume, and stop music, in python script - Anne
* Using mplayer to play music from online - team effort (in progress)
+
* Ability to download music from online - Trey
* Connecting beaglebone black to bluetooth speaker - Anne (in progress)
+
* Using mplayer to play custom music files on the BeagleBone - team effort
* Solving choppyness of mplayer when playing music - mostly Trey, little bit Anne
+
* Connecting beaglebone black to bluetooth speaker - Anne (never figured out a solution)
 +
* Solving choppyness of mplayer when playing music - mostly Trey, little help from Anne
 +
* Documentation - Anne, little help from Trey
  
 
== Future Work ==
 
== Future Work ==
  
Suggest addition things that could be done with this project.
+
Here are some ideas that could be cool to implement in the future:
  
* Have a way to dynamically load music to the Beagle from the app
+
* Add newly downloaded music to the list in the app
 
* Play music on multiple audio outputs at the same time
 
* Play music on multiple audio outputs at the same time
 
* Have a display change with the music playing
 
* Have a display change with the music playing
 +
* Finish Bluetooth speaker effort
  
 
== Conclusions ==
 
== Conclusions ==
  
This project presented some interesting challenges. Using mplayer in the Python application cause the output of the audio to initially skip at some points. We tried many different things to solve this but ultimately the issue was the sampling rate used during playback. Overriding this setting caused the audio to sound a lot better. Another issue we had was getting the Bluetooth set up. Initially, we didn't know that we needed to use a Bluetooth dongle, so it was a lot of work before finally realizing we needed to purchase that. After getting the dongle, the work we did initially worked to connect to the speaker. Then, the BeagleBone stopped connecting to the speaker after turning off the Beagle and turning it back on. We tried a different dongle and installing different packages to monitor Bluetooth, but so far no luck.  
+
This project presented some interesting challenges. Using mplayer in the Python application cause the output of the audio to initially skip at some points. We tried many different things to solve this. The main solutions we tried we changing the command to include different optional settings. Many of these things were similar to manipulating the cache size and the amount of data read in before playback begins. Ultimately the issue was the sampling rate used during playback. Overriding this setting caused the audio to sound a lot better.  
 +
 
 +
Another issue we had was getting the Bluetooth set up. Initially, we didn't know that we needed to use a Bluetooth dongle with the BeagleBone Black, so it was a lot of work before finally realizing we needed to purchase that. Initially, without the dongle, the black was just telling us there was no controller for Bluetooth so it was just always "waiting to connect to bluetoothd". After getting the dongle we still needed to run the the commands listed above to get the module for Bluetooth and start it up. After this setup we began trying to connect the speaker. While the pairing process was successful, the BeagleBone would not connect to the speaker. We kept getting the error "Failed to connect: org.bluez.Error.Failed whenever we tried to run the connect command. We tried a different dongle and installing different packages to monitor Bluetooth, but no luck. Some insight that we have for this problem in the future is that there are different Bluetooth protocols and we think that maybe we need the Bluetooth with the speaker is not compatible with the BeagleBone Bluetooth. This is only a hunch as we could find no information on this topic. Also, another group working with Bluetooth for audio output said the Bluetooth connection only seemed to be reliable if there was something going on constantly (playing music always).
 +
 
 +
Since we were able to have the phone connect via Bluetooth to the BeagleBone, we tried to implement a similar system with another speaker. We tried to set up one Bone to connect to another via Bluetooth then have each BeagleBone drive a different output. We used a similar script to the script that was setting up the Bluetooth connection between the phone and the BeagleBone. After working on this idea, it seems to us that the BeagleBone does seem to set up a connection well. The phone to BeagleBone connection is set up initially by the phone "discovering" and connecting with the Bone. When the Bone tries to do a similar thing with any other system we see many errors. We never found what is causing this behavior but we know that you can set up a connection from the BeagleBone. When looking over the various groups for the Bone with similar topics we found that many people were having this issue of connectivity with the Bone without luck of a solution.  
  
Besides these two hiccups, creation of the app to outputting sound went smoothly. The project allowed us to experiment with different peripherals that we thought could make an interesting project. Some things that would be interesting to pursue is sending the music files to the BeagleBone so that you could play any song that you had on your phone. There might also be a way to get the music from other apps to play on the Beagle (basically just use the Beagle as the audio out for the phone). Overall, while there were some difficult parts, we are happy with the outcome of the system as it presented us new ways to connect to and use the BeagleBone.  
+
Besides these hiccups, creation of the app to outputting sound went smoothly. The audio ended up just being driven by an audio dongle in the BeagleBone. The project allowed us to experiment with different peripherals that we thought could make an interesting project. We found new things along the way that we were unaware of that we were able to bring together to make a functioning system. Some things that would be interesting to pursue is sending the music files to the BeagleBone so that you could play any song that you had on your phone. There is also probably a way to get the music from other apps to play on the Beagle (basically just use the Beagle as the audio out for the phone). Overall, while there were some difficult parts, we are happy with the outcome of the system as it presented us new ways to connect to and use the BeagleBone.  
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Latest revision as of 08:14, 19 October 2019

thumb‎ Embedded Linux Class by Mark A. Yoder


Team members: Anne Boxeth, Trey Lewis

Grading Template

I'm using the following template to grade. Each slot is 10 points. 0 = Missing, 5=OK, 10=Wow!

00 Executive Summary
00 Installation Instructions 
00 User Instructions
00 Highlights
00 Theory of Operation
00 Work Breakdown
00 Future Work
00 Conclusions
00 Demo
00 Late
Comments: I'm looking forward to seeing this.

Score:  10/100

(Inline Comment)

Executive Summary

The goal of this project is to interface a simple android application with the BeagleBone. Songs will be able to be chosen/downloaded and controlled from the Android App and played through a speaker connected to the bone via a USB dongle. We had some features in mind that we were unable to implement due to various roadblocks in the project. One feature was the option to play through a Bluetooth speaker connected to the Bone. Another feature that would be neat to include is playing songs through YouTube so you can have a wider range of options to play.

Installation Instructions

  • To get the app you will need to:
    • Have an Android device
    • Enable applications from unknown sources on that device (this can be done in the settings - settings -> applications -> enable unknown sources)
    • Navigate to the 'AppToSpeaker' directory of our project
    • Get the 'app-debug.apk' file from the PC onto the device, either through direct transfer or email
    • Once the app is on the device, in the file system navigate to the folder containing the .apk file, click on it, and hit 'install'
    • The app will then be downloaded installed on the device


Here are some things we found when trying to implement Bluetooth (ultimately we were not able to get the Bluetooth working but here are some things to check if you are working on Bluetooth):

  • If bluetoothctl gives you "waiting to connect to bluetoothd":
    • sudo modprobe btusb
    • sudo systemctl start bluetooth
    • Also try restarting the device
  • Commands to run to install various packages you will need:
    • Run the install.sh script (./install.sh) to install all the necessary programs, libraries, and packages.
  • Commands to run to pair and connect to a Bluetooth device:
    • bluetoothctl
    • agent on
    • default-agent
    • scan on (wait until you see the device you want to connect to)
    • scan off
    • trust XX:XX:XX:XX:XX:XX
    • pair XX:XX:XX:XX:XX:XX
    • connect XX:XX:XX:XX:XX:XX

User Instructions

Everything in this program is controlled from the Android device. Insert the USB Audio Dongle into one of the USB ports on the BeagleBone. Connect a speaker to the dongle using an auxiliary cable. Run the setup.sh file (./setup.sh) to make the BeagleBone discoverable via Bluetooth. The BeagleBone must be discoverable for the phone to find it. If the phone is unable to find the BeagleBone, the discoverable mode may have timed out, simply run setup.sh again. The BeagleBone should be running the perky_blue.py (may have to run as root, 'sudo ./perky_blue.py') program found in the Git repo under the AppToSpeaker folder. Open the Android app. Start by selecting "discover" and then selecting your BeagleBone device to Bluetooth connect to. Select the song to play once the BeagleBone is connected to the device. You can also manually input a file to play that is not one of the songs listed. To do this, hit the "Play Custom Song" button, then enter the file name without the extension and press enter. If entered correctly, the song should begin playing and can be controlled from the app. If you want to download a new song onto the bone to play, press the "Download Song" button and enter the link to download the mp3 file. The bone must have an internet connection for this feature to work properly. Once the song is downloaded, you can use the "Play Custom Song" button to input the file name and play the song. Once songs are playing, they can be controlled by the buttons at the bottom of the application. From left to right, the buttons are: Pause, Play, Stop, Volume Down, and Volume Up. Closing the Android Application will end the program on the bone.

Highlights

Our project lets you control music on the Bone from your phone. This uses a Bluetooth connect to send commands to the Beagle from your phone. You have all the commands of a basic stereo with the additional ability to choose new music to download.

Note: The app was designed on a phone with a 6 inch display, devices with smaller displays may have a more compact layout.

  • Basic screen when you open the app
  • Trying to discover Bluetooth devices
  • Connected to the BeagleBone via Bluetooth
  • Playing a song
  • Playing custom music file
  • Choose file to download
  • This is the new button layout at the bottom of the app
  • This is what the basic set up is

Here is a YouTube demo the app.

Theory of Operation

The basic structure of our program is an Android app sends instructions to an application running on the BeagleBone which controls the music. The app first 'discovers' the BeagleBone and connects to it via Bluetooth. Then, the user can select to play, pause, resume, or stop playing different songs. The user can also control the volume. The BeagleBone controls the music according to the command using mplayer. The audio output plays through a headset. Below you can see a diagram on the interaction of different parts of the system.

This is the basic flow of the program.

Work Breakdown

  • Phone connect to bone through app via Bluetooth- Trey
  • Wrote App - Trey
  • Using mplayer to play, pause, resume, and stop music, in python script - Anne
  • Ability to download music from online - Trey
  • Using mplayer to play custom music files on the BeagleBone - team effort
  • Connecting beaglebone black to bluetooth speaker - Anne (never figured out a solution)
  • Solving choppyness of mplayer when playing music - mostly Trey, little help from Anne
  • Documentation - Anne, little help from Trey

Future Work

Here are some ideas that could be cool to implement in the future:

  • Add newly downloaded music to the list in the app
  • Play music on multiple audio outputs at the same time
  • Have a display change with the music playing
  • Finish Bluetooth speaker effort

Conclusions

This project presented some interesting challenges. Using mplayer in the Python application cause the output of the audio to initially skip at some points. We tried many different things to solve this. The main solutions we tried we changing the command to include different optional settings. Many of these things were similar to manipulating the cache size and the amount of data read in before playback begins. Ultimately the issue was the sampling rate used during playback. Overriding this setting caused the audio to sound a lot better.

Another issue we had was getting the Bluetooth set up. Initially, we didn't know that we needed to use a Bluetooth dongle with the BeagleBone Black, so it was a lot of work before finally realizing we needed to purchase that. Initially, without the dongle, the black was just telling us there was no controller for Bluetooth so it was just always "waiting to connect to bluetoothd". After getting the dongle we still needed to run the the commands listed above to get the module for Bluetooth and start it up. After this setup we began trying to connect the speaker. While the pairing process was successful, the BeagleBone would not connect to the speaker. We kept getting the error "Failed to connect: org.bluez.Error.Failed whenever we tried to run the connect command. We tried a different dongle and installing different packages to monitor Bluetooth, but no luck. Some insight that we have for this problem in the future is that there are different Bluetooth protocols and we think that maybe we need the Bluetooth with the speaker is not compatible with the BeagleBone Bluetooth. This is only a hunch as we could find no information on this topic. Also, another group working with Bluetooth for audio output said the Bluetooth connection only seemed to be reliable if there was something going on constantly (playing music always).

Since we were able to have the phone connect via Bluetooth to the BeagleBone, we tried to implement a similar system with another speaker. We tried to set up one Bone to connect to another via Bluetooth then have each BeagleBone drive a different output. We used a similar script to the script that was setting up the Bluetooth connection between the phone and the BeagleBone. After working on this idea, it seems to us that the BeagleBone does seem to set up a connection well. The phone to BeagleBone connection is set up initially by the phone "discovering" and connecting with the Bone. When the Bone tries to do a similar thing with any other system we see many errors. We never found what is causing this behavior but we know that you can set up a connection from the BeagleBone. When looking over the various groups for the Bone with similar topics we found that many people were having this issue of connectivity with the Bone without luck of a solution.

Besides these hiccups, creation of the app to outputting sound went smoothly. The audio ended up just being driven by an audio dongle in the BeagleBone. The project allowed us to experiment with different peripherals that we thought could make an interesting project. We found new things along the way that we were unaware of that we were able to bring together to make a functioning system. Some things that would be interesting to pursue is sending the music files to the BeagleBone so that you could play any song that you had on your phone. There is also probably a way to get the music from other apps to play on the Beagle (basically just use the Beagle as the audio out for the phone). Overall, while there were some difficult parts, we are happy with the outcome of the system as it presented us new ways to connect to and use the BeagleBone.




thumb‎ Embedded Linux Class by Mark A. Yoder