Skip to content

Commit

Permalink
Merge pull request #3661 from raspberrypi/develop
Browse files Browse the repository at this point in the history
Roll out copy updates to prod
  • Loading branch information
nathan-contino committed May 17, 2024
2 parents f211e2f + 952058e commit bc3e078
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 38 deletions.
22 changes: 17 additions & 5 deletions documentation/asciidoc/accessories/audio/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ There are a number of third-party audio software applications available for Rasp

If you need to configure Raspberry Pi OS yourself, perhaps if you're running a headless system of your own and don't have the option of control via the GUI, you will need to make your Raspberry Pi audio board the primary audio device in Raspberry Pi OS, disabling the Raspberry Pi’s on-board audio device. This is done by editing the xref:../computers/config_txt.adoc#what-is-config-txt[`/boot/firmware/config.txt`] file. Using a Terminal session connected to your Raspberry Pi via SSH, run the following command to edit the file:

[source,console]
----
$ sudo nano /boot/firmware/config.txt
----
Expand All @@ -18,8 +19,9 @@ Find the `dtparam=audio=on` line in the file and comment it out by placing a # s
#dtparam=audio=on
----

Press CTRL+X, then Y and Enter to save, followed by a reboot of your Raspberry Pi in order for the settings to take effect.
Press `Ctrl+X`, then the `Y` key, then *Enter* to save. Finally, reboot your Raspberry Pi in order for the settings to take effect.

[source,console]
----
$ sudo reboot
----
Expand All @@ -36,6 +38,7 @@ All the necessary mounting hardware including spacers, screws and connectors is

There are multiple versions of the audio cards, and the version that you possess determines the actions required to configure it. Older IQaudIO-marked boards (black PCB) are electrically equivalent to the Raspberry Pi-branded boards (green PCB) but have different EEPROM contents. The following command can be used to confirm which version you have:

[source,console]
----
$ grep -a . /proc/device-tree/hat/*
----
Expand Down Expand Up @@ -74,24 +77,28 @@ Preconfigured scripts (loadable ALSA settings) https://github.com/raspberrypi/Pi

The Codec Zero needs to know which of these input and output settings are being used each time the Raspberry Pi powers on. Using a Terminal session on your Raspberry Pi, run the following command to download the scripts:

[source,console]
----
$ git clone https://github.com/raspberrypi/Pi-Codec.git
----

If git is not installed, run the following command to install it:

[source,console]
----
$ sudo apt install git
----

The following command will set your device to use the on-board MEMS microphone and output for speaker playback:

[source,console]
----
$ sudo alsactl restore -f /home/pi/Pi-Codec/Codec_Zero_OnboardMIC_record_and_SPK_playback.state
$ sudo alsactl restore -f /home/<username>/Pi-Codec/Codec_Zero_OnboardMIC_record_and_SPK_playback.state
----

In order for your project to operate with your required settings when it is powered on, edit the `/etc/rc.local` file. The contents of this file are run at the end of every boot process, so it is ideal for this purpose. Edit the file:

[source,console]
----
$ sudo nano /etc/rc.local
----
Expand All @@ -112,19 +119,21 @@ Add the chosen script command above the exit 0 line and then Ctrl X, Y and Enter
#
# By default this script does nothing.
sudo alsactl restore -f /home/pi/Pi-Codec/Codec_Zero_OnboardMIC_record_and_SPK_playback.state
sudo alsactl restore -f /home/<username>/Pi-Codec/Codec_Zero_OnboardMIC_record_and_SPK_playback.state
exit 0
----

Ctrl X, Y and Enter to save and reboot your device for the settings to take effect:
Press `Ctrl+X`, then the `Y` key, then *Enter* to save. Reboot for the settings to take effect:

[source,console]
----
$ sudo reboot
----

If you are using your Raspberry Pi and Codec Zero in a headless environment, there is one final step required to make the Codec Zero the default audio device without access to the GUI audio settings on the desktop. We need to create a small file in your home folder:

[source,console]
----
$ sudo nano .asoundrc
----
Expand All @@ -138,8 +147,9 @@ pcm.!default {
}
----

Ctrl X, Y and Enter to save, and reboot once more to complete the configuration:
Press `Ctrl+X`, then the `Y` key, then *Enter* to save. Reboot once more to complete the configuration:

[source,console]
----
$ sudo reboot
----
Expand Down Expand Up @@ -184,6 +194,7 @@ solution.

The amp will start up muted. To unmute the amp:

[source,console]
----
$ sudo sh -c "echo 22 > /sys/class/gpio/export"
$ sudo sh -c "echo out >/sys/class/gpio/gpio22/direction"
Expand All @@ -192,6 +203,7 @@ $ sudo sh -c "echo 1 >/sys/class/gpio/gpio22/value"

to mute the amp once more:

[source,console]
----
$ sudo sh -c "echo 0 >/sys/class/gpio/gpio22/value"
----
24 changes: 13 additions & 11 deletions documentation/asciidoc/accessories/audio/getting_started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ Make sure that you update your operating system before proceeding and follow the

Open a shell — for instance by connecting via SSH — on your Raspberry Pi and run the following to create our Python script:

[source,console]
----
$ sudo nano chatter_box.py
----

Adding the following to the file:
Add the following to the file, replacing `<username>` with your username:

[source,python]
----
#!/usr/bin/env python3
from gpiozero import Button
Expand All @@ -48,18 +50,18 @@ print(f"{date}")
# Make sure that the 'sounds' folder exists, and if it does not, create it
path = '/home/pi/sounds'
path = '/home/<username>/sounds'
isExist = os.path.exists(path)
if not isExist:
os.makedirs(path)
print("The new directory is created!")
os.system('chmod 777 -R /home/pi/sounds')
os.system('chmod 777 -R /home/<username>/sounds')
# Download a 'burp' sound if it does not already exist
burp = '/home/pi/burp.wav'
burp = '/home/<username>/burp.wav'
isExist = os.path.exists(burp)
if not isExist:
Expand All @@ -81,18 +83,18 @@ def released():
print("Released at %s after %.2f seconds" % (release_time, pressed_for))
if pressed_for < button.hold_time:
print("This is a short press")
randomfile = random.choice(os.listdir("/home/pi/sounds/"))
file = '/home/pi/sounds/' + randomfile
randomfile = random.choice(os.listdir("/home/<username>/sounds/"))
file = '/home/<username>/sounds/' + randomfile
os.system('aplay ' + file)
elif pressed_for > 20:
os.system('aplay ' + burp)
print("Erasing all recorded sounds")
os.system('rm /home/pi/sounds/*');
os.system('rm /home/<username>/sounds/*');
def held():
print("This is a long press")
os.system('aplay ' + burp)
os.system('arecord --format S16_LE --duration=5 --rate 48000 -c2 /home/pi/sounds/$(date +"%d_%m_%Y-%H_%M_%S")_voice.m4a');
os.system('arecord --format S16_LE --duration=5 --rate 48000 -c2 /home/<username>/sounds/$(date +"%d_%m_%Y-%H_%M_%S")_voice.m4a');
button.when_pressed = pressed
button.when_released = released
Expand All @@ -102,7 +104,7 @@ pause()
----

Ctrl X, Y and Enter to save. To make the script executable, type the following:
Press `Ctrl+X`, then the `Y` key, then *Enter* to save. To make the script executable, type the following:

----
$ sudo chmod +x chatter_box.py
Expand All @@ -114,10 +116,10 @@ Enter the following to create a crontab daemon that will automatically start the
$ crontab -e
----

You will be asked to select an editor; we recommend you use `nano`. Select it by entering the corresponding number, and press Enter to continue. The following line should be added to the bottom of the file:
You will be asked to select an editor; we recommend you use `nano`. Select it by entering the corresponding number, and press Enter to continue. The following line should be added to the bottom of the file, replacing `<username>` with your username:

----
@reboot python /home/pi/chatter_box.py
@reboot python /home/<username>/chatter_box.py
----

Ctrl X, Y and Enter to save, then reboot your device.
Expand Down
9 changes: 5 additions & 4 deletions documentation/asciidoc/accessories/audio/hardware-info.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ $ sudo alsactl store

You can save the current state to a file, then reload that state at startup.

To save:
To save, run the following command, replacing `<username>` with your username:

[source,console]
----
$ sudo alsactl store -f /home/pi/usecase.state
$ sudo alsactl store -f /home/<username>/usecase.state
----

To restore a saved file:
To restore a saved file, run the following command, replacing `<username>` with your username:

----
$ sudo alsactl restore -f /home/pi/usecase.state
$ sudo alsactl restore -f /home/<username>/usecase.state
----

=== MPD-based audio with volume control
Expand Down
13 changes: 3 additions & 10 deletions documentation/asciidoc/computers/os/using-python.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ To use a virtual environment you will need to create a container to store the en

One way you can proceed is to create a new virtual environment for each Python project you make. Here, you'll create a directory to hold your own code along with a virtual environment directory:

[source,bash]
[source,console]
----
$ mkdir my_project
$ cd my_project
Expand All @@ -78,7 +78,6 @@ $ python -m venv env

If you now look inside the `my_project` directory you'll see a directory called `env`.

[source,bash]
----
$ ls -la
total 12
Expand All @@ -92,23 +91,20 @@ NOTE: If you want to inherit the currently installed packages from the system Py

Inside this directory is a full Python distribution. To activate your virtual environment and make that version of Python the one you're currently using, you should type:

[source,bash]
----
$ source env/bin/activate
(env) $
----

You'll see that your prompt is now prepended with `(env)` to indicate that you're no longer using the system Python. Instead, you're using the version of Python contained inside your virtual environment. Any changes you make here won't cause problems for your system Python; nor will any new modules you install into your environment.

[source,bash]
----
(env) $ which python
/home/pi/my_project/env/bin/python
/home/<username>/my_project/env/bin/python
----

If you install a third-party package, it'll install into the Python distribution in your virtual environment:

[source,bash]
----
(env) $ pip install buildhat
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Expand All @@ -131,7 +127,6 @@ Successfully installed buildhat-0.5.12 colorzero-2.0 gpiozero-2.0 pyserial-3.5

Now, if you `pip list`, you'll see that your current version of Python includes your new modules.

[source,bash]
----
(env) $ pip list
Package Version
Expand Down Expand Up @@ -173,7 +168,7 @@ $

An alternative method to creating a virtual environment for each of your Python projects is to create a single virtual environment for your user account, and then activate that environment before running any of your Python code. This approach may be preferred if you commonly install the same set of modules for each project, and don't want to have to bother creating individual Python environments for each project, essentially just duplicating your environment.

[source,bash]
[source,console]
----
$ python -m venv ~/.env
$ source ~/.env/bin/activate
Expand All @@ -182,7 +177,6 @@ $ source ~/.env/bin/activate

You can check again that you're in a separate environment by using `pip list`:

[source,bash]
----
(.env) $ pip list
Package Version
Expand All @@ -193,7 +187,6 @@ setuptools 66.1.1

...and leave it using `deactivate`.

[source,bash]
----
(.env) $ deactivate
$
Expand Down
12 changes: 6 additions & 6 deletions documentation/asciidoc/computers/os/using-webcams.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ Now the picture is taken at full resolution with no banner.

=== Automating image capture

You can write a Bash script which takes a picture with the webcam. The script below saves the images in the `/home/pi/webcam` directory, so create the `webcam` subdirectory first with:
You can write a Bash script which takes a picture with the webcam. The script below saves the images in the `/home/<username>/webcam` directory, so create the `webcam` subdirectory first with:

[,bash]
----
mkdir webcam
----

To create a script, open up your editor of choice and write the following example code:
To create a script, open up your editor of choice and write the following example code, replacing `<username>` with your username:

[,bash]
----
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
fswebcam -r 1280x720 --no-banner /home/pi/webcam/$DATE.jpg
fswebcam -r 1280x720 --no-banner /home/<username>/webcam/$DATE.jpg
----

This script will take a picture and name the file with a timestamp. Saving the file as `webcam.sh`, first make the file executable:
Expand Down Expand Up @@ -147,7 +147,7 @@ Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to '/home/pi/webcam/2013-06-07_2338.jpg'.
Writing JPEG image to '/home/<username>/webcam/2013-06-07_2338.jpg'.
----

=== Time-lapse captures
Expand All @@ -160,11 +160,11 @@ First open the cron table for editing:
crontab -e
----

This will either ask which editor you would like to use, or open in your default editor. Once you have the file open in an editor, add the following line to schedule taking a picture every minute (referring to the Bash script from above):
This will either ask which editor you would like to use, or open in your default editor. Once you have the file open in an editor, add the following line to schedule taking a picture every minute (referring to the Bash script from above), replacing `<username>` with your username:

[,bash]
----
* * * * * /home/pi/webcam.sh 2>&1
* * * * * /home/<username>/webcam.sh 2>&1
----

Save and exit, and you should see the message:
Expand Down
4 changes: 2 additions & 2 deletions documentation/asciidoc/computers/remote-access/samba.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ On Windows 10 there is a Sharing Wizard that helps with some of these steps.
$ mkdir windowshare
----

Now, we need to mount the remote folder to that location. The remote folder is the host name or IP address of the Windows PC, and the share name used when sharing it. We also need to provide the Windows username that will be used to access the remote machine.
Now, we need to mount the remote folder to that location. The remote folder is the host name or IP address of the Windows PC, and the share name used when sharing it. We also need to provide the Windows username that will be used to access the remote machine. Don't forget to replace the `<username>` placeholder with your Raspberry Pi OS username.

[source,console]
----
$ sudo mount.cifs //<hostname or IP address>/<shared windows folder> /home/pi/windowshare -o user=<name>
$ sudo mount.cifs //<hostname or IP address>/<shared windows folder> /home/<username>/windowshare -o user=<name>
----

You should now be able to view the content of the Windows share on your Raspberry Pi.
Expand Down

0 comments on commit bc3e078

Please sign in to comment.