accessing gpio from within kivy android app

落爺英雄遲暮 提交于 2021-02-19 05:58:26

问题


OK I am stumped and its possible I have just not had enough experience with android, so I dont know which permissions to use.

I have recompiled the android kernel to expose the gpio pins I need, maybe I need to do something in the kernel to solve my problem... basically at this point i have no idea

I can open adb shell and go /sys/class/gpio/export 141 and get the gpio folder and its files (value,direction,etc).

and when I am in the adb shell I can set the direction and values using echo out>direction;echo 1>value;echo 0>value; and everything works great , the pin drives low or high.

I put the export 141 into init.rc and now that gets exported on startup. If I try to access the value file from within my kivy app it crashes and says permissions denied (to be expected)

If I chmod 0666 to both the direction and value it sucessfully updates the permissions in the file sys.

-rw-rw-rw- root     root         4096 2013-10-01 06:59 value
-rw-rw-rw- root     root         4096 2013-10-01 06:59 direction

now when i try to write to the files from kivy(python) I get [Errno 1] Operation not permitted I get the same result if I try to chown the file to my apps user or to system. I feel like Ive tried almost everything and cant seem to write to /sys/class/gpio/gpio141/value or direction


回答1:


OK I finally figured it out... right before I pulled out all my hair.

so for whatever reason it would crash and die when I would call

 with open("/sys/class/gpio/gpio141/value","w") as f:
     f.write("1")

however if I called it as

 os.system("echo 1>/sys/class/gpio/gpio141/value") 

it worked fine.

Im still not sure why I would get operation not permitted when I would try to open it as a filehandle



来源:https://stackoverflow.com/questions/19170689/accessing-gpio-from-within-kivy-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!