Posts: 13
Threads: 2
Joined: Jul 2024
Reputation:
0
Greetings.
I have connected an oled display, everything works. But this display burns out pixels when working for a long time. I decided to use buttons in gpio buttons to give commands to turn the display off or on. But this requires two buttons - one to turn on and one to turn off. Is there any way to make it work on one button? Pressed - the command to turn off is sent. Pressed again - command to turn on. That is the trigger mode.
Thank you.
Sorry for my English - I write through a translator, I'm from Ukraine.
Posts: 13,441
Threads: 305
Joined: Mar 2018
Reputation:
545
What model display and how is it connected?
Posts: 13
Threads: 2
Joined: Jul 2024
Reputation:
0
SSD1306 I2C display. Connected to pin 5 and 3 of the GPIO connector of the Raspberry Pi Zero 2W. MPD Oled program. It has commands "sudo systemctl stop mpd_oled" and "sudo systemctl start mpd_oled" to turn off and on the MPD Oled. When turned off, the display goes off. I am using in GPIO buttons two buttons. One turns off, the other turns on. It is not convenient and not rational. I would like to use only one button for on/off.
Posts: 72
Threads: 3
Joined: Nov 2022
Reputation:
7
Why not have a script that checks the status of the mpd_oled service ?
e.g:
Code: if (systemctl is-active --quiet service); then
echo -e "SERVICE is Running!"
else
echo -e "SERVICE has Stopped status!"
fi
Change the echo to start/stop as appropriate.
Posts: 13
Threads: 2
Joined: Jul 2024
Reputation:
0
(07-05-2024, 09:00 PM)steve4star Wrote: Why not have a script that checks the status of the mpd_oled service ?
Change the echo to start/stop as appropriate.
Please forgive me, I don't understand programming in the Linux environment at all
Could you please tell me how to do it, or point me in the right direction.
Thanks
Posts: 1,282
Threads: 24
Joined: Jun 2022
Reputation:
42
(07-09-2024, 09:04 PM)Romanz Wrote: (07-05-2024, 09:00 PM)steve4star Wrote: Why not have a script that checks the status of the mpd_oled service ?
Change the echo to start/stop as appropriate.
Please forgive me, I don't understand programming in the Linux environment at all
Could you please tell me how to do it, or point me in the right direction.
Thanks
Code: #!/bin/bash
if (systemctl is-active --quiet mpd_oled); then
sudo systemctl stop mpd_oled
else
sudo systemctl start mpd_oled
fi
1. copy the contents in the code-block above into /home/<your username>/bin/mpd_oled_toggle.sh
2. make such file executable: chmod 0777 /home/<your username>/bin/mpd_oled_toggle.sh
3. in the command of the button (just one button, now), specify the whole path as it appears here above, instead of each of the sudo systemctl start/stop ...
Posts: 13
Threads: 2
Joined: Jul 2024
Reputation:
0
07-10-2024, 04:08 PM
(This post was last modified: 07-10-2024, 05:02 PM by Romanz.)
Thank you.
Moode 8.3.9
All done. On the first startup, the display goes blank. Restarting it doesn't turn it on. And the subsequent ones, too.
What is interesting, after the first application of the script, it does not start even in the terminal. I use the command sudo systemctl start mpd_oled - does not start.
If you look at the status with sudo systemctl status mpd_oled command - it says Stoped MPD Oled Display. Only rebooting helps.
Posts: 1,282
Threads: 24
Joined: Jun 2022
Reputation:
42
(07-10-2024, 04:08 PM)Romanz Wrote: Thank you.
Moode 8.3.9
All done. On the first startup, the display goes blank. Restarting it doesn't turn it on. And the subsequent ones, too.
What is interesting, after the first application of the script, it does not start even in the terminal. I use the command sudo systemctl start mpd_oled - does not start.
If you look at the status with sudo systemctl status mpd_oled command - it says Stoped MPD Oled Display. Only rebooting helps.
What does it mean "only rebooting helps"? Didn't you say that at startup it is OFF, and then it does not start, no matter what?
Posts: 13
Threads: 2
Joined: Jul 2024
Reputation:
0
The system boots up, the display appears on the oled display. If I go to terminal and enter the command "sudo systemctl stop mpd_oled" the display goes out. If I type "sudo systemctl start mpd_oled" at once, the display appears. If I press the button and run the script, the display goes out. The next press does not help. If I type the command "sudo systemctl start mpd_oled" in the terminal, there is no response either. Only rebooting moode helps.
Posts: 1,282
Threads: 24
Joined: Jun 2022
Reputation:
42
07-11-2024, 09:11 AM
(This post was last modified: 07-11-2024, 09:21 AM by Nutul.)
(07-11-2024, 08:29 AM)Romanz Wrote: The system boots up, the display appears on the oled display. If I go to terminal and enter the command "sudo systemctl stop mpd_oled" the display goes out. If I type "sudo systemctl start mpd_oled" at once, the display appears. If I press the button and run the script, the display goes out. The next press does not help. If I type the command "sudo systemctl start mpd_oled" in the terminal, there is no response either. Only rebooting moode helps.
Now it's clearer...
So:
1. at startup everything is OK
2. you can switch it OFF by pressing the button
3. you cannot, then, switch it back ON neither with the button, nor with the command.
Sounds strange... like the script somehow does not terminate, or there are some errors that prevent it to be run any further after the first invoke...
I would try the following, then:
1. add echo lines in the two IF branches, so to see which path is taken by the script, so that it looks like this:
Code: #!/bin/bash
if (systemctl is-active --quiet mpd_oled); then
echo "MPD_OLED is active, turning it OFF..."
sudo systemctl stop mpd_oled
echo "Done."
else
echo "MPD_OLED is not active, turning it ON..."
sudo systemctl start mpd_oled
echo "Done."
fi
2. after startup, instead of pressing the buttons, just open a terminal, and call the script on the command-line, and report what you see as the output of the script.
|