Skip to content

bsaund/musicbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Musicbox

This is my raspberry pi musicbox. It allows me to play my local music (e.g. mp3s) on a bluetooth speaker by scanning a barcode in a physical binder of my music. As a backup, there is a web interface. I give some color commentary in my blog post.

Scanning a barcode

This musicbox is built on mopidy, and therefore could be adapted to all of the mopdiy plugins and websites.

If you run into problems, or want more detail, please create an issue.

Setup

Overview

  1. Set up raspbian
  2. Install mopidy
  3. Resolve issues
  4. Set up custom code for the barcode reader and for reacting to the bluetooth remote

Set up raspbian

  • Install raspbian using the image writer utility.
  • Boot into raspbian. For convenience, enable ssh and VNC in the Raspberry Pi Configuration using the main system menu. You can then use Remmina from ubuntu to remote-desktop into the pi.
  • [Optional] Set a static IP for the raspberry pi in your router.
  • Connect to your bluetooth speakers, play some test sounds.

Install mopidy

Resolve issues

I had issues making my bluetooth speaker connect nicely. When run as a service mopidy sound would not play over bluetooth. I followed this link

Also, my bluetooth speaker regularly disconnects. To make sure the raspberry pi connects whenever the bluetooth speaker becomes available I followed this issue and

  • Added load-module module-switch-on-connect to /etc/pulse/default.pa to autoconnect to bluetooth as the speaker turns off and on:

Set up custom code

  • Add the systemd service files to /lib/systemd/system/
  • Install all dependencies (apt + pip) in one step:
    sudo bash scripts/install_dependencies.sh
    
    Or install pip packages only: pip3 install -r scripts/requirements.txt
  • sudo systemctl enable musicbox-bluetooth.service
  • sudo systemctl enable musicbox-scanner.service
  • For more information on systemd
  • Scanner logs: journalctl -u musicbox-scanner.service -b -n 100 --no-pager (use -f to follow). If you only see “exit-code” lines, scroll up for Python tracebacks, or run python3 ~/musicbox/code/barcode_player.py in SSH to print errors directly. The bundled unit sends stdout/stderr to the journal and sets PYTHONUNBUFFERED=1.

Add the bluetooth remote controller listener

The code/bluetooth_control.py should already work nicely with any remote control. To create this script, I learned from these links: https://thehackerdiary.wordpress.com/2017/04/21/exploring-devinput-1/ https://stackoverflow.com/questions/54745576/detecting-the-buttons-on-a-bluetooth-remote-hid-over-gatt

Add barcode scanner

  • Connect the barcode scanner and look at the path created on the raspberry pi under /dev/input/by-id/
  • Edit the path in code/barcode_player
  • I already had permissions, but if you run into permissions issues check out the udev rules:
  • SUBSYSTEM=="usb", ATTR{idVendor}=="28e9", ATTR{idProduct}=="28e9", MODE="0666"
  • udevadm control --reload

Add Dropbox sync

Generate your directory

Check out the img folder for an example directory.

  • On a computer with your music (not necessarily the raspberry pi), run from the code/ directory. By default the library path is ~/Dropbox/Music on whatever machine you use (laptop user vs pi does not need to be edited). To use a different folder, set MUSICBOX_MUSIC_DIR (or pass it in systemd with Environment=MUSICBOX_MUSIC_DIR=/path).
  • Optional: set MUSICBOX_SCANNER_DEVICE or MUSICBOX_BLUETOOTH_INPUT to your /dev/input/... paths if they differ from the defaults in code/musicbox_paths.py.
  • Run python3 barcode_map.py
  • A pdf with your music is created. Print this out double-sided.
  • Copy the .barcode_config file to the raspberry pi (happens automatically if using dropbox sync)
  • Restart the barcode scanner service sudo systemctl restart musicbox-scanner.service (or just restart the pi)
  • Scan a barcode. The corresponding album should be playing on the bluetooth speaker.

About

Instructions and code for my raspberry pi music box

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors