Physical button to control relay
06 Nov 2022 21:09 #256097
by jlm123
Physical button to control relay was created by jlm123
Hey all:
I have a physical button connected to a mesa card input
I have a relay connected to a mesa card output.
I also have a software button setup in probe_basic that controls the relay.
When I push the physical button, I want the relay to turn on. When i push it again, i want the relay to turn off. (this will be for a draw bar piston for manual tool changes)
I think I need to use the toggle function - just not sure how to go about setting up the hal commands.
I have a physical button connected to a mesa card input
I have a relay connected to a mesa card output.
I also have a software button setup in probe_basic that controls the relay.
When I push the physical button, I want the relay to turn on. When i push it again, i want the relay to turn off. (this will be for a draw bar piston for manual tool changes)
I think I need to use the toggle function - just not sure how to go about setting up the hal commands.
Please Log in or Create an account to join the conversation.
07 Nov 2022 08:23 #256119
by TOLP2
Replied by TOLP2 on topic Physical button to control relay
You are right, you need a
toggle
component for that. Below is an example setup, please provide your own pin-names.
# Load the component into the HAL
loadrt toggle count=1
# Add its function (ottherwise it won't run). Because relays are slow, I think the servo-thread is fast enough
addf toggle.0 servo-thread
# Connect the pins
net toggle.N.in <= mesa-card.gpio.button.pin
net toggle.N.out => mesa-card.gpio.relay.pin
The following user(s) said Thank You: jlm123
Please Log in or Create an account to join the conversation.
07 Nov 2022 14:23 #256140
by jlm123
Replied by jlm123 on topic Physical button to control relay
I needed to add the pin names - so:
Now I want to get the software button working also as it was before the I got the physical button working. Currently I get the error like "piston can't be used because it already has an out". In my postgui file I have "net piston => qtpyvcp.piston.checked"
net pistonbutton toggle.0.in <= hm2_7i76e.0.7i76.0.0.input-27
net piston toggle.0.out => hm2_7i76e.0.7i76.0.0.output-04
Now I want to get the software button working also as it was before the I got the physical button working. Currently I get the error like "piston can't be used because it already has an out". In my postgui file I have "net piston => qtpyvcp.piston.checked"
Please Log in or Create an account to join the conversation.
08 Nov 2022 10:44 #256201
by andypugh
Replied by andypugh on topic Physical button to control relay
Is the software button momentary or latching?
What you want is a little harder than it might first appear, in that if the relay is "on" on the screen, you need a mechanism to turn it off if the hardware button changes state.
The simplest way to do this (if you have control of the GUI, and are not, for example, using something like coolant-flood which has hardwired behaviour) is to use a momentary button which has its onscreen appearance linked to the actual state of the output pin.
For the case of a momentary onscreen button with no status display, use a second toggle component and combine the two toggle outputs with a HAL "XOR2" component.
You can do all this in a single HAL component using LUT5, if you wire the output to the input (as well as to the physical output). Though I think you might need to also pass both inputs through an edge detector or you simply get a 500Hz output all the time any button remains pressed. (I would have to think harder on this point than I curently have time for to be sure)
What you want is a little harder than it might first appear, in that if the relay is "on" on the screen, you need a mechanism to turn it off if the hardware button changes state.
The simplest way to do this (if you have control of the GUI, and are not, for example, using something like coolant-flood which has hardwired behaviour) is to use a momentary button which has its onscreen appearance linked to the actual state of the output pin.
For the case of a momentary onscreen button with no status display, use a second toggle component and combine the two toggle outputs with a HAL "XOR2" component.
You can do all this in a single HAL component using LUT5, if you wire the output to the input (as well as to the physical output). Though I think you might need to also pass both inputs through an edge detector or you simply get a 500Hz output all the time any button remains pressed. (I would have to think harder on this point than I curently have time for to be sure)
Please Log in or Create an account to join the conversation.
08 Nov 2022 10:45 #256202
by andypugh
Replied by andypugh on topic Physical button to control relay
See also toggle2nist:
linuxcnc.org/docs/stable/html/man/man9/toggle2nist.9.html
linuxcnc.org/docs/stable/html/man/man9/toggle2nist.9.html
Please Log in or Create an account to join the conversation.
11 Nov 2022 07:32 #256407
by TOLP2
Replied by TOLP2 on topic Physical button to control relay
Do you mean the physical button and the hard ware button should be in parllel. Meaning you can press either button to toggle the piston?
In that case I would recommend a simple or-component to combine the two inputs before the toggle.
In that case I would recommend a simple or-component to combine the two inputs before the toggle.
Please Log in or Create an account to join the conversation.
16 Nov 2022 20:01 #256888
by jlm123
Replied by jlm123 on topic Physical button to control relay
Yep - Both buttons should work.
I figured it out earlier today. Threw a xor function on the buttons, then toggled the result.
Note that "piston" comes out of my postgui file.
I figured it out earlier today. Threw a xor function on the buttons, then toggled the result.
Note that "piston" comes out of my postgui file.
net pistonbutton <= hm2_7i76e.0.7i76.0.0.input-27
net piston => xor2.1.in0
net pistonbutton => xor2.1.in1
net pistonresult <= xor2.1.out
net pistonresult => toggle.0.in
net pistonout toggle.0.out => hm2_7i76e.0.7i76.0.0.output-04
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
Time to create page: 0.083 seconds