Skip to main content

mocassino

Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats

Overview

mocassino is a service turning a Raspberry Pi device with a Pimoroni Pirate Audio hat into a standalone audio player for local audio files that can be used even when fully offline.

The service handles the four buttons of the hat, pilots its display, and delegates the playback to MOC (music on console), which it controls by running mocp commands.

Mocassino running on a Raspberry Pi Zero 2 with Pimoroni Pirate Audio Headphone Amp in a Flirc case

The supported Pimoroni Pirate Audio hats are those featuring the 1.3" IPS color LCD display (240x240 px, ST7789 driver) with four tactile buttons and a DAC:

Features

  • Playback control with the buttons of the hat: play/pause, previous/next track, seek backward/forward, volume down/up
  • Playback information rendered on the display of the hat: artist, title, and album of the current track, playback progress, volume, etc.
  • Adjustable screen brightness and timeout
  • Configurable, minimal UI (elements, colors, etc.)
  • Music library directory browser: select a directory or a single audio file to play
  • Menu to change most of the settings of the running service
  • Settings stored in a YAML configuration file
  • Save the playback state and volume on exit, and restore them on the next boot
  • Configurable behavior on boot and on exit
  • To develop/debug on a PC without the hardware: built-in Tk-based simulator for the display and the buttons

Requirements

  • One of the supported Raspberry Pi devices: 3, 4, 5, Zero, Zero 2
  • One of the supported Pimoroni Pirate Audio hats listed above
  • An SD card or SSD with a (64-bit) OS based on Debian 13 (trixie) installed (e.g., Raspberry Pi OS Full or Lite, DietPi, etc.)
  • Some local audio files (FLAC, MP3, OGG, WAV) to play

Make sure your /boot/firmware/config.txt has the following entries:

# enable SPI
dtparam=spi=on

# prevent pin GPIO 9 to be claimed for MISO,
# as it is needed to drive the hat display
dtoverlay=spi0-2cs,no_miso

# enable the DAC
dtoverlay=hifiberry-dac
gpio=25=op,dh

Installation

Download the install script:

cd /tmp
curl -kO https://raw.githubusercontent.com/pettarin/mocassino/refs/heads/main/install.sh

Inspect all the available options by issuing the --help option:

bash install.sh --help
Usage: bash install.sh [options]

Options:
  --alsa-card-number NUMBER             Use the ALSA card NUMBER for the software volume control (default: '0')
  --display-orientation [0|90|180|270]  Configure the specified display orientation (default: '0')
  --library-directory-path PATH         Configure the specified PATH as the root directory for the library (default: '/')
  --no-install-apt-dependencies         Do not install the required APT packages (alsa-utils build-essential liblgpio-dev moc python3-dev python3-pip python3-venv swig)
  --no-install-sudoers                  Do not install the sudoers file
  --no-install-systemd                  Do not install the systemd service
  --no-install-venv                     Do not install the virtual environment
  --no-uninstall-first                  Do not remove a previous installation before installing
  --no-write-alsa-configuration         Do not write the ALSA configuration to file
  --no-write-configuration              Do not write the configuration to file
  --run-arguments STRING                Use the provided STRING as argument to the ExecStart command line of the systemd service (default: 'run --foreground')
  --run-as-group STRING                 Use the provided STRING as group for the service (default: 'audio')
  --run-as-user STRING                  Use the provided STRING as user for the service, creating it if it does not exist (default: 'mocassino')
  --uninstall                           Remove a previous installation and exit
  --uninstall-user                      When removing a previous installation, also remove the user created by this script

Note: this script must be executed as root, for instance with sudo

To install the service with the default options, which should be fine for most users, simply execute the script without arguments nor options:

sudo bash install.sh
[INFO] Running installation as:   '0' (root)
[INFO] Systemd service to run as:
[INFO]   group: 'audio'
[INFO]    user: 'mocassino'
...
    The installation takes between 1 and 5 minutes,
    depending on the device and your connection.
...
[INFO] Installation of mocassino complete

The last steps of the installation script start the service (you should see the application GUI drawn on the display, similar to the screenshots shown below), and then print its status:

...
[INFO] Installing systemd service ...
Created symlink '/etc/systemd/system/multi-user.target.wants/mocassino.service' → '/usr/lib/systemd/system/mocassino.service'.
● mocassino.service - Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats
     Loaded: loaded (/usr/lib/systemd/system/mocassino.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-11-28 22:34:55 CET; 1s ago
 Invocation: cefe7dfa63c84cda8cb2c782972b8d68
       Docs: https://github.com/pettarin/mocassino
    Process: 1431 ExecStartPre=/usr/bin/aplay -D default -f cd -d 1 /dev/zero (code=exited, status=0/SUCCESS)
   Main PID: 1433 (mocassino)
      Tasks: 1 (limit: 448)
        CPU: 1.161s
     CGroup: /system.slice/mocassino.service
             └─1433 /opt/mocassino/venv/bin/python3 /opt/mocassino/venv/bin/mocassino run --foreground

Nov 28 22:34:54 zephyr systemd[1]: Starting mocassino.service - Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats...
Nov 28 22:34:54 zephyr aplay[1431]: Playing raw data '/dev/zero' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Nov 28 22:34:55 zephyr systemd[1]: Started mocassino.service - Lightweight audio player based on MOC for Raspberry Pi devices with Pimoroni Pirate Audio hats.
[INFO] Installing systemd service ... done
[INFO] Installation of mocassino complete

Some application settings can be specified at install time, so that they are applied out-of-the-box instead of requiring the user to change them via the application GUI or editing the configuration file. For example, to rotate the display by 180 degrees (which is useful when using a Flirc case for a Raspberry Pi Zero 2 ) and to set the root directory of the music library at /music (make sure that user mocassino and/or group audio can read and traverse it!) instead of the default /:

sudo bash install.sh --display-orientation 180 --library-directory-path /music
[INFO] Running installation as:   '0' (root)
[INFO] Systemd service to run as:
[INFO]   group: 'audio'
[INFO]    user: 'mocassino'
...
[INFO] Configuration arguments:
[INFO]      --display-orientation '180'
[INFO]   --library-directory-path '/music'
...

To uninstall the service and remove all the files created by it:

sudo bash install.sh --uninstall
[INFO] Running installation as:   '0' (root)
...
[INFO] Uninstalling service mocassino ...
...
[INFO] Uninstalling service mocassino ... done
[INFO] Option --uninstall specified: exit without installing service mocassino

Manual Installation (Developers And Advanced Users)

mocassino is published on PyPI as the same-name package mocassino.

Developers and advanced users might want to setup a development environment instead of relying on the installation script described above. See the DEVELOPMENT documentation for the details.

GUI Usage

The installation script installs mocassino as a systemd service, which is started automatically when the device boots up (and immediately after its installation).

The MOC server is started automatically by mocassino, if it is not already running.

Buttons

With the default display orientation 0, the four buttons are located as described in the following table:

Button Label Location
A Top Left
B Bottom Left
X Top Right
Y Bottom Right

Mocassino with display with rotation 0 (audio jack on the left)

When a different orientation is selected, the actions are attached to the location of the button with respect to the display. For instance, when orientation 180 is selected, the following mapping takes place:

Button Label Location Acts As Button ... In Orientation 0
Y Top Left A
X Bottom Left B
B Top Right X
A Bottom Right Y

Mocassino with display with rotation 180 (audio jack on the right)

Similarly for orientations 90 and 270.

Playback Screen

The first time the service runs, immediately after its installation, it shows the following "Playback Screen":

Playback screen after setup

After selecting a directory or file to play (see Section "Library Menu" below for the details), the "Playback Screen" will be similar to the following:

Playback screen after open

In the Settings > Display > UI Elements menu it is possible to select what UI elements are shown or hidden. For example, the side icons at the corners, the playlist progress bar on the left, and the volume bar on the right can be hidden:

Playback screen without side icons

Buttons

The default actions for the four buttons of the hat while the "Playback Screen" is displayed are:

Button Location Short Press Long/Hold Press
Top left Play/pause Open the menu
Bottom left Next track Previous track
Top right Volume up Seek forward
Bottom right Volume down Seek backward

Menu Screen

The "Main" menu screen is as shown by the next screenshot:

Main menu

Pressing the Top Left button will go back to the "Playback Screen". In general, the Top Left button acts as a "back one level" or "cancel" button, no matter the nesting level of the menu currently displayed.

Pressing the Top or Bottom Right buttons will cycle through the various menu items upwards or downwards (with wrap-around at top and bottom), highlighting the current item.

Menu items with a > on the right can be highlighted (with Top/Bottom Right buttons, as explained in the previous paragraph) and then selected by pressing the Bottom Left button: the corresponding submenu or choices will be displayed.

Menu items with a square box on the right represent a boolean value (■ for true, ☐ for false): highlighting it (Top/Bottom Right buttons) and selecting it (Bottom Left button) will toggle the corresponding boolean value.

Library Menu

Selecting the "Library" submenu in the "Main" menu enters the browser of the music library directory, showing all directories and files that are direct children of the it:

Library menu 1

A directory can be highlighted and selected to enter it:

Library menu 2 Library menu 3 Library menu 4

Selecting the "Play this folder" item (or a selecting a single file) regenerates the current playlist, adding the appropriate file(s), possibly recursively inspecting subdirectories of the selected directory, and returns to the "Playback Screen" view, starting the playback.

The above screenshots show a music library organized in a hierarchical tree by author (Francesco_De_Gregori) and album (Titanic).

Settings Menu

Settings menu

Submenus (first level only; to see a screenshot of all the submenus, consult the detailed GUI Usage documentation):

Settings > Display menu Settings > Playback menu Settings > Run menu Settings > Startup menu Settings > Reset all settings menu

Examples of different UI elements shown/hidden:

Settings > Display > UI elements menu with all elements shown Settings > Display > UI elements menu with all elements shown, corresponding screen

Settings > Display > UI elements menu with no side bars shown Settings > Display > UI elements menu with no side bars shown, corresponding screen

Settings > Display > UI elements menu with no side bars nor timers shown Settings > Display > UI elements menu with no side bars nor timers shown, corresponding screen

Settings > Display > UI elements menu with only timers shown Settings > Display > UI elements menu with only timers shown, corresponding screen

System Menu

System menu

Submenus:

System > Restart service menu System > Reboot menu System > Shutdown menu

About Mocassino Menu

About mocassino menu

Submenus:

About mocassino > Host menu About mocassino > OS menu About mocassino > Python menu

Buttons

The default actions for the four buttons of the hat while the "Menu Screen" is displayed are:

Button Location Short Press Long/Hold Press
Top left Back one level (None)
Bottom left Select (None)
Top right Up Select
Bottom right Down Select

Configuration Files

The permanent settings are stored in the file located at /opt/mocassino/run/.config/mocassino/configuration.yaml, an example of which can be found at res/configuration/configuration.yaml. Most of the settings can be changed directly through the service menus, thus not requiring a local or SSH connection to the device running mocassino.

The state of the player is stored in the file located at /opt/mocassino/run/.config/mocassino/state.yaml file, an example of which can be found at res/configuration/state.yaml. Regular users do not need to alter this file.

CLI Usage

The CLI Usage guide describes all the commands, subcommands, and most of the options of the CLI tool mocassino.

Releases And Changelog

The list of releases and their changes is contained in the CHANGELOG document.

Development

Consult the DEVELOPMENT document to learn how to set up a development environment, run the tests, and browse the project structure.

The CONTRIBUTING document explains how to report issues and propose changes.

License

This project is licensed under the GNU General Public License v3.0 or later (GPLv3+).

See the LICENSE file for details.

The bundled Roboto Regular font is licensed under the SIL Open Font License 1.1, see the OFL.txt file for details.

Authors

  • Alberto Pettarin (Web)

Metadata

Release files for mocassino 0.0.10

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

Source distribution (sdist)

Source distribution for mocassino 0.0.10
File Size Uploaded Provenance Actions
mocassino-0.0.10.tar.gz 368.4 kB Without provenance Details for mocassino-0.0.10.tar.gz

Release files / mocassino-0.0.10.tar.gz

Download URL mocassino-0.0.10.tar.gz
Size 368.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d1496c62146dd7029ca8c30c41e7f35f9c56eff1ec6596678b775b5ed7b0a3c4
BLAKE2b-256 checksum
How to use checksums
5370f82892775e88dda40cbe6c416ca8fa9543a7f8cda91dc269874126b16623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for mocassino 0.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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