# luniebox lunibox is a RFID jukebox based on a Raspberry Pi. It is similar to the [Phoniebox](https://www.phoniebox.de) \[[https://github.com/MiczFlor/RPi-Jukebox-RFID](GitHub)\] and an upgrade of the [TonUINO (de)](https://www.voss.earth/tonuino/) which both are DIY versions of the popular Toniebox©. The main focus for now is to play Spotify© content, playing local files or other sources will be integrated later. ## Prerequisites You need to be familiar with ssh (Putty on Windows). For the usage of Spotify© a premium account is required. ### Hardware - Raspberry Pi (tested with Raspberry Pi 3 Model B, Zero W, Zero 2 W) \[starting at ~14€\] - power supply (5V ~2.5A) \[starting at ~6€\] - Micro SD card (at least 4GB) \[starting at ~4€\] - RC522 RFID Reader connected to [TODO] \[starting at ~1.50€\] - RFID (MiFare) cards or chips \[starting at ~2€\] - a Audio Card: - Pimoroni Audio Amp SHIM (3W Mono Amp) \[starting at ~11€\] with passive speaker \[starting at ~5€\] - Pimoroni Audio DAC SHIM \[starting at ~14€\] with active speaker - Adafruit Speaker Bonnet for Raspberry Pi - ...something else (use custom setup!) - (optional) MPU9250 9-axis sensor [TODO] \[starting at ~1.50€\] - (optional) Waveshare UPS HAT + 2x 18650 18650 Li battery \[starting at ~30€\] - some wires or dupont connectors \[starting at ~2€\] - case for all above - depending on hardware: soldering equipment A minimal setup (Raspberry Zero 2 W, power supply, Micro SD, RC522, Cards, Audio Amp) should be about ~40€ plus case materials. ### Software - latest Raspberry Pi OS blank installation on Micro SD card (Instructions: [raspberrypi.com/software/](https://www.raspberrypi.com/software/)) - WiFi connection - ssh enabled ### Optional: Headless installation If you're using a Raspberry Pi Zero or have missing peripherals to setup WiFi and ssh please perform the following steps: - insert Micro SD card with Raspberry Pi OS into a computer - place an empty file called `ssh` into `/boot` folder/partioon - place a filed called `wpa_supplicant.conf` into `/boot` folder/partition with following content ``` country=$COUNTRY_CODE ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="$WIFI_SSID" psk="$WIFI_PASSWORD" } ``` - replace `$COUNTRY_CODE` with upper-case country code (eg. GB or DE) and `$WIFI_SSID` and `$WIFI_PASSWORD` with your WiFi credentials - plug card back into your Pi and connect power supply ## Setup Establish a ssh connection to your Pi: - the Pi should be reachable under `raspberrypi` or `raspberrypi.local` in your network, if not try to find out it's IP address from your router. - default username is `pi` and default password is `raspberry` - Example: `ssh pi@raspberrypi.local` or `ssh pi@192.168.2.100` > ⚠️ Warning: you should change the default passwort by executing `passwd` after login ### Automatic setup > ⚠️ Warning: executing scripts from the internet without checking is bad. This is only done to get things done fast. In any doubts you can perform the [Manual setup](#manual-setup) and execute all commands step-by-setop to understand what's going on. - download and excecute setup script (you will be prompted to confirm certain steps beforehand anyway) > `curl https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh -o luniebox.sh` > > `chmod +x luniebox.sh` > > `./luniebox.sh` ### Manual setup #### Software setup go to home directory > `cd /home/pi` install `git`, `python3-venv` and `python3-pip` > `sudo apt install -y git python3-venv python3-pip` clone repository `https://git.bstly.de/Lurkars/luniebox.git` with sources and config: > `git clone https://git.bstly.de/Lurkars/luniebox.git luniebox` setup application > `cd /home/pi/luniebox/application` > > `python -m venv venv` > > `source venv/bin/activate` > > `export CFLAGS=-fcommon` > > `pip install -r requirements.txt` > > `deactivate` > > `mkdir /home/pi/luniebox/config` > > `cp /home/pi/luniebox/contrib/config/luniebox.cfg /home/pi/luniebox/config/luniebox.cfg` > > `sudo cp /home/pi/luniebox/contrib/luniebox-app.service /etc/systemd/system/` > > `sudo cp /home/pi/luniebox/contrib/luniebox-daemon.service /etc/systemd/system/` > > `sudo systemctl daemon-reload` > > `sudo systemctl enable luniebox-app luniebox-daemon` setup spotifyd > `mkdir /home/pi/luniebox/bin` > > `wget -c https://github.com/Spotifyd/spotifyd/releases/download/v0.3.3/spotifyd-linux-armv6-slim.tar.gz -O - | tar -xz -C /home/pi/luniebox/bin` > > `cp /home/pi/luniebox/contrib/config/spotifyd.cfg /home/pi/luniebox/config/spotifyd.cfg` (if you use other audio hardware, you may need to adjust the `backend` and `device` properties to your needs!) > > `sudo cp /home/pi/luniebox/contrib/spotifyd.service /etc/systemd/system/` > > `sudo systemctl daemon-reload` > > `sudo systemctl enable spotifyd` setup mpd > `mkdir /home/pi/luniebox/library` > > `sudo apt install -y mpd` > > `sudo cp /home/pi/luniebox/contrib/config/mpd.conf /etc/mpd.conf` (if you use other audio hardware, you may need to adjust the `audio_output` section to your needs!) > start/restart all services > `sudo systemctl restart mpd spotifyd luniebox-daemon luniebox-app` setup ClSpotify > `git clone https://github.com/agent255/clspotify.git /home/pi/clspotify` > > `cd /home/pi/clspotify` > > `python -m venv venv` > > `source venv/bin/activate` > > `pip install -r requirements.txt` > > `deactivate` > > `sed -i -i 's/^zspotify_path =.*$/zspotify_path = \/home\/pi\/clspotify\//' /home/pi/luniebox/config/luniebox.cfg` #### Hardware Setup ##### enable SPI for RFID Reader uncomment `dtparam=spi=on` in `/boot/config.txt` > `sudo sed -i '/dtparam=spi=on/s/^#//g' /boot/config.txt` ##### enable I2C for MPU9250 9-axis sensor install `i2c-tools` and `python3-smbus` > `sudo apt install -y i2c-tools python3-smbus` uncomment `dtparam=i2c_arm=on` in `/boot/config.txt` > `sudo sed -i '/dtparam=i2c_arm=on/s/^#//g' /boot/config.txt` add `dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24` to `/boot/config.txt` > `printf "dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24" | sudo tee -a /boot/config.txt` #### Setup Audio ##### for Pimoroni Amp or DAC disable onboard audio comment out `dtparam=audio=on` in `/boot/config.txt` > `sudo sed -i '/dtparam=audio=on/s/^/#/g' /boot/config.txt` setup hifiberry-dac by adding ``` dtoverlay=hifiberry-dac gpio=25=op,dh ``` to `/boot/config.txt` > `printf "dtoverlay=hifiberry-dac\ngpio=25=op,dh" | sudo tee -a /boot/config.txt` ##### for Adafruit Speaker Bonnet for Raspberry Pi disable onboard audio comment out `dtparam=audio=on` in `/boot/config.txt` > `sudo sed -i '/dtparam=audio=on/s/^/#/g' /boot/config.txt` setup hifiberry-dac and i2s by adding ``` dtoverlay=hifiberry-dac dtoverlay=i2s-mmap ``` to `/boot/config.txt` > `printf "dtoverlay=hifiberry-dac\ndtoverlay=i2s-mmap" | sudo tee -a /boot/config.txt` create `/etc/asound.conf` file with following content: ``` pcm.speakerbonnet { type hw card 0 } pcm.dmixer { type dmix ipc_key 1024 ipc_perm 0666 slave { pcm "speakerbonnet" period_time 0 period_size 1024 buffer_size 8192 rate 44100 channels 2 } } ctl.dmixer { type hw card 0 } pcm.softvol { type softvol slave.pcm "dmixer" control.name "PCM" control.card 0 } ctl.softvol { type hw card 0 } pcm.!default { type plug slave.pcm "softvol" } ``` After setup, reboot system. > `sudo reboot` ## Planned features - status LEDs - indicators for UPS HAT - WiFi Hotspot (https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/158-raspberry-pi-auto-wifi-hotspot-switch-direct-connection)