Navigation

    Recalbox Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • recalbox.com
    • Gitlab repository
    • Documentation
    • Discord

    GPIO activate on startup

    GamePad/GPIO/USB encoder
    gpio activate startup
    2
    6
    291
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • naitreia
      naitreia last edited by

      Hi,

      is it possible to activate on startup a GPIO-Pin to activate an Optokoppler?

      Cheers

      1 Reply Last reply Reply Quote 0
      • naitreia
        naitreia last edited by

        Hi,

        noone who can help me?

        i tryed it with this as script but it's not working:


        case "$1" in
        start)
        echo „18“ > export
        echo "out" > gpio18/direction
        echo "1" > gpio18/value
        ;;
        stop)
        echo "0" > gpio18/value
        ;;
        restart|reload)
        Add your restart / reload code here!
        ;;
        *)
        esac

        exit $?

        Cheers

        1 Reply Last reply Reply Quote 0
        • naitreia
          naitreia last edited by

          Hi,

          really no one who can help here?
          I only want to have for example GPIO18 as output when recalbox is starting to controle a optocoupler.

          Cheers

          1 Reply Last reply Reply Quote 0
          • ian57
            ian57 Staff
            Developer
            Global moderator
            Creator
            Team
            last edited by ian57

            @naitreia you can create the custom.sh file in /recalbox/share/system/ like this :

            #!/bin/sh
            #
            # Start optocoupler
            #
            # Support for optocoupler 
            #
            
            # GPIO numbers should be from this list
            # 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25
            
            # Note that the GPIO numbers that you program here refer to the pins
            # of the BCM2835 and *not* the numbers on the pin header. 
            # So, if you want to activate GPIO7 on the header you should be 
            # using GPIO4 in this script. Likewise if you want to activate GPIO0
            # on the header you should be using GPIO17 here.
            
            start() {
                    echo -n "Starting opto: "
                    # Set up GPIO 18 and set to output
                    echo "18" > /sys/class/gpio/export
                    echo "out" > /sys/class/gpio/gpio18/direction
                    # Write output
                    echo "1" > /sys/class/gpio/gpio18/value
                    echo "OK"
            }
            
            stop() {
                    echo -n "Stopping opto: "
                    # Set up GPIO 18 and set to output
                    echo "18" > /sys/class/gpio/export
                    echo "out" > /sys/class/gpio/gpio18/direction
                    # Write output
                    echo "0" > /sys/class/gpio/gpio18/value
                    # Clean up
                    echo "18" > /sys/class/gpio/unexport
                    echo "OK"
            }
            
            case "$1" in
              start)
                    start
                    ;;
              stop)
                    stop
                    ;;
              restart|reload)
                    stop
                    start
                    ;;
              *)
                    echo "Usage: $0 {start|stop|restart}"
                    exit 1
            esac
            
            exit $?
            

            don't forget

            chmod 755 custom.sh
            

            You can try to use it with

            /etc/init.d/S99custom start
            

            you should get

            # /etc/init.d/S99custom start
            Starting opto: OK
            

            "UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." Dennis Ritchie

            1 Reply Last reply Reply Quote 0
            • naitreia
              naitreia last edited by

              Thx for this i will try it today!

              ian57 1 Reply Last reply Reply Quote 0
              • ian57
                ian57 Staff
                Developer
                Global moderator
                Creator
                Team
                @naitreia
                last edited by

                @naitreia I corrected 2 errors in the scripts above, please be sure to copy the code after this post 🙂

                "UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." Dennis Ritchie

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post

                Want to support us ?

                110
                Online

                87.8k
                Users

                25.8k
                Topics

                178.7k
                Posts

                Copyright © 2021 recalbox.com