# luniebox

**luniebox** is a RFID jukebox based on a Raspberry Pi. It is similar to the [Phoniebox](https://www.phoniebox.de) \[[GitHub](https://github.com/MiczFlor/RPi-Jukebox-RFID)\] 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 and playing local files (also supports Spotify© download for offline use). 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 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 \[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) 2x Push Buttons for volume control \[starting at ~1€\]
- (optional) MPU9250 9-axis sensor \[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, Speaker, Buttons) should be about ~45€ 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

Open terminal on your pi or 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 password by executing `passwd` after login**

### Hardware connection

For a detailed Raspberry Pi pinout take a look at [https://pinout.xyz](https://pinout.xyz).

#### Connect RC522 RFID Reader

- SDA to Pin 24 \[GPIO 8 / SPI0 CE0\]
- SCK to Pin 23 \[GPIO 11 / SPI0 SCLK / CLK\]
- MOSI to Pin 19 \[GPIO 10 / SPI0 MOSI\] 
- MISO to Pin 21 \[GPIO 9 / SPI0 MISO\]
- GND to Pin 20 \[Ground\]
- RST to Pin 22 \[GPIO 25\]
- 3.3v to Pin 1 \[3v3 Power\]

#### Connect Push Buttons

- first push button (volume down)
  1. Pin 8 \[GPIO 14\]
  2. Pin 6 \[Ground\]

- second push button (volume up)
  1. Pin 7 \[GPIO 4\]
  2. Pin 9 \[Ground\]

#### Connect MPU9250 9-axis sensor

- SDA to Pin 16 \[GPIO 23\]
- SCL to Pin 18 \[GPIO 24\]
- GND to Pin 14 \[Ground\]
- 3V3 to Pin 17 \[3v3 Power\]


### Installation

By downloading and executing the [luniebox.sh](luniebox.sh) script you go trough an interactive installation process. You can also pass the `-a` argument to skip any prompts. Use the `-h` argument for detailed parameter to configure automatic installation directly to choose for example your audio device.

> **⚠️ 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 installation manually and execute all commands step-by-step to understand what's going on. For a detailed instruction got to the [INSTALL](INSTALL.md) document.**

- interactive

  ```
  bash <(curl -s https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh)
  ```

- full automatic

  ```
  bash <(curl -s https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh) -a
  ```

- alternative first download script, take a look and then execute

  ```
  curl https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh -o luniebox.sh
   
  chmod +x luniebox.sh

  ./luniebox.sh
  ```

## 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)
