mellowtigger: (penguin coder)
I found a good solution for loading a music playlist loop beginning at boot.

A quick comment for some good news, though. Do you remember when I told you that audio is borked on the pi? Well, the Raspberry Pi Executive Director agrees. He posted on January 1st a job position specifically for work on the ALSA audio driver. I look forward to some fixes in future Raspbian builds. Now back to the fun stuff.

It takes a small amount of setup mojo to get it working, but I like the mpd server and client software for the usage that I envision. In my case, we need a continuous audio feed for our phone system. It will play the music-on-hold that you hear while waiting for your phone call to route. We could also use a similar system to play the audio enrichment music for dogs, cats, and other critters in our shelters. We want the audio files to play continuously as long as the pi is powered up. Here are the commands that you will need to get your pi working.

sudo apt-get install mpd mpc
mkdir -p /home/pi/.mpd/playlists
mkdir /home/pi/Desktop/music
touch /home/pi/.mpd/{mpd.db,mpd.log,,mpdstate}
ls -al /home/pi/.mpd
sudo vi /etc/mpd.conf

You are now editing the default global config file for mpd. (Don't use a local version. It causes lots of file permission pains. I wasted hours before finding this global file.) It needs to contain the server configuration variables. Here is the info that worked for me. You should be able to use the same text. Either modify the lines that are already there, or delete the contents and insert just these lines.

music_directory "/home/pi/Desktop/music"
playlist_directory "/home/pi/.mpd/playlists"
db_file "/home/pi/.mpd/mpd.db"
log_file "/home/pi/.mpd/mpd.log"
pid_file "/home/pi/.mpd/"
state_file "/home/pi/.mpd/mpdstate"
audio_output {
type "alsa"
name "mpdaudio"
bind_to_address ""

That last line is necessary as a hard-coded ip4 address. Most tutorials suggest that you use "localhost" instead. I did, but I kept getting errors. Apparently the Raspberry Pi network setup has both ip4 and ip6 assignments for localhost, but mpd gets confused by the duplication. Hardcode the ip4 address as listed above, and you're good. You have mpd working as a system service at startup.

Copy your .mp3 files into your Desktop/music folder. The server will see whatever files are in it. Keep the filenames in alphabetical order, so it simplifies your playlist ordering. Now we need to use the client to make sure the server is playing at the proper volume and in a repeat loop. We want it to check for updates daily.

cd /etc/cron.daily
sudo touch
sudo chmod 755
sudo vi

Insert these commands into the file.

# Refresh the mpd music database
mpc volume 100
mpc repeat on
mpc update
mpc clear
mpc add /
mpc play

If you want, you can see when these daily scripts will execute.  Use "more /etc/crontab" to see the listing.  Notice that scripts in the cron.daily folder are executed every day at 06:25.  We also want to run the update at boot time, just for our own peace of mind.  We'll need to update the startup script.

sudo vi /etc/rc.local

The last line of the startup script should be "exit 0". Before that line, insert this command.

# Refresh the mpd music database

Save and exit. If you want to test immediately, you can use these commands to place a soothing river sound for playback.

cd ~/Desktop/music
sudo reboot

If all goes well, you are listening to your music files play in a continuous loop soon after your pi powers up. If you need to do any troubleshooting, these commands should help you stop the server daemon.

ps -ef | grep mpd
sudo service mpd stop
sudo pkill mpd

If you need additional help, then check out this extensive mpd guide.
mellowtigger: (penguin coder)
This topic requires a post of its own because audio is mildly "broken" in the latest Raspbian image.

Raspbian uses ALSA (Advanced Linux Sound Architecture), and it comes with a standard "aplay" command to play audio files. You can try it yourself with audio files that are already installed. Telnet to your Raspberry Pi and try the following command.
sudo aplay /usr/share/sounds/alsa/Front_Center.wav
If your speakers are hooked up to your Pi, you probably heard the audio message. That success is encouraging, at least until you try to play some music files of your own. Suddenly, you find playback quite restrictive. Aplay is working only with audio files that are:
  1. stored with old .WAV or .AU file format,
  2. stored with integer (not floating point) values, and
  3. sampled with cd-quality resolution (such as 144,000 Hertz).
Those limitations severely cramp the utility of the Pi. I scanned a lot of forum posts that offered workarounds, but none of them worked for me. I'm a big fan of the VLC player on Windows, but even it was of no help on Raspbian. Some people found that a particular package added to the most recent Raspbian image is causing their problem. Removing it seems to be a useful improvement, at least for this current Raspbian release.
sudo apt-get --purge remove pulseaudio
Now let's download some audio files in other formats.
cd ~/Desktop
If we try the standard Aplay program, we find that we can play other .wav files, but we still can't hear the .mp3 file. You can use Control-C to interrupt playback.
aplay river-4.wav
aplay river-4.mp3
We'll need to install a different program to play the .mp3 file. We find the opposite issue with this program; it plays .mp3 files but not .wav formats.
sudo apt-get install mpg321
mpg321 river-4.mp3
mpg321 river-4.wav
There's still a slight "pop" sound as the audio engages/disengages.  At least we have our playback options covered with these two programs together. We really need to get a single program that covers all the formats, with playlists, and with repeating loops. Until then, audio is less than "friendly" in the current Raspbian distribution.  I'm certain that better solutions will appear in future releases.
mellowtigger: (penguin coder)
You collected the hardware and software, so now you're ready to configure your Pi. It's surprisingly easy.  You can complete the process in less than 10 minutes.

pi.diskimager1) Write the image to the memory card.

Put the SD memory card into your card reader. Run your Win32DiskImager software. Make very sure that you are writing the image file onto the correct drive letter. You could destroy your Windows boot drive if you choose the wrong drive letter! It takes a few minutes to finish writing the image to the card.

If you're assigning a permanent ip address, proceed to step 2.  If you're using the IP Scanner to find your network address, then skip to step 3.

2) Edit "cmdline.txt".

You may need to remove the memory card and reinsert it before you see the new drive in your Windows system. If it asks, do NOT scan or repair. Open up the drive letter and edit the boot configuration file using the default Notepad. Look for the "console=tty1" parameter. After it, you'll need to insert another parameter, constructed with the new A) ip address, B) gateway, and C) netmask (in that order) that you already selected. For instance, I used this parameter:
After the console parameter, insert a space character, then the above line, then another space. Do not delete the other parameters that come afterwards. Do not press Enter; let it all run together as one line. Save the file and exit.

3) Power up.

Insert the memory card into your Pi. Connect the Pi to the ethernet cable and the USB power cable. Within a few seconds, you should see the green lights start flashing on your Pi. You're ready to connect.

pi.putty4) Telnet into it.

Run the Secure Shell telnet program called Putty. Enter the IP address that you configured above. (Or use the network scanner software to find the temporary address automatically given to your Pi.)  In this example, I'm connecting to Use the default port number (22) and protocol (SSH).

The first time that you connect to your Pi, Putty will warn you with an imposing message about a potential security breach. Click Yes to accept. It's just warning you that it hasn't previously connected to the destination computer that you're contacting now.

Use the default userid ("pi") and password ("raspberry"). Congratulations, you're working on your new Raspberry Pi.

5) Change the password.

For safety's sake, never leave the default userid on any device in your network. Type this command and press Enter.
sudo passwd pi
Enter a new password; enter it again for confirmation.

6) Update your configuration.
sudo raspi-config
Use the arrow keys to navigate the menu, then select "change_timezone" and press Enter.  Wait for this utility to build a menu for your system.  Use the arrows and Enter to select your geographic region.  When it's done, you will return to the main menu.

Select "expand_rootfs" and press Enter. This utility will reconfigure your filesystem to take advantage of all available space. The operating system image that you installed was made for the minimum 2GB memory card. If you bought a larger card, that extra space is not available until you reconfigure. After it's done, select "Finish" and press Enter. Do not select to reboot.
Use this command to confirm that your Pi is in the correct timezone.  Restart the configuration menu if you need to make another change.
sudo reboot
Use this convenient command to reboot your Pi now. Your Putty connection will drop as your Pi reboots. Wait a few seconds for the green lights to reappear, then connect to your Pi again. It may take longer than usual for this reboot to enable the telnet connection. It took over a whole minute in my case. Subsequent reboots will complete faster.
df -h
After the reboot, telnet back to your Pi and use this command to check your drive space.  You should see the Size for "rootfs" appropriate for your memory card capacity.

7) Enable fullscreen gui.

The standard Microsoft method of connecting to remote computers is via Remote Desktop Protocol. You already have an RDP program on your Windows computer, but you'll need to install an RDP service on your Pi.
sudo apt-get install xrdp
It will ask if you want to continue. Press 'Y' (for 'yes') and Enter, then it will install the package.
This command will logout your userid and close your telnet session.

pi.rdp8) Connect with fullscreen gui.

Go to the Start menu on your Windows computer and enter "mstsc" into the text box, then press Enter. That abbreviation stands for "Microsoft Terminal Services Client". It's the program that Microsoft uses for its RDP sessions.

In the popup dialog box, enter the network address of your Raspberry Pi.

Remember, though, that your Pi does not have a powerful cpu, so it cannot quickly construct screens at resolutions that you're probably using on your Windows computer. I got a faster response by toning down the screen requirements.

Click the down arrow next to "Options".  Go to the "Display" tab.pi.rdp.login  Change the configuration to something smaller, like "1280 by 1024" pixels.  Change the colors to something smaller, like "High Color (16 bit)".

Press Connect to accept all other defaults.

Enter the username and the password that you've previously used for your Pi, then click the OK button to connect.

Do not click on any other buttons during the setup process.  If you do, you may accidentally interrupt the initialization.  You will have to close the window and start again.  Be patient.  Eventually, you will see the traditional Raspbian desktop image.


The web browser is called Midori.  Use it to login to G+ and read your news.  It was slow, but it worked for me.  Whenever you're ready to quit your session, use the icon in the bottom left corner (like the Windows Start button) to select Logoff.

Have fun!
mellowtigger: (tech support)
sciencefair.projectkit.75in1Experimenting with a Raspberry Pi reminds me of bygone days playing with a Science Fair project kit from Radio Shack. They're cheap, and they're fun. They only cost about $35 for the base Pi, but you'll need 2X or 3X that amount to actually get it working.

These prerequisites are the hard part; actually doing the setup is very quick and easy! 

This post explains all of the prerequisites that you need to prepare your Pi with minimal accessories, assuming you are working from an existing Windows computer with an empty USB port. I will explain in a subsequent post how to actually perform the setup. 

You start by budgeting an extra $40 for this mandatory hardware and free software:

SD memory cardabout $64GB or larger preferred.
micro-USB to USB cableabout $10Buy micro-USB not mini-USB!  It powers your Pi from your other computer's USB port, so buy appropriate cord length for where you will be placing your Pi.
ethernet cableabout $8I use cat-5e, but I think cat-5 and cat-6 are also fine.  Make sure it too is an appropriate cord length for your Pi's location.
plastic caseabout $10I don't care for the one I bought, so I have no recommendation here.
operating systemfreeI use the recommended Raspbian linux image.
Win32DiskImagerfreeI use this recommended program to write the Raspbian image file to the SD memory card.
secure shell telnetfreeI use this Putty.exe.

Right-click the file and choose to Extract All to some directory of your choosing.  If you don't see an Extract All option, then your computer also needs a program that will allow it to UnZip that file.  I recommend the free program 7zip.

You're almost ready to begin working.  Unfortunately, you may need some additional hardware.  This configuration is where you may run into more expenses, depending on the setup you already have for your home computer.  You may need two additional items if you don't already own them.

 SD card reader about $20It's mandatory that you be able to access the SD memory card on your Windows computer.  If your computer lacks a card reader, then you must purchase one (internal or external).

You'll need the card reader only once during setup, though, so it's an extravagant expense unless you also use the card reader to transfer photographs from a camera.  It's nice to have one available.
1 small router
1 ethernet cable
about $35
about $8
It's mandatory that you have a free ethernet port on your cablemodem (or router) near your computer.  If your original router has no spare ethernet port, then you must purchase 1 small router (a switch or hub with 4 or 5 ports) and 1 extra ethernet cable.

It will act as a small "junction box" for your network, allowing both your main computer and your Pi to use the same network connection.  You'll disconnect your main computer's ethernet cable, then put the new router there.  You'll connect both your main computer and your Pi to that new router, effectively putting a Y-junction in your network link.

You also need to know the ip address for your Raspberry Pi.  You have two options.

The automatic solution is to let the network assign the address for you.  Unfortunately, this method also means that you have to inquire for the address when you want to connect to your Pi.

To query network addresses, you need to install free internet scanner software on your computer.  I recommend the free program Advanced IP Scanner.  You will need to run the scan whenever your Pi gets a new temporary ip address, so you know the address to which you connect.

It will take a minute (or 2 or 3) for it to scan your local network.  Sort the results by Manufacturer name, and look for the one labeled "Raspberry Pi Foundation".  That's the computer address that you'll need to know later.
The manual solution is to assign a permanent network address to your Pi before you even start.  I prefer this solution, and I used it in my setup.

You can easily "guess" a useful ip address by looking at the address used by your current computer. Use the Start button (or Start / Run on older Windows computers) to get the empty box where you can type in a program name. Type in "cmd" and press Enter. You will get an old MS-DOS black box on your window. Enter this command "ipconfig" and press Enter. You're looking for 3 sets of numbers. Write them down.
  1. IPv4 Address
  2. Subnet Mask
  3. Default Gateway
Your computer's IPv4 address is probably something like "". Pick a new number for the last segment, such as "". The number must be less than 256, but it can be anything that your network doesn't already need. You can test it out now by using that same black box to type in this command: "ping". It should say "Destination host unreachable". If it shows you something about bytes and time or "Request timed out" instead, then pick a different number. You need a network address that is unused. Type "exit" and Enter to close the MS-DOS box.

Now you have all of the hardware and software you need to setup your Raspberry Pi "headless", which means without its own attached monitor, keyboard, or mouse.  You'll be doing it from your existing Windows computer instead.  Stay tuned for the next blog post.


mellowtigger: (Default)

June 2017

1112 1314151617


RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 27th, 2017 12:24 pm
Powered by Dreamwidth Studios