No description
  • Python 71.8%
  • Nix 28.2%
Find a file
2023-04-15 17:38:44 +02:00
lib further tweaks on bluetooth 2019-11-25 18:46:54 +01:00
config.json updated instructions, fix lcd display, fix retry on connection issues 2019-11-17 00:17:32 +01:00
flake.lock init flake module 2022-07-05 17:13:09 +02:00
flake.nix update to nixos-22.11 2023-04-15 17:38:44 +02:00
module.nix init flake module 2022-07-05 17:13:09 +02:00
piradio further tweaks on bluetooth 2019-11-25 18:46:54 +01:00
piradio.service add pipewire-pulse to piradio.service 2021-10-07 20:20:20 +02:00
README.md fix installation instructions 2021-10-07 20:29:38 +02:00
screenshot.jpeg updated installation instructions in README.md 2019-11-27 20:15:06 +01:00

PiRadio

Advanced modification to an existing Lenco internet radio using a Raspberry PI as hardware replacement. A demonstration video can be found here.

Maintainers

Features

  • Audio normalization
  • Auto play on startup
  • Remember volume and last station
  • Easy json configuration file
  • Bluetooth audio playback

Requirements

This project relies on some specific hardware, which was available as part of the commercial Lenco radio.

  • LCD Display HD44780 16x2 chars
  • Keypad
  • Audio amplifier with speakers
  • Raspberry PI (tested with v4)

Note: The audio amplifier and the Rasperry PI have to seperate power supplies to suppress "EMC noise". This instruction covers only the software part. Please lookup the specific data sheets for the hardware components to figure out how to wire them to your Raspberry PI. A rough pinout sketch can be found here. The pinout PiRadio is using is hardcoded into the Python source code.

Installation

Core system setup

I'm using ArchLinuxARM as the base operating system for this project.

In order to access the GPIO pins without being superuser, you have to append this UDEV rule file at /etc/udev/rules.d/raspberrypi.rules:

...

SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660"

SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
        chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
        chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
        chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
'"

Audio output has to be enabled in the boot config file /boot/config.txt as noted in the ArchLinuxARM wiki on Raspberry Pi 4:

dtparam=audio=on

Add custom repository to /etc/pacman.conf to get access to custom packages used by PiRadio:

...
[projectinsanity]
SigLevel = PackageOptional
Server = https://onny.project-insanity.org/archlinux

Install all the required libraries and runtimes:

pacman -Sy pipewire-pulse python-raspberry-gpio python-pad4pi python-pulse-control python-rplcd python-mpv sudo bluez python-dbus python-gobject iwd firmware-raspberrypi

Create users and groups

groupadd gpio
useradd -m piradio
gpasswd -a piradio audio
gpasswd -a piradio gpio

To change the default sink or audio output device, you can run following commands:

su piradio
pactl list-sinks
pactl set-default-sink 1

The number after set-default-sink is the ID of your output device.

Further, here's a fast way to auto connect your Raspberry PI to your Wifi network. First create a file at /var/lib/iwd/MY WIFI.psk, where MY WIFI represents the ESSID (name) of your network. It contains the wifi network configuration:

[Security]
Passphrase=12345678910

Create systemd-networkd configuration file for the wifi-interface at /etc/systemd/network/wlan0.network:

Match]
Name=wlan0

[Network]
DHCP=yes
DNSSEC=no

Start and enable your wifi connection with:

systemctl enable --now iwd
systemctl restart systemd-networkd

There is a dedicated bluetooth firmware package available in the alarm repository:

pacman -S firmware-brcm43xx

To enable Bluetooth on the kernel site, you'll have to append following line to /boot/config.txt:

dtparam=krnbt=on

Make the Bluetooth device stay in discoverable mode forever and set appropriate device class for audio playback, by adapting the parameters in /etc/bluetooth/main.conf:

Class = 0x00041C

Enable=Source,Sink,Media,Socket
[...]
DiscoverableTimeout = 0

Enable and start Bluetooth to apply changes:

systemctl enable --now bluetooth

PiRadio Installation

Download the program to your system

git clone https://git.project-insanity.org/onny/py-piradio.git /usr/lib/piradio

Start and enable the service to run PiRadio on boot

ln -s /usr/lib/piradio/piradio.service /etc/systemd/user/
su piradio
systemctl daemon-reload --user
systemctl enable --user --now piradio

Automatically login into piradio user so that our user services gets startet at boot:

mkdir /etc/systemd/system/getty@tty1.service.d

Create the file /etc/systemd/system/getty@tty1.service.d/override.conf with following content:

[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin piradio --noclear %I $TERM

That's all, your radio should be working now.

Configuration

You can add your internet radio stream urls to the configuration file at /usr/lib/piradio/config.json.

Credits