Hey
I have a python script that I want to run by just pushing a button. I could mainly find tutorials for doing this by starting another python script that waits from button input, and then starts up the python script. However I'd like to be able to start my script without launching anything else beforehand.
Since I couldn't find much on this, I turned to chatGPT and did the following:
- Connected button to BCM pin 20 and ground
- Created a bash script with the following content and made it executable- Created a service file with the following contentsAccordingly this was supposed to listen for any button presses on pin 20 and launch the bash script. However I can't get the service to run. When I check for status I get this.It says the ExecStart failed, but I can run the command directly in the terminal without error (however it starts the script without waiting for the button press, which is not what is intented).
My linux skills are still a bit thin, so I would appreciate any help to get this working.
I have a python script that I want to run by just pushing a button. I could mainly find tutorials for doing this by starting another python script that waits from button input, and then starts up the python script. However I'd like to be able to start my script without launching anything else beforehand.
Since I couldn't find much on this, I turned to chatGPT and did the following:
- Connected button to BCM pin 20 and ground
- Created a bash script with the following content and made it executable
Code:
#!/bin/bashcd /home/christian/GIT/RoboCar_3.0/src/python /home/christian/GIT/RoboCar_3.0/src/main.py
Code:
[Unit]Description=Run Python Script on Button PressAfter=multi-user.target[Service]Type=simpleExecStart=/usr/bin/gpiomon --falling gpiochip0 20 | /home/christian/GIT/RoboCar_3.0/src/start_car.shRestart=on-failure[Install]WantedBy=multi-user.target
Code:
× gpio-button.service - Run Python Script on Button Press Loaded: loaded (/etc/systemd/system/gpio-button.service; enabled; preset: enabled) Active: failed (Result: exit-code) since Sat 2025-01-11 19:57:13 GMT; 1s ago Duration: 5ms Process: 1998 ExecStart=/usr/bin/gpiomon --falling gpiochip0 20 | /home/christian/GIT/RoboCar_3.0/src/start_car.sh (code=exited, status=1/FAILURE) Main PID: 1998 (code=exited, status=1/FAILURE) CPU: 5msJan 11 19:57:13 raspberrypi systemd[1]: gpio-button.service: Scheduled restart job, restart counter is at 5.Jan 11 19:57:13 raspberrypi systemd[1]: Stopped gpio-button.service - Run Python Script on Button Press.Jan 11 19:57:13 raspberrypi systemd[1]: gpio-button.service: Start request repeated too quickly.Jan 11 19:57:13 raspberrypi systemd[1]: gpio-button.service: Failed with result 'exit-code'.Jan 11 19:57:13 raspberrypi systemd[1]: Failed to start gpio-button.service - Run Python Script on Button Press.
My linux skills are still a bit thin, so I would appreciate any help to get this working.
Statistics: Posted by Siggerud — Sat Jan 11, 2025 8:06 pm