Having fun with the Raspberry Pi B+ and Pi MusicBox

Now that Christmas is over, I needed to find the next “thing” for my Raspberry Pi. After some googling, I decided to give Pi Musicbox a try. Musicbox is basically a spin of the Raspbian Linux distribution with Mopidy allowing you to play all sorts of streaming services like Spotify, TuneIn, SoundCloud and local sound files on a ‘headless’ Raspberry Pi.

In this post, I will describe a bit of the work I had to do to get Pi Musicbox working to my satisfaction including some of the issues I am still encountering.

First:

The Hardware:

Installation:

The first thing I had to do was ‘dd’ the musicbox image into my mini SD card using a SD card adapter on my laptop which is running Fedora 21:

sudo dd bs=1M if=musicbox0.5.2.img of=/dev/mmcblk0

Once that was done, I mounted the card on my laptop and modified the config/settings.ini file in the MUSICBOX partition. In that file, you can set the root password for your server, enable ssh, set up wifi (*), configure your Spotify account (**) among other things.

(*) I started my set up using my canaKit wifi usb dongle, but once I started doing things with samba mounts to share music, I quickly noticed a lot buffering issues with the system while trying to play music, so I gave up on the wifi and plugged it in directly into my router’s ethernet port.

(**) You must have a Spotify Premium account for you to be able to connect to it via Pi Musicbox.

After saving my changes to settings.ini file, I unmounted my card, took it out of the adpater and plugged it into the Pi. Once it booted it up, I just accessed http://192.168.1.30/ (the IP my router gave my Pi) from my laptop.

Pi Musixbox Web Interface

Pi Musixbox Web Interface

Configuration:

Depending how fancy you want to go with your set up, this is probably be the part of the project that will take most of your time. In my case, I wanted to make the songs I had on my mac playable from the Pi.

I shared a Music folder I had with some albums on my mac, and mounted the share o the Pi.

MusicBox has a set of options in the settings.ini to allow you to enter a Samba share information in there for the system to scan, but I could not get that to work with a share coming from a mac, so I went and edited the /etc/fstab on my pi and added:

//192.168.1.79/music /mnt/music cifs username=myusername,password=mypassword,nounix,sec=ntlmssp,noperm,rw 0 0

My guess is that Musicbox tries to mount a samba/cifs share without using the sec=ntlmssp option, which is required to mount a share from a Mac OS X host in Linux. Again, it is just a guess at this moment.

Note that I am mounting the above on /mnt/music. I had to modify the /etc/mopidy/mopidy.conf file. I had to set media_dir option to /mnt/music

My playlists from Spotify automatically in the system

My playlists from Spotify automatically in the system

My premium membership to Spotify had expired, and when I first started playing with Musicbox the part related to Spotify would just spin on the web interface and nothing would happen. I ended up finding the log for the application and noticed when mopidy started it said non-premium accounts couldn’t access the content I was trying to access.

The log location for mopidy on Musicbox is: /var/log/mopidy/mopidy.log

ssh enabled. Note the samba mount from my mac for "local" files over the network.

ssh enabled. Note the samba mount from my mac for “local” files over the network.

Remember to enable ssh and set a root password on the settings.ini (as previsouly mentioned) so you can access the log file.

Local Radio:

Probably my second favorite feature on Musicbox is the ability to interact with TuneIn, which allows you to listen to local radio stations that have an online presence. And, in case you are wondering, my favorite feature in the Spotify connectivity.

Pi Musicbox uses the TuneIn API to give you access to local radio.

Pi Musicbox uses the TuneIn API to give you access to local radio.

Problems:

As much fun as I am having in setting this up, there are a few issues I am fighting with. Some of them may be of my own doing, and others may be related to mopidy itself, but at this point, I just see them as problems. So, this is meant to be for information’s sake and not criticism on the project at all.

  • Samba configuration on settings.ini doesn’t seem to work with OS X shares.
  • Streaming from a samba share via wifi (using the canaKit wifi dongle at least) doesn’t quite work. Too much buffering.
  • local file refreshes doesn’t seem to work unless the system is rebooted.
    • I tried running ‘mopidy local scan‘ to force a file scan, but it aways fails with the error: UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc3 in position 4560: ordinal not in range(128)
  • I also had the error above on the mopidy.log when I was trying to scan for thousands of files on my Samba share. I reduced the files to about 480, and made sure only files with “ascii” characters where available and then my local files showed up on the web interface.
  • Manually restarting (or stopping and then starting) mopidy doesn’t seem to trigger a local file scan either.

Conclusion:

Yet another great little afternoon project for the Raspberry Pi. I now have a music/radio streaming service in the house that can be remotely accessed via a web interface. It doesn’t require a monitor or TV, no keyboard or mouse. Just a network connection and some speakers. That’s all I have to say about that. :-)

2,983 total views, 2 views today

Posted in hardware, music, raspberrypi, raspbian | Leave a comment

Having fun with the Raspberry Pi B+, Part III

Here’s a quick way to create a lightshowPi remote control on your Android phone.

1. This is for an Android Phone, I am not sure about iPhone. Download the app RasPi Check: https://play.google.com/store/apps/details?id=de.eidottermihi.rpicheck

You connect to your Raspberry Pi via SSH on your home network

2. I wrote a quick little python script that turns on all the Christmas lights on my tree using python’s RPi.GPIO. This is for whenever I want to just have the lights on w/o the blinking and music.

##### starts here ####
# script name: christmas-on.py

#!/usr/bin/env python
import RPi.GPIO as GPIO

light1 = 12
light2 = 16
light3 = 22
light4 = 32
light5 = 40

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(light1,GPIO.OUT)
GPIO.setup(light2,GPIO.OUT)
GPIO.setup(light3,GPIO.OUT)
GPIO.setup(light4,GPIO.OUT)
GPIO.setup(light5,GPIO.OUT)

GPIO.output(light1,GPIO.HIGH)
GPIO.output(light2,GPIO.HIGH)
GPIO.output(light3,GPIO.HIGH)
GPIO.output(light4,GPIO.HIGH)
GPIO.output(light5,GPIO.HIGH)
### ends here

Assumptions:
a) I am only using 5 channels on my SSR board
b) I am using GPIO ports: 18, 23, 25, 12, 21

3. The christmas-off.py is exactly the same, just using GPIO.LOW isntead of GPIO.HIGH.

4. Add 4  commands to the RasPi Check app.
a) lights on
sudo /home/pi/gpio/christmas-on.py
b) light off
sudo /home/pi/gpio/christmas-on.py
c) dane on
export SYNCHRONIZED_LIGHTS_HOME=/home/pi/gpio/lightshowpi/ && nohup $SYNCHRONIZED_LIGHTS_HOME/bin/start_music_and_lights
d) dance off
export SYNCHRONIZED_LIGHTS_HOME=/home/pi/gpio/lightshowpi/ &&  $SYNCHRONIZED_LIGHTS_HOME/bin/stop_music_and_lights

Image attached to post.

Screenshot_2014-12-09-22-46-31
It works like a charm….

Note: The creator of LightshowPi just told me, I can turn on all the lights (and off) by using:

# Turn all lights on
sudo /home/pi/gpio/lightshowpi/py/hardware_controller.py –state=on

# Turn all lights off
sudo /home/pi/gpio/lightshowpi/py/hardware_controller.py –state=off

Previous Posts:

Having fun with the Raspberry Pi B+
Having fun with the Raspberry Pi B+, Part II

1,476 total views, 1 views today

Posted in christmas, linux, raspberrypi | 1 Comment

Having fun with the Raspberry Pi B+, Part II

A couple of weeks ago, I wrote a little bit about my experience with the Raspbery Pi B+ and the Canakit. The article ended up getting some love from reddit’s /r/raspberry_pi and opensource.com on twitter, which I truly appreciated :-).

As I previously mentioned, I ordered the Sainsmart 8 Channel 5V Solid State Relay Module Board. It finally arrived today, so I went to Target to buy the material to do my “dancing” Christmas Tree.

So, what exactly did I do here?

  1. First you have to read the original post, and make sure you watch the tutorial on how to set up the breadboard.
  2. Once you are comfortable with that. Look at the LightshowPi project. Learn how to use it.
  3. Join their Google+ Community.
  4. Read up the people’s projects and photos they share over there.
  5. Once, you’ve done all that and you understand what’s going on then order the Sainsmart 8 Channel 5V Solid State Relay Module Board. WARNING, mine took 2 weeks to arrive!
  6. You can search for videos on Youtube on how to connect your Pi to the SSR board, I watched this one. If you understand the GPIO stuff, the SSR board part is pretty simple. The tricky part for me was the electrical part as I have very little knowledge about house electricity.
  7. I purchased: 6 polarized extension chords at Target, 5 for the light string, and 1 for the power source. I am only using 5 channels out of the 8 on the SSR board.
  8. Then I used this amazing step by step photos on how to cut the wires and daisy chain the power source into the relay… and the rest is history :-)
  9. I also needed something to cut the wires with, a small screw driver to tighten the SSR board slots, electrical tape and a jackknife.

Here are some photos and videos:

IMG_2690

raspbery pi, ssr board connected to the lights

IMG_2688

ssr board connected to the extension chords

Here are 3 videos I posted on YouTube with the final results:

1,683 total views, 1 views today

Posted in christmas, linux, raspberrypi | 2 Comments

Fedora 21 Extra Backgrounds

If you want to use one of my photos as an official Fedora 21 background.

Try it out:

yum install f21-backgrounds-extras-gnome

My photo of Flagler Beach, FL (w/o any editing)

My photo of Flagler Beach, FL (w/o any editing)

Original: https://www.flickr.com/photos/afsilva2/12178037005/

766 total views, no views today

Posted in fedora 21, photography, screenshot, wallpaper | 1 Comment

Having fun with the Raspberry Pi B+

It is Thanksgiving week in the US, and I had some paid time off banked at my job. So, I decided to do a stay home vacation and tinker with something. I decided that “something” would be a Raspberry Pi. A quick search on Amazon, and I ended up ordering the CanaKit Raspberry Pi B+ Ultimate Starter Kit (I will refer to it from now on as “the kit”).

Instagram photo of the unboxing.

Now, I personally don’t need another computer running Linux at home, so I wanted the Raspberry Pi (I will refer to it from now on as “the pi”) to do something I haven’t done before. When I looked at all the LEDs and wires that came with the Starter Kit the first thing that came to mind was Osborne Family Spectacle of Dancing Lights at Disney’s Hollywood Studios. Call me silly, that’s OK!

I had no idea if I would be able to pull it off, but if I could at least understand a bit more of how to make software interact with hardware at the scale in which the Pi claims it could do then my stay home vacation would certainly be a good one.

pi

The Raspberry Pi B+ (photo taken by yours truly)

The kit arrived last Friday (Nov-21), and I wasted no time. First, being completely biased to anything Fedora or Red Hat based, I decided to use NOOBS to install Pidora, and as cool as this Fedora spin is, I quickly noticed it just wasn’t going to be the Linux distribution I should use to make my little Christmas Light show.

I went with the Pi’s recommendation and installed Raspbian, which in a very short amount of time proved itself to be the better distribution to be running on the Pi. You may be asking, what reasons were they? Well, here are a few:

  1. raspi_config which allowed me to do quite a bit of configuration changes to the raspberry pi right off the bet.
  2. LXDE as a window manager. Raspbian’s out of the box needed about 50% less memory than Pidora, which on a little piece of hardware that has 512 MB of RAM this is HUGE!
  3. Included apps: Mathematica, Scratch, Sonic Pi, and the needed python libraries to do some coding with the GPIO pins were all already bundled in Raspbian.
  4. The Raspberry Pi book (and the foundation) recommends Raspbian, so following examples (from the book and online) are much more repeatable in Raspbian.
pi+keyboard

Using a Logitech MK401 seems to be working pretty well with the Pi.

By Friday night, I have the Pi connected to my TV, with Raspbian installed, and connected to the house’s wifi. I run an: apt-get update && apt-get upgrade to update the OS, and now I am ready to look into all the “extras” that came with the kit.

Aside from some very theoretical stuff I had in physics in high school and college about electricity, I have never really had any chance or interest in applying any of that theory anywhere. Terminologies like breadboard, jumper wires, resistors, current, voltage, etc… weren’t foreign words, but they were “theoretical” words for me. So, what did I do? I googled my answers, what else? :-)

First, I used this video on Youtube to learn about the breadboard and the kit. Then I did it myself, and expanded on it by adding extra LEDs.

Now, that I had the lights working the next step was going to be how do I make them “listen to music”?

Another google search, and I found this awesome open soure project for the Pi called: LightshowPi. And it is with this project that and its Google+ Community that I was able to successfuly complete the first phase of this personal project.

board

The CanaKit breadboard, GPIO board, LEDs and resistors.

pi+tv

The raspberry pi connected to a $80 720p TV I bought at Best Buy. It was cheaper than any other LCD monitor around.

Here’s a quick video of the mini-light show:

So, what’s next?

Now, that I’ve gotten my Christmas Light show going (in a very small scale), I want to go a bit bigger. I want to light up my Christmas tree this year using my Pi and LightshowPi, and do something like this. I have ordered a Sainsmart 8 Channel 5V Solid State Relay Module Board hoping I will be able to pull this off by Christmas. And who knows, maybe next year, I will expand and set up lights outdoors for the public.

5,244 total views, 13 views today

Posted in christmas, linux, raspberrypi | 6 Comments