GPIO: controlling an output with an input
Dear,
I would like to be able to turn my printer on and off from a pushbutton using an input and controlling a relay from an output of the GPIO, I did not find a solution from the menu functions GPIO Pins configuration, is it possible?
If possible, could you tell me how to do it?
Thank you in advance for your help.
Regards
Laurent
Regards
Laurent
Comments
Now add input with "Run G-Code on change mode" and select the edge rising or falling to trigger it.
In the script you check if output is on or of and trigger the opposite. Testing is done by
- get_gpio_state(gpioName)
So assuming you named output onoffRelay it would look like thisReturns the state of a gpio pin with given name (from Global Setting->GPIO Pins, not BCM pin number). Works for digital outputs and inputs.
@gpio onoffRelay toggle
This changes output every time you press the button.
Thank you for your help, for the moment it does not work, below my configurations.
1) Ouput configuration for Rock PI4 (work in manual with Menu):
- Name : onoffRelay
- Function : Set output on/off
- GPIO Pin : 146
- G-Code to trigger: ;@gpio onoffRelay on|off|toggle
2) Input configuration : (State change when I push the pushbutton)
- Name : BP
- Function : Run G-Code on change
- GPIO Pin : 71
- Edge : Rising
- Debounce time : 2 ms
- G-Code : @gpio onoffRelay toggle
Is it OK?
Thank you in advance for your help.
Regards
Laurent
Now you need to ensure it triggers only once. Add in input gcode in addition:
@echo Input Triggered
you see in terminal if it triggers the message. Should appear once - if you see it twice you switch on and off directly. Some switches have bouncing so it can happen multiple time. If I remember right you can add debouncing time for inputs.
You can also test the @gpio onoffRelay toggle command in console to test if it works as expected like the menu switch.
Regards
Laurent