Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GPIO on a Neo

Featured Replies

Hy

 

I tried to play around with the GPIOs and found some nice threads here however I don't get past the

modprobe gpio

command. I get this error

modprobe: FATAL: Module gpio not found in directory /lib/modules/4.14.29-sunxi64

 

Does my kernel build has no GPIO library inside?

Linux 4.14.29-sunxi64 #64 SMP Sat Mar 24 11:13:51 CET 2018 aarch64 GNU/Linux
 

Andy

 

 

  • Author

thx hmm I installed it but I get:

Unrecognized board type, aborting...
AIOInit error

 

I tried to launch the ledtest.py script

 

When I look the board up in the /run/machine.id file its a "Nanopi Neo Plus 2" and this is not listed in the 

armbianio.c file. So what can I do? (the real board is a "NanoPi Neo Core 2")

 

Andy

 

 

  • Author

So can you implement thees pins (for the Neo Core2 and Neo Plus 2)?

 

I used the http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO_Core2#Diagram.2C_Layout_and_Dimension link and tried to blink an LED:

I used the UART1_TX / GPIOG6 Pin. This is the Linux Pin 198. And it works!

# echo "198" >/sys/class/gpio/export
# echo "out" >/sys/class/gpio/gpio198/direction
# echo "1" > /sys/class/gpio/gpio198/value

Now it would be great if I could use this in a Python script

 

Andy

 

6 hours ago, Andy said:

 


# echo "198" >/sys/class/gpio/export
# echo "out" >/sys/class/gpio/gpio198/direction
# echo "1" > /sys/class/gpio/gpio198/value

Now it would be great if I could use this in a Python script

 

 

 

how about a system-call?

import os
os.system('echo "198" >/sys/class/gpio/export')
os.system('echo "out" >/sys/class/gpio/gpio198/direction')
os.system('echo "1" > /sys/class/gpio/gpio198/value')


 

  • Author

yes I did already try this however without root permission it does not work.

 

I tired then to add this to the rule file

SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio; chown -R root:gpio /sys/devices/platform/soc/*.gpio/gpio && chmod -R 770 /sys/devices/platform/soc/*.gpio/gpio'"

 

And add my user to the GPIO group created before but still I get Permission denied for the direction command...

 

How can I get permission to execute the Python file without being root -s?

 

Andy 

10 hours ago, Andy said:

So can you implement thees pins (for the Neo Core2 and Neo Plus 2)?

 

I used the http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO_Core2#Diagram.2C_Layout_and_Dimension link and tried to blink an LED:

I used the UART1_TX / GPIOG6 Pin. This is the Linux Pin 198. And it works!


# echo "198" >/sys/class/gpio/export
# echo "out" >/sys/class/gpio/gpio198/direction
# echo "1" > /sys/class/gpio/gpio198/value

Now it would be great if I could use this in a Python script

 

Andy

 

In Python:

  o = open("/sys/class/gpio/export", "w"); o.write("198");  o.close()

  o = open("/sys/class/gpio/gpio198/direction", "w"); o.write("out"); o.close()

  o = open("/sys/class/gpio/gpio198/value", "w"); o.write("1"); o.close()

 

  • Author
1 hour ago, richardk said:

In Python:

  o = open("/sys/class/gpio/export", "w"); o.write("198");  o.close()

  o = open("/sys/class/gpio/gpio198/direction", "w"); o.write("out"); o.close()

  o = open("/sys/class/gpio/gpio198/value", "w"); o.write("1"); o.close()

 

 

Thx richard but same problem. No permission for the command "/sys/class/gpio/gpio198/direction"

See post above...

 

Andy

Just now, Andy said:

 

Thx richard but same problem. No permission for the command "/sys/class/gpio/gpio198/direction"

See post above...

 

Andy

Oh - okay.

 

If Debian, then "sudo adduser debian gpio" will add "gpio" privileges to user "debian", then log out and back in so the change takes effect.

 

  • Author
4 hours ago, Andy said:

And add my user to the GPIO group created before but still I get Permission denied for the direction command...

 

I have already done that but still no success....

Traceback (most recent call last):
  File "testGPIO.py", line 13, in <module>
    open('/sys/class/gpio/gpio198/direction', 'w').write('out')
IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio198/direction'

 

Andy

37 minutes ago, Andy said:

 

I have already done that but still no success....

 

maybe python does not run as your user?
what is the output of
 

import os
os.system('id')

and then try to give gpio permission to this user?

  • Author

this is the output:

 

uid=1000(deldro) gid=1000(deldro) groups=1000(deldro),20(dialout),27(sudo),29(audio),44(video),46(plugdev),101(systemd-journal),108(netdev),112(ssh),1001(gpio)

 

Andy

 

 

9 minutes ago, Andy said:

this is the output:

 


uid=1000(deldro) gid=1000(deldro) groups=1000(deldro),20(dialout),27(sudo),29(audio),44(video),46(plugdev),101(systemd-journal),108(netdev),112(ssh),1001(gpio)

 

user deldro seems already to be in the group gpio:

uid=1000(deldro) gid=1000(deldro) groups= 1001(gpio)

 

So I got no other idea :(

  • Author

the problem seems the permission command.

I used the 

chown -R root:gpio /sys/class/gpio

 

However after boot it does not set properly.

I put this command in the /etc/rc.local file is this the wrong place?

 

Andy

 

  • Author

after booting it seems that the permissions are set correctly:

 

ls -l /sys/class/gpio/
total 0
--w--w---- 1 root gpio 4096 Mar 27 21:17 export
lrwxrwxrwx 1 root gpio    0 Mar 27 21:17 gpiochip0 -> ../../devices/platform/soc/1c20800.pinctrl/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Mar 27 21:17 gpiochip352 -> ../../devices/platform/soc/1f02c00.pinctrl/gpio/gpiochip352
--w------- 1 root gpio 4096 Mar 27 21:17 unexport

However when I run the Python code I get permission denied for the open('/sys/class/gpio/gpio198/direction', 'w').write('out') command.

 

When I now type again the same command as written in the /etc/rc.local (chown -R root:gpio /sys/class/gpio) in the terminal

and relaunch the python script it does work! (ls -l /sys/class/gpio/ shows the same result as right after the booting)

Why do I need to set the permission twice??

 

Andy

 

 

 

10 hours ago, guidol said:

user deldro seems already to be in the group gpio:

uid=1000(deldro) gid=1000(deldro) groups= 1001(gpio)

 

a next idea from tonight - as I did see the user deldro is also sudo-user, maybe the echo does work with sudo?

import os
os.system('sudo echo "198" >/sys/class/gpio/export')
os.system('sudo echo "out" >/sys/class/gpio/gpio198/direction')
os.system('sudo echo "1" > /sys/class/gpio/gpio198/value')

 

  • Author

sorry guys still same error.

 

However when I run the script with sudo and enter the password then it works.

However I need to run this script as "normal" user (deldro) which is also a sudo-user.

I could add the python to visudo to not ask for a password when using "sudo python...) but

I think this is not the "right" solution...

 

Andy

This would be a function of sysfs.  You'lll note that you are able to write to /sys/class/gpio/export without error (after changing permissions).  This triggers the new creation of /sys/class/gpio/gpioXX using default sysfs permissions.  You would need to do the chmod after writing to the export, and not before (IE: during boot).

 

The gpio sysfs module would need to support configuration of ownerships and permissions for new creations to change this.

  • Author

hmm and what about a python library like the one from bitbank2 (ArmbianIO).

Would this solve the problem?

 

Andy

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.