Raspberry Pi volume control using rotary encoder KY040 and ZeroSeg 7 segment display
- ZeroSeg 8 character 7 segment display
- KY040 rotary encoder with push button function
Open terminal
sudo apt-get update && apt-get upgrade
https://cdn.shopify.com/s/files/1/0176/3274/files/ZeroSeg_User_Guide_1.2.pdf
To use the left GPIO pins which are unfortunately not accessible because ZeroSeg covers all 40 pins you have to different options.
Name | Description | Physical Pin | RPi Function |
---|---|---|---|
DIN | Data In 19 | GPIO 10 (MOSI) | |
CS | Chip Select | 24 GPIO 8 (SPI CE0) | |
CLK | Clock | 23 GPIO | 11 (SPI CLK) |
SW1 | Left Switch/Button | 11 | GPIO 17 |
SW2 | Right Switch/Button | 37 | GPIO 26 |
The manual of ZeroSeg gives the following hint:
Power and GND lines have not been documented, however it's worth mentioning that the MAX7219CNG chip uses the 5V line, whilst the switches use 3.3V
For this I connected all of the 40 GPIO pins with male-female wires and simply did some trial and error to check which pins are used for power supply. The result is the following:
First 2 pins of the ZeroSeg are 3V and 5V
GND pin is the pin under the the second 5V pin
Schematic:
Pin | Pin | Description |
---|---|---|
3V | 5V | <== VCC |
IO2 | 5V | |
IO3 | GND | <== GND (choose any if already in use) |
IO4 | IO14 | |
... | ... |
You have to be careful when you connect the pins to the RPi. Do not miscalculate while counting the pins. Do not connect wrong pins, this could damage your RPi seriously. I am not responsible for any damage caused by wrong wiring or use of this tutorial.
Get a GPIO exander or multiplexer, google search delivers lots of results.
If you use want to use onboard audio enter:
amixer -c 0 controls
If you want to use an external usb sound card enter:
amixer -c 1 controls
Should output results like this:
numid=3,iface=MIXER,name='PCM Playback Switch' numid=4,iface=MIXER,name='PCM Playback Volume' <== Script default, change if necessary numid=2,iface=PCM,name='Capture Channel Map' numid=1,iface=PCM,name='Playback Channel Map'
Note the device descriped with "Playback Volume", here numid = 4
git clone https://github.com/Hotwheels93/rpi-volume-control cd rpi-volume-control
Edit volumectl.py:
To set the right sound card change the lines 25, 41 and 76 to with your card number and id:
sudo nano volumectl.py
Example: ['amixer','q', '-c', '1', 'cset', 'numid=4', str(volume)] (default)
Run:
python volumectl.py
To enable autostart open terminal and type
crontab -e
@reboot sudo python /home/pi/rpi-volume-control/volumectl.py