Making the Raspberry Pi Boot And Run My Jukebox Program Only

I put this post together over a three day period. It attempts to document how to set up software (in this case the Raspberry Pi Convergence Jukebox software that I’ve written) so it “self boots” when a Raspberry Pi is powered up. For something that is seemingly simple I managed to spend three days before finally getting it going. Hopefully if you’re reading this I can save you some time. What complicated this “seemingly simple” task was that the Jukebox program consists of two pieces of software that need to be run together;

  1. The first program is a Python based Play Engine that operates in a terminal window. It’s function is to first catalogue all of mp3’s that make up the Jukebox’s content and then to play that content either randomly or from a playlist that is generated when a user selects a song.
  2. The second program is a Python based Tkinter GUI application that the user interacts with to select songs, monitor upcoming selections and display credits.

Both these Python applications are pretty mature having been tested for hundreds of hours. I have recently ported the software to the Raspberry Pi and have had no problems starting them from the command line so I expected the process to autostart them to be relatively simple. What I didn’t know –and what I couldn’t find any documentation on– was that autostarting a Python based Tkinter application and a Python based terminal application happen in two different autostart directories as part of the Raspian boot process. So here is what I learned…

The first thing I had to do was to set-up the proper output which in this case was using an HDMI monitor.

Setting HDMI To 720P

I found the information to set the HDMI output to 720P at

Getting The Sound To Operate via HDMI Connection

In my previous post Convergence Jukebox Now Ported To Raspberry Pi I noted where to find the information that describes how to get a USB soundcard working on a Raspberry Pi.  However, prior to setting up my USB soundcard, I was unable to get sound via my HDMI connection. I found this link —Sound does not work with an HDMI monitor— that explained the process.

NOTE: I found I had to reverse the what I had done to enable my USB sound card in order to get the HDMI audio working.

Backing Up My Convergence Jukebox SD Card

Having done all this work to configure my SD card I thought it prudent to back up my custom Raspian SD card in case I break it trying to get the auto boot to work. To back up my Convergence Jukebox I followed the the following blog post How to Clone Your Raspberry Pi SD Card for Super Easy Reinstallations as a start. It worked…

HOWEVER: the method above described creates an image file as large as the card itself. Hence the 64 gig card I’m using –so it can hold a large number of mp3 files– took a long time to create the image file. I decided to go with it and eventually rebuild a small working version on a 2 or 4gig SD card at a future date. After all an SD disk img file only needs the os and files to get the the program running. The mp3 library can always be added to a rebuilt SD card later.

Getting My Program To Run At Bootup

I found this post “Choosing which programs run when the Pi boots” to be useful. It’s short and concise and its last section describes simply describes how to run a Python program at Bootup.

In implementing this process I discovered as the Jukebox Player Engine started that it lost the path to it’s ancillary files and the program would not run. I located the fix using the information at this link “Python os.chdir() Method“. By adding two lines of code to Engine the the problem was solved.

Once my Player Engine was happily playing songs I quickly discovered that the screen would go to sleep and go blank. Not good for a continuous Jukebox Application. I solved this problem by following the instructions at this post on how to disable screen sleep on the Raspberry Pi.

The method described in  “Choosing which programs run when the Pi boots” is great to run python terminal programs, However it turns out that is  not good for running Python Tkinter GUI programs. As mentioned previously the Convergence Jukebox GUI program uses Tkinter to generate the Jukebox GUI. In order to run a Python script that requires Tkinter one has to have the Lightweight X11 Desktop Environment (or LXDE) running prior to starting a Tkinter application. This link “Autorun browser on startup gives one a clue on how to run a GUI application once LXDE runs. This second link “Running a Python Script AFTER X GUI Starts up” shows specifically how to run a python script after the LXDE has started.

There are a few things I learned that are worth noting here.

  1. A Python terminal application is best auto started in the /etc/rc.local file as described in Choosing which programs run when the Pi boots“.
  2. A Python Tkinter GUI application is best auto started from the /etc/xdg/lxsession/LXDE/autostart file as described in “Running a Python Script AFTER X GUI Starts up“.
  3. Do not start the two Python applications at the same time. You can delay the start of a Python based Terminal program got 20 seconds by coding the rc.local file with (sleep 20;sudo python /path/mypythonprogram.pyc) &
  4. I could not get both programs to run when I placed them in the LXDE autostart file no matter how hard I tried.
  5. And finally…. At some point during my exploration my GUI stopped displaying. Eventually I believe it was because of the Python file permissions.  While my Player Engine was compiled Python code (.pyc file) my GUI program was not. Apparently if one does not log into the Raspberry Pi –as would be the case when a program is auto started at boot up– one has to make a python script executable by changing permissions. In my case I used the Raspberry Pi’s file manager as discussed in this blog post “Making A Start.

Hiding My Mouse Cursor

Once I had the Jukebox booting correctly on my Raspberry Pi I wanted to hide my mouse cursor. I discovered how to do this by reading this post called “Hide mouse cursor“.

To close you’ll find one great Raspberry Pi link at:

Woz and an Apple I at Kansasfest 2013

Convergence Jukebox Now Ported To Raspberry Pi

It’s Done….

It took me almost a year to complete my current project. Some months ago I started a project to create a Jukebox for myself capable of playing my mp3’s. Today mp3 jukeboxes are a dime a dozen but I wanted one that would mimic a 1950’s jukebox employing a mechanical controls (of a type) and be coin operable. Initially I tried using two readily available programs DWJukkebox and Arcade Jukebox 8 (AJ8). I ultimately tried Arcade Jukebox 8 –I could not get DW Jukebox working with a coin machine– but with the development of AJ8 closed some years ago and no documentation I was limited to customizing it with external programs like AutoHotKey in the Windows OS environment.

Last summer I decided to write my own Jukebox –with the features I wanted– from scratch using Python. I chose Python because I was told it was easy to learn and it’s cross platform. I did the initial development on Windows and placed a fully functioning Windows OS Convergence Jukebox beta version in the field within the last two weeks. Convergence Jukebox 1.0 contains the following features.

  1. No limit to the number of MP3’s in its library.
  2. Display of 16 songs on each Jukebox screen featuring both title and artist. The GUI was created using TK.
  3. Clear indication of current song title/artist at the top of the Jukebox Display
  4. Ability to search song selection by Artist or Title.
  5. Ability to jump between letters of the alphabet during song search
  6. A side status screen that displays sort mode, information on song playing (title, artist, year released, song length and album/release information), up to 18 upcoming song selections, credits, cost barker line and number of songs available on the jukebox.
  7. Integration with a  Weavefuture Coin Acceptor AK5 System via a Weavefuture USB  Jukebox Interface Board
  8. An X-keys® XK-24 Programmable Keypad to operate the Jukebox
  9. A log that monitors and records when the Jukebox is turned on, the playing random, skipped and user selected songs.
  10. Remote maintenance access employing LogMeIn.

Today I managed to complete the initial port of the python software to my Raspberry Pi. It only took me about four hours total to configure the code for the Pi version. Primarily it involved changing the code slightly to accommodate the mpg321 mp3 player and changing the filepaths between the Windows OS and Raspian Wheezy OS.

Here is how the initial port looks on the Raspberry Pi;

2nd Jukebox Gui Image From Raspberry Pi 2

Here is how the Interface to the Windows OS Jukebox looks;


Some Notes…

OK. Here is my recipe for working with Python on my Raspberry Pi and ensuring proper set-up with a USB soundcard.

1.  First follow my previous blog post Back In The Raspberry Pi Business Today. Starting To Port My Python Based Jukebox To Wheezy to set up a remote desktop.

2. Install WinSCP on windows machine for file transfers and Putty to the Pi.

3. Using WinSCP create a python folder in the /home/pi directory. This is where python projects go.

4. Using WinSCP create a folder (my current project) in the /home/pi/python directory. This will be the folder for my current project.

5. Install pip.

6. Install idlex. sudo pip install idlex

7. Install mpg321. sudo apt-get install mpg321

8. Install hsaudiotag sudo pip install hsaudiotag.

9. Install Python Imaging Library. sudo apt-get install python-imaging sudo apt-get install python-imaging-tk.  sudo apt-get install python-imaging-tk

10. Setup the USB soundcard by following instructions at Start at Updating alsa options on that page.


LEGO & Raspberry Pi Reads eBooks Aloud: eReader Reader

Check out this “Jack The Ripper” DVD bot powered by a #Raspberry_Pi

Back In The Raspberry Pi Business Today. Starting To Port My Python Based Jukebox To Wheezy

Spent most of last evening booting up my Raspberry Pi’s that I got last year. My plan is to see how well my Python based Convergence Jukebox will run on a Pi. It was written on a Windows PC (and is now in a field beta test) using Python 2.7. The only python module employed in the code specific to Windows is the mp3 player module. As far as I can tell if I can replace that player module with something that will run on the Pi it should be a relatively simple port. However as I discovered over the last year in both learning Python and writing a Jukebox from scratch nothing much was actually “simple”.

Just wanted to mention that one of the first things I set up was a remote desktop from my Mac based Windows “Paralleled” desktop to my Raspberry Pi. I followed Remotely Accessing the Raspberry Pi via RDP – GUI Mode and it worked well. One thing to keep in mind the remote desktop software (called RDPDesk) for Windows is now downloaded from