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

Comments

  • I think it should not be hard. You define a output so you have a gcode command for that pin to change it. Add the default state command in run on activate script in g-codes for printer. Normally off I'd say.

    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)
      Returns the state of a gpio pin with given name (from Global Setting->GPIO Pins, not BCM pin number). Works for digital outputs and inputs.
    So assuming you named output onoffRelay it would look like this
    @gpio onoffRelay toggle

    This changes output every time you press the button.
  • Dear,
    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
  • Ok if manual trigge rin menu works the output is at least correct.

    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.
  • Dear,

    It works now, I set Debounce time to 200ms.
    Thanks again for your help.
    Is there a document listing the instructions and explanation of their functions?

    Regards
    Laurent
  • Mainly our manual and in the app some inputs have tooltips.
Sign In or Register to comment.