Run It

Running the Code

The following command will start our volume control script. Adjusting the trimpot will printout the OS volume level on the screen.

Download: file
$ sudo python3 ./Analog_Inputs_for_Raspberry_Pi_Using_the_MCP3008.py

Testing the Volume Control

Opening a second terminal on your Raspberry Pi we can run the "speaker-test" command and listen to the volume change as we turn the trimpot. 

Download: file
$ speaker-test -t sine -f 440

Controlling MP3 Volume

The mpg123 command can be used to play MP3 files on your Raspberry Pi. We can open an additional terminal and play MP3 files and adjust the volume with the trimpot we have wired up.

Download: file
$ mpg123 <MP3 filename>
This guide was first published on Jul 29, 2012. It was last updated on Jul 29, 2012. This page (Run It) was last updated on Sep 16, 2019.