WiringPi - Controlling a Relay using buttons

Hi Everyone,

First I apologize if this topic has already been mentioned, but I didn't find anything useful yet.

I'm runing Octoprint on a Raspberry Pi 3 B+, everything is working perfectly.
I've managed to create "buttons" on the web interface in order to control gpio and a 4-way relay behind it.

This relay allow me to control a few things, PSU, lights, Hotbed and Printer.

I wanted to add somehting more to my configuration, but since I'm new to all of this it's a bit obscure, and also I think I don't have the rights words to express myself.

I would like to use 4 physical push button, in order to control my 4-way relay (in addition to the web interface).

These buttons will be assigned to a specific relay, and when pushed, they will "invert" the status of the relay. Meaning that if the relay is open it will close it, and if it's closed it will open it.

I know how to change the status of a gpio using WiringPi, but this task is a bit more difficult, I will need to read the status of 4 entries in some sort of loop and then make a decision based on what is done.

On paper it seems easy, but I'm a bit lost here to apply this.

Thanks in advance for your help.

So basically, you need to learn how to program (if I understand you correctly). The area of math is called Boolean.

Name the relays A through D and we can talk about what it is that you'd like to do.

Check this article It may be good starting point for your design.

1 Like

Hi everyone,

Thanks a lot for your answers, yep I need to learn how to create some sort of daemon that will check specific inputs, and based on what is hapening, this daemon will change the specified output in order to interact with the relay.

I'm going to check in details the link that you mentionned.

In python, there are two methods of toggling a boolean variable; here's the usual way.

bRelay1 = False        # Initialize it to False (relay OFF/disconnected)
bRelay1 = not bRelay1  # Now it's True (ON)
bRelay1 = not bRelay1  # Now it's False (OFF)

I know it's a slightly old thread, but have you looked at the enclosure plugin?