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.

Accessing the GPIO pins through sysfs with mainline kernel

Featured Replies

Hello I'm using OPI PC+

and tried to figure  out some free gpio to play with it. Taking a look at forums/etc there are formula to calculate current GPIO number according to this https://linux-sunxi.org/GPIO and some posts here, there is a formula:

 

(position of letter in alphabet - 1) * 32 + pin number

 

so can someone explain me how pin 38 (PG6) becomes GPIO 198?

 

calculation back from the formula point letter F

 

 

 

  • Author

figured it out thanks to you, by pin number they do not means pin number on the connector.

so PG6 becomes :

G (7) - 1 = 6

6*32 = 192

and then we add number from  the name (PG6)

192 + 6 = 198

When you are doing frequently such calculations and getting bored, you simply use python script to help you out ...

#!/usr/bin/python3

import sys
import string

def convert(value):
	value = value.upper()
	alp = value[1]
	idx = string.uppercase.index(alp)
	num = int(value[2:], 10)
	res = idx * 32 + num
	return res

if __name__ == "__main__":
	args = sys.argv[1:]
	if not args:
		print("Usage: %s <pin>" % sys.argv[0])
		sys.exit(1)

	print("%d" % convert(args[0]))

sry if this is a stupid question: in which format should <pin> be given to your script?

I only get these:

cg@poisson:/usr/local/bin$ GpioCalc.py pg6
Traceback (most recent call last):
  File "/usr/local/bin/GpioCalc.py", line 22, in <module>
    print("%d" % convert(args[0]))
  File "/usr/local/bin/GpioCalc.py", line 11, in convert
    idx = string.uppercase.index(alp)
AttributeError: 'module' object has no attribute 'uppercase'

cg@poisson:/usr/local/bin$ GpioCalc.py g6
Traceback (most recent call last):
  File "/usr/local/bin/GpioCalc.py", line 22, in <module>
    print("%d" % convert(args[0]))
  File "/usr/local/bin/GpioCalc.py", line 11, in convert
    idx = string.uppercase.index(alp)
AttributeError: 'module' object has no attribute 'uppercase'

cg@poisson:/usr/local/bin$ GpioCalc.py g 6
Traceback (most recent call last):
  File "/usr/local/bin/GpioCalc.py", line 22, in <module>
    print("%d" % convert(args[0]))
  File "/usr/local/bin/GpioCalc.py", line 10, in convert
    alp = value[1]
IndexError: string index out of range

cg@poisson:/usr/local/bin$ GpioCalc.py 38
Traceback (most recent call last):
  File "/usr/local/bin/GpioCalc.py", line 22, in <module>
    print("%d" % convert(args[0]))
  File "/usr/local/bin/GpioCalc.py", line 11, in convert
    idx = string.uppercase.index(alp)
AttributeError: 'module' object has no attribute 'uppercase'

cg@poisson:/usr/local/bin$ 

Sorry, I wasn't the original author of that script.

 

Although it headed with #!/usr/bin/python3, your issues seems that it is not python3 compatible, try it with python2.7 ...

 

(Or if you really python3, change the "uppercase" which is now "ascii_uppercase")

 

EDIT : it is better to change the "uppercase" to "ascii_uppercase", since it works on both python2.7 and python3

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.