Adding Global Volume Control to the Pocket CHIP
I’ve been gradually adding internal speakers to each of my Pocket CHIPs lately and found it cumbersome to have to either open alsamixer or use the volume control page in the Pocket CHIP launcher to control volume.
The Pocket CHIP uses awesome as it’s window manager. With awesome you can use the Lua language to script the appearance and behaviour of the user interface, write functions, bind shortcuts to key presses, etc.
I decided to use this to add volume control. With my changes to ~/.config/awesome/rc.lua you can simply press ctrl+↑ or ctrl+↓ and the volume will increase or decrease by 10% respectively.


The changes are quite simple, first I defined some functions:
volume_up = function ()
volume_ctl("up", 10);
end
volume_down = function ()
volume_ctl("down", 10);
end
volume_ctl = function (direction, amount)
local current_vol = awful.util.pread("amixer sget 'Power Amplifier' | awk -F '[][]' '/dB/ {print substr($2, 1, length($2) - 1)}'")
current_vol = current_vol:gsub("[\r\n%z]", " ")
local target_vol = current_vol
if direction == "up" then
target_vol = current_vol + amount
if target_vol > 100 then
target_vol = 100
end
else
target_vol = current_vol - amount
if target_vol < 0 then
target_vol = 0
end
end
awful.util.pread("amixer sset 'Power Amplifier' "..target_vol.."%")
naughty.notify({
text="Volume: "..target_vol.."%",
timeout=1
})
end
I’m using the output from amixer sget piped through to awk to get the current volume, adding/substracting 10 from that value and then using amixer sset to update the volume.
The Pocket CHIP is using an older 3.4.15 build of awesome, so the methods to get text from a subcommand are a bit different than the currently available docs but I browsed the 3.4 source on Github and worked out how to achieve what I needed.
Once the functions are defined, they just need to be bound to a key. Find the Key bindings block and add the new bindings:
awful.key({"Control",}, "Up", volume_up),
awful.key({"Control",}, "Down", volume_down),
I’ve posted the entire rc.lua as a gist on Github.
Caveats
I’ve limited the volume range to between 0-100%. You can go higher than this in alsamixer directly, but it seemed sensible to have a limit. A volume level of around 50% sounds best to me.
Though the volume level is changed, the slider found in the launcher UI doesn’t update automatically to reflect the current volume level. That’s not something I can control.
Sometimes the increment amount seems a bit random. The functions are adding/substracting 10% each time but somehow amixer adds a random 1% here or there. If you want more fine control you can adjust the volume_up and volume_down functions in your rc.lua to use a smaller value.
Related posts
- CHIP Stuff
This page is a changing document. I’ll probably add more notes to it in the future. These are just some notes that I’ve put together in the past about flashing and upgrading the CHIP (and Pocket CHIP) computer.
- Using ORCA with FluidSynth on the Pocket CHIP
This post is about using the ORCA livecoding playground on the Pocket CHIP From the ORCA wiki: Orca is a two-dimensional esoteric programming language in which every letter of the alphabet is an operator, where lowercase letters operate on bang, uppercase letters operate each frame. This livecoding language is designed to procedurally generate MIDI, UDP or OSC messages.
- Running a Tailscale exit node in a local VM
I run Tailscale on my laptops, phone and NAS, and wanted to add an exit node so I could route traffic through my own connection when I’m out and about. The obvious place to put it was the NAS, since it’s already always on, but the NAS also holds everything I’d least like exposed if something went wrong. Making it double up as an exit node, with every device’s outbound traffic flowing through it, didn’t sit right. What I wanted instead was a disposable, isolated VM living on the same machine doing that job, leaving the NAS untouched.
Discussion
- 2021
Reply on reddit.com
Join the conversation
Reply from your own site with a Webmention (how?).
