MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    GPIO without root

    Scheduled Pinned Locked Moved Solved Development
    gpiowiring-pi
    4 Posts 2 Posters 6.5k Views 1 Watching
    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.
    • paviroP Offline
      paviro
      last edited by paviro

      I am currently writing a module which uses the GPIO Pins for that the script has to be started as root. I tried running MM with DISPLAY=:0 sudo npm startbut all I get this way is a No protocol specifiederror on startup. Any idea how to fix this or how to use wiring-pi without root? Wasn’t there an Raspbian update recently that allowed GPIO access without root? I don’t remember it exactly…

      We're all stories in the end. Just make it a good one, eh?

      – The Doctor

      1 Reply Last reply Reply Quote 0
      • KirAsh4K Offline
        KirAsh4 Moderator
        last edited by

        First Google result brings this up:
        https://dissectionbydavid.wordpress.com/2013/10/21/raspberry-pi-using-gpio-wiringpi-without-root-sudo-access/

        A Life? Cool! Where can I download one of those from?

        1 Reply Last reply Reply Quote 0
        • paviroP Offline
          paviro
          last edited by paviro

          That’s nice and all but too complicated for people to setup…
          Adding a sudo somewhere is one thing but that would make installing the module so complicated :confused:
          Seems like it might be possible by using usermod -a -G gpio pi will check and report.

          We're all stories in the end. Just make it a good one, eh?

          – The Doctor

          1 Reply Last reply Reply Quote 0
          • paviroP Offline
            paviro
            last edited by paviro

            Found a workaround! Use the shell within node to export the pins. Works without root if the user is added to the gpio group, to do that execute sudo useradd -g pi gpio.


            Setup the pins

            const exec = require('child_process').exec;
            
            exec("echo '22' > /sys/class/gpio/export", null);
            exec("echo 'in' > /sys/class/gpio/gpio22/direction", null);
            
            exec("echo '17' > /sys/class/gpio/export", null);
            exec("echo 'out' > /sys/class/gpio/gpio17/direction", null);
            

            Control the pins

            gpio.setup('sys');
            
            gpio.wiringPiISR(22, gpio.INT_EDGE_BOTH, function(delta) {
            	if (gpio.digitalRead(22) == 1) {
            		console.log("High");
            		gpio.digitalWrite(17, 1)
            	}
            	else if (gpio.digitalRead(22) == 0) {
            		console.log("Low");
            		gpio.digitalWrite(17, 0)
            	}
            });
            

            We're all stories in the end. Just make it a good one, eh?

            – The Doctor

            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post
            Enjoying MagicMirror? Please consider a donation!
            MagicMirror created by Michael Teeuw.
            Forum managed by Sam, technical setup by Karsten.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy