Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New component] HiFiBerry Sound Card & OnOff SHIM #2169

Merged
merged 59 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6475eeb
Add components folder to installation and docs. First component is hi…
pabera Dec 19, 2023
6639015
Allow for all hifiberry boards
pabera Dec 19, 2023
9d709b7
Disabling HDMI Audio
pabera Dec 20, 2023
9621133
Finalize HiFiBerry doc
pabera Dec 20, 2023
8b31685
Refer to Pi Pinout for convenience
pabera Dec 20, 2023
e1dfb53
Enable ALSA config as an option as well
pabera Dec 20, 2023
8174d34
Allow script to be run multiple times
pabera Dec 20, 2023
6ce855c
Add OnOff SHIM as component
pabera Dec 21, 2023
701f8e3
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Dec 21, 2023
a62c036
Make script more robust based on PR comments
pabera Dec 25, 2023
0427214
Update hifiberry soundcard options
pabera Jan 1, 2024
c6df305
Automate soundcard detection for asound.conf
pabera Jan 1, 2024
bfaad30
use /boot/config based on debian version
pabera Jan 1, 2024
2cac674
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Jan 2, 2024
0da4d73
Reorganize a few things
pabera Jan 2, 2024
2aa6f47
some bugfixes
pabera Jan 2, 2024
e18189b
Final fixes
pabera Jan 2, 2024
9cebeaa
Optimize case
pabera Jan 2, 2024
348413c
Update docs
pabera Jan 2, 2024
99df470
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Jan 4, 2024
56cddb7
Uninstall option
pabera Jan 11, 2024
2cf5516
fix: Remove option was not reachable
pabera Jan 11, 2024
1679be2
fix: enable sudo
pabera Jan 11, 2024
240a938
fix: make I/O fail silently
pabera Jan 11, 2024
f3e0bb8
feat: Introduce 1-line installation
pabera Jan 12, 2024
0aa34ad
feat: outsource onboard_sound as its own option
pabera Jan 12, 2024
251224a
refactor: remove alsa config
pabera Jan 12, 2024
3abef5f
fix: update case function
pabera Jan 12, 2024
61aa460
fix: adding some thens
pabera Jan 12, 2024
ee0c47c
fix: some iterations did not work
pabera Jan 12, 2024
165e07e
fix: adding another sudo
pabera Jan 12, 2024
dc89268
refactor: get_key_by_item_number for associated arrays
pabera Jan 12, 2024
7758da6
refactor: remove last bits of alsa
pabera Jan 12, 2024
cda18f9
fix: final touches
pabera Jan 12, 2024
8e584b7
fix: add missing removal only option
pabera Jan 12, 2024
3740abb
fix: outsource example_usage for 1-line install
pabera Jan 12, 2024
35189e0
fix: condition for 1-line installation
pabera Jan 12, 2024
fd67e1e
fix: another fix for if conditions
pabera Jan 12, 2024
00e03ed
refactor: move 1-line installation down
pabera Jan 12, 2024
4ff95a1
gs
pabera Jan 12, 2024
2434315
another fix
pabera Jan 12, 2024
38797d2
fix: write array check differently
pabera Jan 12, 2024
cd31cf5
refactor: final touches
pabera Jan 12, 2024
8e0707f
feat: enable silent mode for check_existing_hifiberry
pabera Jan 12, 2024
b66c430
fix: reintroduce sudo check
pabera Jan 12, 2024
3e217cc
fix: documentation
pabera Jan 12, 2024
4aa34bf
fix: final touches again
pabera Jan 13, 2024
d1e2f58
fix: remove is_sudo again
pabera Jan 13, 2024
a43bafd
fix: Remove last sudo occurrences
pabera Jan 13, 2024
8e16955
fix: bullet proof
pabera Jan 14, 2024
8c96690
Make bash files executable
pabera Jan 14, 2024
b9f1ed6
fix: Update documentation
pabera Jan 14, 2024
66acd47
fix: 1-line path does not worj
pabera Jan 14, 2024
709f576
Update documentation/builders/components/soundcards/hifiberry.md
pabera Jan 15, 2024
09b6e48
Update documentation/builders/components/soundcards/hifiberry.md
pabera Jan 15, 2024
83b5d99
Update documentation/builders/components/soundcards/hifiberry.md
pabera Jan 15, 2024
94e9bcf
fix: Update regex for commented code
pabera Jan 16, 2024
daf396e
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Jan 16, 2024
4cb9ffd
Adding OnOff Shim resource
pabera Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions documentation/builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
* [Card Database](./card-database.md)
* [Troubleshooting](./troubleshooting.md)

## Components
* [Power](./components/power/)
* [OnOff SHIM for safe power on/off](./components/power/onoff-shim.md)
* [Soundcards](./components/soundcards/)
* [HiFiBerry Boards](./components/soundcards/hifiberry.md)

## Advanced

* [Bluetooth (and audio buttons)](./bluetooth-audio-buttons.md)
Expand Down
34 changes: 34 additions & 0 deletions documentation/builders/components/power/onoff-shim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# OnOff SHIM by Pimorino

The OnOff SHIM from Pimorino allows you to savely start and shutdown your Raspberry Pi through a button. While you can switch of your Phoniebox via an RFID Card (through an RPC command), it is difficult to switch it on again without cutting the physical power supply.

## Installation

To install the software, open a terminal and type the following command to run the one-line-installer. A reboot will be required once the installation is finished.

> [!NOTE]
> The installations will ask you a few questions. You can safely answer with the default response.
pabera marked this conversation as resolved.
Show resolved Hide resolved

```
curl https://get.pimoroni.com/onoffshim | bash
```

* [Source](https://shop.pimoroni.com/products/onoff-shim?variant=41102600138)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add how to customize the shutdown command, so the Phoniebox shutdown is used (that's why I was working on pbc.c and run_rpc_tool.py).

I could add something tonight.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably, add it directly to this PR

## How to manually wire OnOff SHIM

The OnOff SHIM comes with a 12-PIN header which needs soldering. If you want to spare some GPIO pins for other purposes, you can individually wire the OnOff SHIM with the Raspberry Pi. Below you can find a table of Pins to be connected.
pabera marked this conversation as resolved.
Show resolved Hide resolved

| Board pin name | Board pin | Physical RPi pin | RPi pin name |
|----------------|-----------|------------------|--------------|
| 3.3V | 1 | 1, 17 | 3V3 power |
| 5V | 2 | 2 | 5V power |
| 5V | 4 | 4 | 5V power |
| GND | 6 | 6, 9, 20, 25 | Ground |
| GPLCLK0 | 7 | 7 | GPIO4 |
| GPIO17 | 11 | 11 | GPIO17 |

## Assembly options

![](https://cdn.review-images.pimoroni.com/upload-b6276a310ccfbeae93a2d13ec19ab83b-1617096824.jpg?width=640)

pabera marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions documentation/builders/components/soundcards/hifiberry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# HiFiBerry

## Automatic setup

Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards.

```
pabera marked this conversation as resolved.
Show resolved Hide resolved
$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo ./setup_hifiberry.sh
```

Optional: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true`

## Additional information

If you like to understand what's happening under the hood, feel free to check the [install script](../../../../installation/components/setup_hifiberry.sh).

The setup is based on [HiFiBerry's instructions](https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/).

## How to manually wire your HiFiBerry board

Most HiFiBerry boards come with 40-pin header that you can directly attach to your Pi. This idles many GPIO pins that may be required for other inputs to be attached (like GPIO buttons or RFID). You can also connect your HiFiBerry board separately. The following table show cases the pins required.

* [Raspberry Pi Pinout](https://github.com/raspberrypi/documentation/blob/develop/documentation/asciidoc/computers/os/using-gpio.adoc)

| Board pin name | Board pin | Physical RPi pin | RPi pin name |
|----------------|-----------|------------------|--------------|
| 3.3V | 1 | 1, 17 | 3V3 power |
| 5V | 2 | 2, 4 | 5V power |
| GND | 6 | 6, 9, 20, 25 | Ground |
| PCM_CLK | 12 | 12 | GPIO18 |
| PCM_FS | 36 | 36 | GPIO19 |
| PCM_DIN | 38 | 38 | GPIO20 |
| PCM_DOUT | 40 | 40 | GPIO21 |

You can find more information about manually wiring [here](https://forum-raspberrypi.de/forum/thread/44967-kein-ton-ueber-hifiberry-miniamp-am-rpi-4/?postID=401305#post401305).
109 changes: 109 additions & 0 deletions installation/components/setup_hifiberry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash

# This script follows the official HiFiBerry documentation
# https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/

# Check if the script is run as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi

check_existing_hifiberry() {
existing_config=$(grep 'dtoverlay=hifiberry-' /boot/config.txt)
if [ ! -z "$existing_config" ]; then
echo "Existing HiFiBerry configuration detected: $existing_config"
read -p "Do you want to proceed with a new configuration? This will remove the existing one. (y/n): " yn
case $yn in
[Yy]* )
remove_existing_hifiberry
return 0;;
[Nn]* )
echo "Exiting without making changes.";
exit;;
* )
echo "Please answer yes or no.";
check_existing_hifiberry;;
esac
fi
}

remove_existing_hifiberry() {
echo "Removing existing HiFiBerry configuration..."
sed -i '/dtoverlay=hifiberry-/d' /boot/config.txt
sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' /boot/config.txt
sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' /boot/config.txt
}

enable_hifiberry() {
echo "Enabling HiFiBerry board..."
grep -qxF "dtoverlay=$1" /boot/config.txt || echo "dtoverlay=$1" >> /boot/config.txt
}

check_existing_hifiberry

# List of HiFiBerry boards
echo "
Select your HiFiBerry board:
1) DAC for Raspberry Pi 1/DAC+ Light/DAC Zero/MiniAmp/Beocreate/DAC+ DSP/DAC+ RTC
2) DAC+ Standard/Pro/Amp2
3) DAC2 HD
4) DAC+ ADC
5) DAC+ ADC Pro
6) Digi+
7) Digi+ Pro
8) Amp+ (not Amp2)
9) Amp3"
read -p "Enter your choice (1-9): " choice

# Enable selected HiFiBerry board
case $choice in
1) enable_hifiberry "hifiberry-dac";;
2) enable_hifiberry "hifiberry-dacplus";;
3) enable_hifiberry "hifiberry-dacplushd";;
4) enable_hifiberry "hifiberry-dacplusadc";;
5) enable_hifiberry "hifiberry-dacplusadcpro";;
6) enable_hifiberry "hifiberry-digi";;
7) enable_hifiberry "hifiberry-digi-pro";;
8) enable_hifiberry "hifiberry-amp";;
9) enable_hifiberry "hifiberry-amp3";;
*) echo "Invalid selection. Exiting."; exit 1;;
pabera marked this conversation as resolved.
Show resolved Hide resolved
esac

echo "Disabling onboard sound..."
sed -i '/dtparam=audio=on/c\dtparam=audio=off' /boot/config.txt
pabera marked this conversation as resolved.
Show resolved Hide resolved

if grep -qx 'dtoverlay=vc4-fkms-v3d' /boot/config.txt; then
echo "Disabling audio in vc4-fkms-v3d overlay..."
sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' /boot/config.txt
fi

if grep -qx 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then
echo "Disabling audio in vc4-kms-v3d overlay..."
sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt
fi

# Check for CONFIGURE_ALSA environment variable
if [ "${CONFIGURE_ALSA}" == "true" ]; then
pabera marked this conversation as resolved.
Show resolved Hide resolved
if [ -f /etc/asound.conf ]; then
echo "Backing up existing asound.conf..."
cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)"
fi

echo "Configuring sound settings in asound.conf..."
cat > /etc/asound.conf << EOF
pabera marked this conversation as resolved.
Show resolved Hide resolved
pcm.hifiberry {
type softvol
slave.pcm "plughw:0"
control.name "HifiBerry"
control.card 0
pabera marked this conversation as resolved.
Show resolved Hide resolved
}

pcm.!default {
type plug
slave.pcm "hifiberry"
}
EOF
fi

echo "Configuration complete. Please restart your device."