SonyPi - bringing an 80's "boombox" into the 21st C

careful with that soldering iron, Eugene
User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 10:35 am

Hi
So this little project of mine has been a lot of fun. Basically what I wanted to do was embed a raspberry pi inside an old boombox / ghetto blaster / portable stereo.

Criteria for my donor boombox:
1. decent make, Sony, Panasonic, JVC etc
2. stereo - I initially looked at old Roberts Radios which would be easy to work on, plenty of space inside, but were only mono speakers and I really wanted stereo. They often have 5 pin DIN inputs though so otherwise would be ideal candidates. Enclosures also tend to be wooden so easier to work with.
3. Line in - following the above, it was going to be a lot easier if there was a line in that I could hook into. Many many years ago I cant remember what it was, but I do remember connecting onto the wires on the back of a tape player head to get line in. I didnt really feel like doing that again, but worse case scenario I could just plug into the line in sockets, best case scenario I could connect inside to the back of the same sockets for a more discreet connection.
4. large battery compartment where the raspberry pi could hide.
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 10:37 am

My donor - Sony CFS W401L

Image

Line in on the top, chunky battery compartment where I could hide the raspberry pi.
Sounded ok, but the speakers themselves were pretty dire so I replaced them. That's another adventure!
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 10:50 am

What's inside?

Raspberry Pi shopping list:
raspberry pi model 3
hifiberry dac+ (plain version)
memory card I already had, but 16 gb class 10 is perfect - actually 16 gig is far too much space!
usb power supply - the official raspberry one
panel mount leads - for usb, ethernet and power
right angled phono/rca interconnect - space is a premium and in the end, only right angled plugs were going to fit.
Finally ..
raspberry pi sticker!! http://www.ebay.co.uk/itm/X2-Powered-By ... 2192007821

OS of choice - dietpi; easy to install the OS, easy to install additional software, things like ssh out of the box makes it so much simpler.
http://dietpi.com/phpbb/viewtopic.php?f=8&t=5

Installed through the dietpi menu:
config for the hifiberry dac+ card
roonbridge http://dietpi.com/phpbb/viewtopic.php?f ... t=80#p4153 (for Roon fans!)
shairport sync http://dietpi.com/phpbb/viewtopic.php?f ... 1221#p1221 (gives airplay support)
wifi hotspot http://dietpi.com/phpbb/viewtopic.php?f ... 1207#p1207 (so i can "ssh" into the pi when there's no network connection)

manual install:
moc - command line media player http://moc.daper.net/

Attached below: I've written all the scripts mentioned in the next 3 posts into 1 single shell script - this does everything mentioned including creating a new mount directory, and installing moc etc. Supplied "as is"; i've tested it as much as I can, and it works on my pi with dietpi os installed. ymmv as they say. I've deleted usb sticks from my setup and re attached them, and moc kicks in and plays and that's as much testing I can do. Works with 3 different usb sticks. Simply download the file, rename to "sonypi_install_script.sh" and run it - you might need to "chmod +x" not sure depends on your access.
Attachments
sonypi_install_script.sh.txt
updated 20 Oct 2017, fix to 99-automount-usb.rules
(2.85 KiB) Downloaded 19 times
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 11:01 am

(remember for all scripts, with dietpi you are "root", for other pi os's you might need "sudo" here and there)

How to get the raspberry pi to recognise and auto mount a usb stick.
This had me scratching my head but plenty of googling later and it works beautifully.

UDEV is the system that manages devices, and /etc/fstab file contains the mount points.
First you need to create a mountpoint
mkdir /mnt/usb
as simple as that! This will be the parent directory for the inserted usb stick, so it will always be /mnt/usb/.....

Now the scripts. These use udev rules that execute when the usb stick is inserted (and again when removed).

FYI I've used "cat <<'EOF' > xxxxxxx" so you only need to copy / paste and it will write the scripts to your device. see https://stackoverflow.com/questions/250 ... rk-in-bash
using EOF inside ' (i.e. 'EOF') means that no substitution occurs.

This one will kick in when a usb stick is inserted. The subsystem type will be scsi and it will be sda1 or sdb1 etc, when that happens, run that "auto_add_usb.sh" script
**fixed 20Oct, the “add” rule needs KERNEL as well or it matches multiple times and kicks off the shell script multiple times too!

Code: Select all

cat <<'EOF' > /lib/udev/rules.d/98-autoadd-usb.rules
SUBSYSTEMS=="scsi", KERNEL=="sd[a-h]1", RUN+="/bin/sh /home/dietpi/auto_add_usb.sh"
EOF
cat <<'EOF' > /lib/udev/rules.d/99-automount-usb.rules
SUBSYSTEMS=="scsi", KERNEL=="sd[a-h]1", ACTION=="add", RUN+="/bin/mount /dev/%k", RUN+="/bin/sh /home/dietpi/mocp_udev.sh"
SUBSYSTEMS=="scsi", ACTION=="remove", RUN+="/bin/sh /home/dietpi/mocp_exit.sh", RUN+="/bin/umount /dev/%k"
EOF


"auto_add_usb.sh" script itself
basically this lists the devices, and for sd** (which will be sda1, sdb1 etc), it picks out the ID of the card (the "awk" bit) into a variable. This is then checked to see if that device is already in the /etc/fstab file, and in the rules.d file, and if not it is added automatically.
example
ls command gives

Code: Select all

root@DietPi:/home# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 15 Oct 18 15:32 35ab52fd-2061-49ad-98c1-2e11ff391d7d -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 10 Oct 18 15:32 5A82-AAE3 -> ../../sda1
lrwxrwxrwx 1 root root 15 Oct 18 15:32 621E-3B3C -> ../../mmcblk0p1
root@DietPi:/home#

grep picks out the line with sd*1 in it
lrwxrwxrwx 1 root root 10 Oct 18 15:32 5A82-AAE3 -> ../../sda1
awk picks out the 9th "word" which would be 5A82-AAE3 - that's the unique ID for that usb stick.
The script then checks if that's already in the fstab file and if not, adds it in with correct parameters.

Code: Select all

cat <<'EOF' > /home/dietpi/auto_add_usb.sh
#!/bin/bash
usbid=`ls -l /dev/disk/by-uuid/ | grep sd[a-h]1 | awk '{ print $9 }'`
if [ -z $usbid ]
then
  exit 0
fi
echo $usbid
checkfstab=`grep $usbid /etc/fstab | wc -l`
if [ $checkfstab -eq 0 ]
then
  echo "UUID=$usbid /mnt/usb auto defaults,noauto 0 0" | tee -a /etc/fstab
fi
EOF


What will this actually do?
The first time you add a brand new usb stick, the id of this will be written into both the /etc/fstab file, and it should start to play.
When the stick is removed, then mocp will gracefully stop, and the device will be unmounted.
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 11:10 am

... continuation.
If you look in the udev rules, you will see reference to moc (aka mocp as that is the command line instruction though the package is called moc).

/home/dietpi/mocp_udev.sh script
the RUN command in udev is only allowed to run short scripts - any longer than 5 secs or so and it will be killed. Hence the use of "at". This basically asks "at" to run another script right now. Effectively the script will run in another shell. https://www.lifewire.com/linux-command-at-4091646

Code: Select all

cat <<'EOF' >/home/dietpi/mocp_udev.sh
#!/bin/bash
echo /home/dietpi/mocp.sh | at now
EOF


and the script that runs is:
/home/dietpi/mocp.sh
This does a couple of things: first cleans up in case moc was already running. Then it locates an m3u file (if there is one) and if found, runs moc using that playlist. Otherwise it runs moc with shuffle on, and pulling in every music file it can find. This is all pointing at /mnt/usb where the newly inserted usb card will be mounted by udev.

Code: Select all

cat <<'EOF' > /home/dietpi/mocp.sh
#!/bin/bash
# stop mocp if it is already running
mocstat=`ps -aux | grep mocp | grep -v grep | grep -v mocp.sh | wc -l`
if [ $mocstat -eq 1 ]
then
  echo "exit mocp"
  mocp --exit
fi
rm -f /root/.moc/pid # this is a temp file that moc creates when it runs
echo "start mocp server"
mocp -S # start the server
mocp -c # clear the playlist
# check for a playlist and if found, use that
playlist=`find /mnt/usb -name "*m3u" | wc -l`
if [ $playlist -eq 1 ] # found just one playlist
then
# load the playlist
  m3u=`find /mnt/usb -name "*m3u"`
  echo "loading playlist" "$m3u"
  mocp -a "$m3u"
else
  echo "doing random play"
  mocp --on s,n -a /mnt/usb/
fi
echo "play!"
mocp --play
EOF


Cleanly shutdown moc on usb removal

Code: Select all

cat <<'EOF' > /home/dietpi/mocp_exit.sh
#!/bin/bash
mocp -c
mocp --exit
EOF
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 11:47 am

Finally you need to install the software / packages that are needed.

Code: Select all

apt-get install at moc moc-ffmpeg-plugin -y


And let the pi announce it's woken up successfully, if there's no usb stick and it's just sitting there idle.
Following creates a script which downloads a wav file if it hasnt already, and plays it. The "sed" commands inserts this script into the startup process.

Code: Select all

cat <<'EOF' > /home/dietpi/startupsound.sh
#!bin/bash
if [ -f /home/dietpi/startup.wav ]
then
  cd /home/dietpi/
  wget "http://soundbible.com/grab.php?id=1589&type=wav" -O startup.wav
fi
aplay /home/dietpi/startup.wav
EOF
sed -i '$ish /home/dietpi/startupsound.sh' /etc/rc.local
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 12:11 pm

And my favourite bit of the whole thing, mentioned in the 2nd post:

wifi hotspot http://dietpi.com/phpbb/viewtopic.php?f ... 1207#p1207

This makes the raspberry pi into a wifi hotspot. By default it creates an SSID "dietpi-hotspot" with passphrase "dietpihotspot" so you can "ssh" into the pi and control it from your phone / ipad.
Very neat!!!
Just type mocp at the command line and away you go!

apps
https://itunes.apple.com/us/app/webssh- ... 55657?mt=8
https://play.google.com/store/apps/deta ... t&hl=en_GB
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 2:14 pm

remote control (sort of) via my phone, I've simply "ssh'd" into the pi as it's running a wifi hotspot; image shows "moc" playing Ultravox from the usb stick inserted into the pi. There's no desktop installed (i could have gone the whole hog and installed lxde + jriver mc) but moc works perfectly for this.
Simply type "mocp" at the command line, and this screen pops up allowing you to select and play songs. Left hand side is directory structure, right hand
side is the playlist, and there are many keys to control the player, stop start pause next etc. I did look into adding a small screen and buttons to control the pi but wifi hotspot + ssh access makes that unnecessary.

When it arrives, the usb socket will simply be panel mounted somewhere on the Sony boombox.

Image
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 2:53 pm

There's not a whole lot of space in there!
Started by snipping out the ridge that went between the batteries left to right, and removed the right hand spring as it was fouling the panel mounted power lead.
Also had to break up into dead space above the battery compartment to get the pi high up enough so something could connect into those dac phono sockets - went with right angled plugs in the end.

Image
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 2:59 pm

Replacing the speakers: the challenge here was finding a full range (low Hz to 20kHz) 4 ohm speaker that was dinky enough to fit where the old ones were. Had to be shallow max 40mm deep and with a magnet that wasnt too large. In the end found Monacor SP8/4 round version - a 3" speaker, 90 mm across. This fitted through the existing 92mm round hole where the originals were mounted so they could sit further forwards giving a little bit extra depth to play with. In the end, the left hand speaker was fouling part of the tape mechanism which luckily I could remove! as it was just plastic.

Image

slap bang in the middle of this photo, see the pen mark? that was my "cut here" line as the left hand speaker's magnet has to fit on the right of this photo.

Image
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 3:08 pm

New speakers fitted - very pleased how this turned out.
Ended up cutting baffles from plywood, with 70mm circular cut outs, and attaching the speakers to this with m4 bolts, sitting proud by 2 "nuts" depth so they would be forward of the original plastic baffle. Therefore requiring less depth internally - right hand speaker perfect fit! left speaker perfect once Id snipped out that bit of "excess" plastic.

Image
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 3:11 pm

Baffle close up
Had to cut round holes in the four corners (ish) to go around the original speaker fixing posts. Washers from my box of spare bits (that brass one was rescued from a broken electric shower - I always rescue screws and washers!)
The second baffle for the left hand speaker (this one is the right) was a lot neater now I knew what I was doing. Started with a sheet of clear perspex that I used as a template for positioning the holes etc. The central ones to mount the speaker itself were bang on!

Image
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

User avatar
Robert
Administrator
Administrator
Posts: 2650
Joined: Mon Nov 04, 2002 12:53 am
Contact:

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby Robert » Wed Oct 18, 2017 3:16 pm

These new speakers - despite being smaller and costing £6 each inc vat, the p&p was more than that - sound *so* much better!
https://www.audiomate.co.uk/proddetail. ... W.max-90mm
home office: Dell laptop running JRriver MC22 / Meridian Explorer / AKG 550's
music room: PC transport running JRiver MC22 / Naim DAC-V1 / Naim Supernait 2 / Neat Motive SX2
kitchen: Naim Unitiqute 2 / Naim NAP100 / Totem Dreamcatchers

RichardLowe
Hero Member
Hero Member
Posts: 825
Joined: Wed Nov 03, 2010 1:06 pm
Location: Aberdeenshire

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby RichardLowe » Wed Oct 18, 2017 7:03 pm

Excellent little project Robert, thank you for the write-up and photos. 8)
(cd xt se > ml binary star i/c) + (NAS > LAN network) > primare pre60 > atlas hyper i/c > primare a60 > atlas hyper 2.0 > boenicke w11

User avatar
STodd
Addicted
Addicted
Posts: 1320
Joined: Thu Mar 15, 2012 2:43 pm
Location: Weybridge, UK

Re: SonyPi - bringing an 80's "boombox" into the 21st C

Postby STodd » Wed Oct 18, 2017 10:12 pm

Great job Robert - must feel very rewarding 8)
MMStreamer (Teddy12/4), Sony BDP ► DAC X Sig/PSX-R || Rega P3-24 (Dino & Dino+)
Pre Xvs/PSX-R ► Mono X ► PMC GB1i || Objective2 ► Sennheiser HD558 || Bluesound PowerNode ► Focal Chorus 705V
Cables: ML Binary Star, Mark Grant G1500HD | Chord Epic ST
AG500 Mains Regen | http://www.last.fm/user/stetod