Skip to main content

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.

Metadata

Release files for qbee-gpio 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qbee-gpio 2.0.1
File Size Uploaded
qbee_gpio-2.0.1.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qbee-gpio 2.0.1
File Interpreter ABI Platform
qbee_gpio-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.4 kB

Release files / qbee_gpio-2.0.1.tar.gz

Download URL qbee_gpio-2.0.1.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ffcf1824b75d32c6017174d4844f780d7a0a8cb00b365050e00b1102d022dfe3
BLAKE2b-256 checksum
How to use checksums
c50ae4c2e5c04a9603b044670f190b8eadcd95b59353bfc092a7bc7884d96e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

Release files / qbee_gpio-2.0.1-py3-none-any.whl

Download URL qbee_gpio-2.0.1-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0de8089584071ced9347f92d55ce1914991b2605de31c13bdcda05a11784c374
BLAKE2b-256 checksum
How to use checksums
426128eea15308fafd9537969fc79a6df57e5763b52378f21af5649d650aa028
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

Release history Release notifications | RSS feed

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page