Skip to main content

Control an LCD display and amplifier relay for use in an AirPlay Raspberry Pi server.

Project description

qbee-gpio

tests version python

A python script to control an LCD and amplifier relay for use in an AirPlay and/or Spotify Connect Raspberry Pi server.

  • Detect sound ouput and turn on the amplifier power supply.
  • Get the track information and display it on an LCD.
  • Auto turn off amplifier power supply and/or shutdown after set period of inactivity.

Installation

sudo python -m pip install qbee-gpio

For first time usage:

qbee --init-config

then change what you need in ~/.qbee.yaml.

Usage

qbee

Pass a -v flag for verbose logging.

Detailed setup

Qbee

For starting up automatically, create /etc/systemd/system/qbee.service file with (adjust users/paths):

[Unit]
Description=Qbee
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
User=qbee
Group=qbee
ExecStart=/usr/local/bin/qbee
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Enable to run on boot: sudo systemctl enable qbee --now.

Optionally, specify a CONFIG env variable when running the script: CONFIG="/etc/qbee.yaml" ~/.local/bin/qbee .... The default config will be located at ~/.qbee.yaml.

See all config options

Setting up shairport-sync

You can follow instructions here. Here is what I used.

Install required packages:

sudo apt install --no-install-recommends build-essential git autoconf automake libtool \
    libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev

Install shairport-sync:

git clone https://github.com/mikebrady/shairport-sync.git
cd shairport-sync
autoreconf -fi
./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-metadata
make
make install
cd ../ && rm -rf shairport-sync

Edit /etc/shairport-sync.conf file, uncomment the metadata block to enable:

metadata =
{
        enabled = "yes";
        include_cover_art = "no";
        pipe_name = "/tmp/shairport-sync-metadata";
        pipe_timeout = 5000;
};

Enable to run on boot: sudo systemctl enable shairport-sync --now.

Setting up Librespot

If Raspotify is available on your system, use it, otherwise, you will need to compile librespot.

For starting up automatically, create /lib/systemd/system/librespot.service file with (adjust users/paths):

[Unit]
Description=Librespot
After=sound.target
Requires=avahi-daemon.service
After=avahi-daemon.service
Wants=network-online.target
After=network.target network-online.target

[Service]
User=qbee
Group=qbee
EnvironmentFile=/etc/librespot.env
ExecStart=/usr/bin/librespot
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

The conf /etc/librespot.env should look like:

LIBRESPOT_NAME="Qbee"

LIBRESPOT_QUIET=

LIBRESPOT_ENABLE_VOLUME_NORMALISATION=
LIBRESPOT_BITRATE="320"
LIBRESPOT_BACKEND="alsa"
LIBRESPOT_INITIAL_VOLUME="40"

LIBRESPOT_ONEVENT="/usr/local/bin/librespot-pipe.sh"

QBEE_LIBRESPOT_METADATA_PIPE="/tmp/librespot-metadata"

You will also need to set up the script to pipe events to Qbee in /usr/local/bin/librespot-pipe.sh and make it executable:

#!/usr/bin/bash

# Expose track_changed librespot events in a named pipe.

# Only expose track changed events.
if [ "$PLAYER_EVENT" != 'track_changed' ]; then
  exit 0
fi
# Need a named pipe.
if [ "$QBEE_LIBRESPOT_METADATA_PIPE" == '' ]; then
  exit 0
fi
# It must already be opened for reading.
if ! [ -p "$QBEE_LIBRESPOT_METADATA_PIPE" ] ; then
  exit 0
fi
artist=$(printf '%s' "$ARTISTS" | base64)
album=$(printf '%s' "$ALBUM" | base64)
title=$(printf '%s' "$NAME" | base64)
printf 'artist:%s,album:%s,title:%s\t' "$artist" "$album" "$title" > "$QBEE_LIBRESPOT_METADATA_PIPE"

Setting up Hifiberry DAC

Edit /boot/config.txt to add:

dtparam=audio=on
dtoverlay=hifiberry-dac

To disable the built-in sound card, edit /etc/modprobe.d/raspi-blacklist.conf to add:

blacklist snd_bcm2835

Edit /etc/asound.conf to set the default sound card for alsa, add:

defaults.pcm.card 0
defaults.ctl.card 0

Disable Pi GPU

This should help give more power to the CPU, useful for older Pis. Edit /boot/config.txt and add:

gpu_mem=16
disable_l2cache=0  # For pi 1 only
gpu_freq=250

Full circuit diagram

The relay turns on the 24 VDC power supply, which powers the amplifier, the LCD backlight and a green status LED.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qbee_gpio-2.0.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

qbee_gpio-2.0.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file qbee_gpio-2.0.1.tar.gz.

File metadata

  • Download URL: qbee_gpio-2.0.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

File hashes

Hashes for qbee_gpio-2.0.1.tar.gz
Algorithm Hash digest
SHA256 ffcf1824b75d32c6017174d4844f780d7a0a8cb00b365050e00b1102d022dfe3
MD5 dbd1b67f1a1ccfa45171763815a73c8a
BLAKE2b-256 c50ae4c2e5c04a9603b044670f190b8eadcd95b59353bfc092a7bc7884d96e08

See more details on using hashes here.

File details

Details for the file qbee_gpio-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: qbee_gpio-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

File hashes

Hashes for qbee_gpio-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0de8089584071ced9347f92d55ce1914991b2605de31c13bdcda05a11784c374
MD5 d1ebad95977965514c7631fe551fff42
BLAKE2b-256 426128eea15308fafd9537969fc79a6df57e5763b52378f21af5649d650aa028

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page