| | 1 | === Adafruit Volume control === |
| | 2 | I am controlling the volume of the MAX9744 using the CircuitPython Libraries (see [https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi] ). |
| | 3 | The things that I had to do: |
| | 4 | ==== Install the library ==== |
| | 5 | while in (.venv) |
| | 6 | * pip3 install RPI.GPIO |
| | 7 | * pip3 install adafruit-blinka |
| | 8 | ==== Enable I2C === |
| | 9 | I2C is not enabled by default so run and enable I2C in the Interfacing Options |
| | 10 | ==== Python script ==== |
| | 11 | Use this script to set the initial volume to about the half (the range is 0 to 63). Create ~/bin/ada_volume.py with the following content |
| | 12 | * nano ~/bin/ada_volume.py |
| | 13 | {{{ |
| | 14 | import board |
| | 15 | import busio |
| | 16 | import adafruit_max9744 |
| | 17 | i2c = busio.I2C(board.SCL, board.SDA) |
| | 18 | amp = adafruit_max9744.MAX9744(i2c) |
| | 19 | amp.volume = 30 |
| | 20 | }}} |
| | 21 | ==== Start using systemd ==== |
| | 22 | Place a service file in the user directory: |
| | 23 | * nano ~/.config/systemd/user/myadavolume.service |
| | 24 | with the content |
| | 25 | {{{ |
| | 26 | [Unit] |
| | 27 | Description=set adafruit volume |
| | 28 | After=network.target |
| | 29 | |
| | 30 | [Service] |
| | 31 | Type=simple |
| | 32 | ExecStart=/home/pi/mycroft-core/.venv/bin/python /home/pi/bin/ada_volume.py |
| | 33 | |
| | 34 | [Install] |
| | 35 | WantedBy=default.target |
| | 36 | }}} |
| | 37 | Enable and start it: |
| | 38 | * systemctl --user daemon-reload |
| | 39 | * systemctl --user enable myadavolume |
| | 40 | * systemctl --user start myadavolume |
| | 41 | |
| | 42 | === Pulseaudio === |
| | 43 | The picroft installation does not use pulseaudio for the output of voice and other sound so the general volume control did not work |
| | 44 | ==== blacklist the internal bcm2835 sound card ==== |
| | 45 | This is for sure totally optional but I did it |
| | 46 | * sudo nano /etc/modprobe.d/alsa-blacklist.conf |
| | 47 | {{{ |
| | 48 | blacklist snd_bcm2835 |
| | 49 | }}} |
| | 50 | ==== force ALSA userspace to use PulseAudio ==== |
| | 51 | * sudo nano /etc/asound.conf |
| | 52 | {{{ |
| | 53 | # Use PulseAudio by default |
| | 54 | pcm.!default { |
| | 55 | type pulse |
| | 56 | fallback "sysdefault" |
| | 57 | hint { |
| | 58 | show on |
| | 59 | description "Default ALSA Output (currently PulseAudio Sound Server)" |
| | 60 | } |
| | 61 | } |
| | 62 | |
| | 63 | ctl.!default { |
| | 64 | type pulse |
| | 65 | fallback "sysdefault" |
| | 66 | } |
| | 67 | }}} |
| | 68 | ==== mycroft conf ==== |
| | 69 | * sudo nano /etc/mycroft/mycroft.conf |
| | 70 | replace: |
| | 71 | {{{ |
| | 72 | "play_wav_cmdline": "aplay -Dplughw:ArrayUAC10,0 %1", |
| | 73 | "play_mp3_cmdline": "mpg123 -a plughw:ArrayUAC10,0 %1", |
| | 74 | }}} |
| | 75 | with |
| | 76 | {{{ |
| | 77 | "play_wav_cmdline": "paplay %1", |
| | 78 | "play_mp3_cmdline": "mpg123 %1", |
| | 79 | }}} |
| | 80 | ==== additional setting in default.pa ==== |
| | 81 | This enables ducking and is a nice feature that the volume of music playing is turned down while Mycroft speaks instead of stopping the output. |
| | 82 | * sudo nano /etc/pulse/default.pa |
| | 83 | add to the end of the file |
| | 84 | {{{ |
| | 85 | unload-module module-suspend-on-idle |
| | 86 | unload-module module-role-cork |
| | 87 | load-module module-role-ducking |
| | 88 | }}} |