Reading pisound button state fro c program

My setup is a raspberry Pi5 with a pisound board.

I am trying to get access to use the state of the pisound button from a c++ code program using the gpiod library. Here are the steps I have taken:

*I modified the pisound-btn.service with ExecStart=/usr/bin/pisound-btn --gpio21
*I added gpio=27=pu and gpio=17=pu to the /boot/firmware/config.txt file
*Using gpiod I set up pin 17 as an input (as I have many times for other gpio pins)

But when I try and read the pin 17 state using gpio_line_get_value it continuously reads as -1.

Am I missing something?

Thanks for your help.

Disable the pisound-btn service so the pin is not reserved (in use) by it and look at its source code for inspiration:

https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/pisound-btn.c#L34

No need for changes in config.txt.

Thanks for the quick reply.

Clarification please - to disable the pisound service do you mean commenting out the pisound-btn.service file contents?

Thanks again.

You can use systemctl to manage the various systemd services, do:

sudo systemctl disable --now pisound-btn.service

The --now argument is a little shortcut to avoid having to explicitly run

sudo systemctl stop pisound-btn.service

Enabled units auto start on system startup, but you can stop and start them manually as desired.

So thank you again, this does allow me to enable and disable the pisound-btn service. Systemctl status shows that it is working to disable/enable the service.

What I am confused by, however, is that with the pisound-btn service ENABLED, shouldn’t I read 3.3v on one of the pins of the pisound button physical pin that connect to the PCB? I am reading 0v on all four of the pushbutton pins on start up with the pisound-btn.service enabled.

A service being Enabled does not necessarily mean that it is Running. When a service is Enabled, it means that it will start automatically on system boot up.

You are right about the GPIO pull-up - there should be a ~3.3V reading on one pair of the pins of the button, and the pisound-btn does request the GPIO pull-up to be enabled. If it’s not, either pisound-btn is not running (check if the process exists by running ps -e | grep pisound-btn), or you have modified the default configuration somewhere.

Otherwise, if everything is in the default state and running, and the GPIO pin is still not pulling up, it might be a damaged GPIO pin on the Raspberry Pi itself.