|
2 | 2 |
|
3 | 3 | This code is for a homemade internet radio. |
4 | 4 | It is based on a Raspberry Pi Zero W with a USB sound card. |
5 | | -Only controllable via a web interface was no option for me, so I added a small OLED display and a rotary encoder. |
6 | | -There is a menu to navigate through with the rotary encoder. |
7 | | -The controller chip of the little oled is the sh1106. (I bought it from ebay) |
8 | 5 |
|
9 | | -An ADS1115 with a potentiometer is used to control the ALSA volume. |
10 | | - |
11 | | -It connects to Mopidy for music playback and webradio stations and to shairport-sync for airplay status information and automatic pausing of MPD. |
| 6 | +## Features |
| 7 | +- Show currently playing title information |
| 8 | +- Rotary encoder to navigate menu on an sh1106 oled screen |
| 9 | +- Connect to MPD to play webradio stations |
| 10 | +- Receive AirPlay via Shairport-Sync with automatic pausing of MPD when connecting |
| 11 | +- ALSA Volume control with a potentiometer connected to an ADS1115 ADC |
| 12 | +- Connect to MQTT broker for volume control |
| 13 | +- FastAPI REST-API and webui to see now playing info and edit saved webradio stations |
12 | 14 |
|
13 | 15 | ## Windows/Usage |
14 | 16 | Some screenshots from the different menu windows (sometimes the font is a bit off because of the simulator): |
15 | 17 | | Now playing | Connection lost | Main Menu | |
16 | 18 | | ----------- | --------------- | --------- | |
17 | | -|  |  |  | |
| 19 | +|  |  |  | |
18 | 20 |
|
19 | | -| Radio stations | Playlist selection menu | Shutdown menu | |
| 21 | +| Radio stations | AirPlay playing | Shutdown menu | |
20 | 22 | | -------------- | ----------------------- | ------------- | |
21 | | -|  |  |  | |
| 23 | +|  |  |  | |
22 | 24 |
|
23 | 25 | When the software is started, it shows a loading screen until it gets a connection to MPD. If the connection is lost while active, it shows a little icon on the idle screen. |
24 | | -If shairport-sync is installed on the system, MPD will be paused when an AirPlay connection is established and the screen will show now playing information. You can also skip the current track or go back to the previous track using the rotary encoder controls. |
| 26 | +MPD will be paused when an AirPlay connection is established and the screen will show now playing information. |
25 | 27 |
|
26 | 28 |
|
27 | 29 | ## Installation |
28 | 30 | The code is provided without further warranty or support. There is no guarantee that it will work properly, since I am not a professional developer and only develop this project in my spare time. |
29 | | -1. Install [Raspberry Pi OS (Lite)](https://www.raspberrypi.org/downloads/raspberry-pi-os/) to your SD Card and set it up (there are lots of great guides online) |
30 | | -2. Install Mopidy/MPD and [configure it to create a playlist of radio stations](#mopidy-configuration). |
31 | | -3. Optional: Install Shairport-Sync and [enable the metadata pipe](#shairport-configuration). |
32 | | -4. Install some prerequisites: ``` sudo apt-get install python3-dev python3-pip libfreetype6-dev build-essential libopenjp2-7 libtiff5``` |
33 | | -5. Download the code: ``` git clone https://github.com/techdiem/RasPi-OLED-Menu.git oledctrl && cd ./oledctrl``` |
34 | | -6. Install python requirements: ``` pip3 install -r requirements.txt ``` (It might be necessary to install Kivy manually first) |
35 | | -7. Move the systemd config to the correct folder: ``` sudo mv oled.service /etc/systemd/system/ ``` |
36 | | -8. Reload systemd: ``` sudo systemctl daemon-reload ``` |
37 | | -9. Switch to the main code folder: ``` cd ./oled ``` |
38 | | -10. Move font files to the ```fonts``` directory, they aren't included due to their copyright. [instructions](oled/fonts/README.md) |
39 | | -11. Copy the config file ``` cp settings.example.py settings.py ``` |
40 | | -12. Set the pinout and other configuration values with ``` nano settings.py ``` |
41 | | - |
42 | | -Start it using ``` python3 oled.py ``` for debug and using ``` sudo systemctl start oled.service ``` for production. |
43 | | -To start on system boot, use ``` sudo systemctl enable oled.service ```. |
| 31 | + |
| 32 | +I'm running Alpine Linux (3.23) on the radio to reduce the memory footprint and boot time of the device. |
| 33 | +- Install [Alpine Linux](https://alpinelinux.org/downloads/) to your SD Card and set it up, also enable the community-repo `setup-apkrepos -c` |
| 34 | +- Update package cache: `apk update` |
| 35 | +- Install alsa audio system, mpd, mpc, shairport-sync and tools: `apk add alsa-utils alsa-utils-doc alsa-lib alsaconf alsa-ucm-conf nano git mpd mpc shairport-sync git nano` |
| 36 | +- Enable shairport metadata bridge like [shown below](#shairport-configuration) |
| 37 | +- Add root to audio group and enable services: `addgroup root audio && rc-service alsa start && rc-update add alsa && rc-service mpd start && rc-update add mpd` |
| 38 | +- Edit MPD config to load radio stations playlist, [see below](#mpd-configuration) |
| 39 | +- Download this project: `git clone https://github.com/techdiem/RasPi-OLED-Menu.git /opt/oledctrl && cd /opt/oledctrl` |
| 40 | +- Install python and dependencies: `apk add python3 py3-pip py3-pyalsaaudio py3-pillow py3-gpiozero py3-fastapi py3-cbor2` |
| 41 | +- Create and activate venv: `python3 -m venv --system-site-packages /opt/oledctrl/venv` |
| 42 | +- In `/etc/pip.conf` add this to download prebuilt wheels for the raspberry: |
| 43 | +``` |
| 44 | +[global] |
| 45 | +extra-index-url=https://www.piwheels.org/simple |
| 46 | +``` |
| 47 | +- Install pip dependencies: `venv/bin/pip3 install -r requirements.txt` |
| 48 | +- Create init system file: `vi /etc/init.d/oled` with the following content: |
| 49 | +``` |
| 50 | +#!/sbin/openrc-run |
| 51 | +
|
| 52 | +command=/usr/local/bin/oled.sh |
| 53 | +command_background=true |
| 54 | +output_log="/var/log/oled.log" |
| 55 | +error_log="/var/log/oled.log" |
| 56 | +pidfile=/run/{RC_SVCNAME}.pid |
| 57 | +command_args="-p ${pidfile}" |
| 58 | +``` |
| 59 | +- Create launch script `/usr/local/bin/oled.sh` with the following content: |
| 60 | +``` |
| 61 | +#!/bin/sh |
| 62 | +
|
| 63 | +cd /opt/oledctrl/oled |
| 64 | +source /opt/oledctrl/venv/bin/activate |
| 65 | +python3 oled.py |
| 66 | +``` |
| 67 | +- Switch to the main code folder: ``` cd oled ``` |
| 68 | +- Move font files to the ```fonts``` directory, they aren't included due to their copyright. [instructions](oled/fonts/README.md) |
| 69 | +- Copy the config file ``` cp settings.example.py settings.py ``` |
| 70 | +- Set the pinout and other configuration values with ``` nano settings.py ``` |
| 71 | + |
| 72 | +Start it using ``` python3 oled.py ``` for debug and using ``` rc-service oled start ``` for production. |
| 73 | +To start on system boot, use ``` rc-update enable oled ```. |
44 | 74 |
|
45 | 75 | ## Configuration notes |
46 | | -### Mopidy configuration |
47 | | -For using the radio station menu, you need to tell mopidy a path to create playlist files. The [Mopidy-MusicBox-Webclient](https://mopidy.com/ext/musicbox-webclient/) has a streams tab which saves the stations to a playlist file called `[Radio stations].m3u8`. |
48 | | -In the mopidy configuration (`/etc/mopidy/mopidy.conf`) configure the m3u component: |
| 76 | +### MPD configuration |
| 77 | +The following options should be configured at minimal: |
49 | 78 | ``` |
50 | | -[m3u] |
51 | | -enabled = true |
52 | | -base_dir = |
53 | | -default_encoding = latin-1 |
54 | | -default_extension = .m3u8 |
55 | | -playlists_dir = /music/playlists |
| 79 | +playlist_directory "/var/lib/mpd/playlists" |
| 80 | +log_file "/var/log/mpd/mpd.log" |
| 81 | +pid_file "/run/mpd/pid" |
| 82 | +user "mpd" |
| 83 | +
|
| 84 | +audio_output { |
| 85 | + type "alsa" |
| 86 | + name "USB Soundcard" |
| 87 | + device "default" |
| 88 | + mixer_control "Speaker" |
| 89 | +} |
56 | 90 | ``` |
57 | | -Enter the same folder here as in the [settings.py](oled/settings.example.py) of this control software. |
58 | | -Make sure, that the user running mopidy has read/write access to this directory! |
59 | | -Now streams added by the MusicBox-Webclient are shown in the radio menu. |
| 91 | + |
| 92 | +Enter the same folder for playlist_directory as in the [settings.py](oled/settings.example.py) of this software. |
| 93 | +Additionally, the device and mixer_control should match the ALSA config options in settings.py for the volume control to work seamlessly from both sides. |
60 | 94 |
|
61 | 95 | ### Shairport configuration |
62 | | -You need to enable the shairport metadata pipe. To do so, edit your `/etc/shairport-sync.conf` file and uncomment/edit the following options: |
| 96 | +The Shairport-Sync configuration is located at `/etc/shairport-sync.conf`. |
| 97 | + |
| 98 | +Set the following entries for volume control to be synced to the iDevice, the config should match the ALSA configuration in settings.py: |
| 99 | +``` |
| 100 | +output_backend = "alsa"; |
| 101 | +ignore_volume_control = "yes"; |
| 102 | +
|
| 103 | +alsa = |
| 104 | +{ |
| 105 | + output_device = "default"; |
| 106 | +// mixer_control_name = "Speaker"; |
| 107 | +}; |
| 108 | +``` |
| 109 | +Here, mixer_control_name is commented, because "Speaker" is the default, but you might need to change that. |
| 110 | + |
| 111 | +Second, you need to enable the shairport metadata pipe. To do so, uncomment/edit the following options: |
63 | 112 | ``` |
64 | 113 | metadata = |
65 | 114 | { |
|
0 commit comments