• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.0k 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.
  • P Offline
    paviro Admin
    last edited by paviro Jul 16, 2016, 1:17 PM May 6, 2016, 5:15 PM

    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
    • K Offline
      KirAsh4 Moderator
      last edited by May 6, 2016, 5:42 PM

      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
      • P Offline
        paviro Admin
        last edited by paviro May 6, 2016, 7:02 PM May 6, 2016, 7:00 PM

        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
        • P Offline
          paviro Admin
          last edited by paviro May 6, 2016, 7:35 PM May 6, 2016, 7:24 PM

          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
          • 1 / 1
          1 / 1
          • First post
            3/4
            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