Jump to content

How to run python script include GPIO config ?


Kwan Xian

Recommended Posts

Hi,guys!

when I build a pthon3 script with gui and GPIO contorl.I can run it when I use terminal with sudo command.

But when I used "settings->session and startup" to config this script,It can't run when my device reboot (Orange Pi PC).

I try to config command like:

"echo 'password'|sudo -S python3 /home/kwan/OPi_PC/u_main.py"

still the same.

And then I tried to edit "/etc/rc.local" file and add:

"echo 'password'|sudo -S python3 /home/kwan/OPi_PC/u_main.py &"

still the same.

 

The problem is when I run the other script without GPIO config and sudo command.

It can run when device reboot.

 

So,It's there anybody can tell me why & how to make it run with sudo.

I really have no idea about it.

Thx!

 

tried:

@reboot sudo python3 /home/kwan/OPI_PCPLUS/Linux_gate.py > /home/kwan/log.log

Error: no display name and no $DISPLAY environment variable
 

 

 

Link to comment
Share on other sites

Hi Kwan Xian,  I don't know which software you use, you might want to checkout this one:

 

Within armbian you find following User-Supported options for GPIO and more:
UserSpaceIO (libgpiod),
pyGPIO accesses 'pins' directly through /dev/mem


 User Space IO is Python 3 and Java 8 bindings for user space GPIO, SPI, I2C, PWM and Serial interfaces
https://forum.armbian.com/topic/6523-user-space-io-is-python-3-and-java-8-bindings-for-user-space-gpio-spi-i2c-pwm-and-serial-interfaces/

 

 pyGPIO - A 'more general' python GPIO library based on pyA20
https://forum.armbian.com/topic/5662-pygpio-a-more-general-python-gpio-library/

 

Link to comment
Share on other sites

On 1/14/2019 at 5:00 AM, martinayotte said:

It can be workarounded also using setuid on python itself :

 

 

Yes,You'r right.

cp /usr/bin/python3 to /usr/bin/my-python and chmod 4775 /usr/bin/my-python.

config "my-python {script-path}" for startup command.

Now,my py script can run when device reboot.

Thank You!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines