import time
from periphery import GPIO
gpio = GPIO("/dev/gpiochip0", 40, "out")
gpio.write(False)
time.sleep(1)
gpio.write(True)
time.sleep(2)
gpio.close()
Basically, I am trying to activate a relay.
The pin stays at 1.38 volts while the script runs (as root). I’ve tried /dev/gpiochip1 as well, no change.
I can change the pin state in the bios, and when I set it to low, the pin reads at .03 volts. So I think the GPIO pins themselves are fine. I am stumped as to why doing anything from linux just doesn’t work.
Some more digging on my end…
I am trying to use libgpiod, which accesses the gpio pins through a character device. The sysfs method is deprecated and removed in newer kernels, so everybody is going to have to adjust anyway.
So, what I am now essentially asking is…What is the correlation between the physical pin number and the line number? 4 gpiochips show up, and 0 and 1 both have 80 lines.
gpioinfo
gpiochip0 - 80 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed unused input active-high
line 4: unnamed unused input active-high
line 5: unnamed unused input active-high
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: unnamed unused input active-high
line 9: unnamed unused input active-high
line 10: unnamed unused output active-high
line 11: unnamed unused output active-high
line 12: unnamed unused output active-high
line 13: unnamed unused input active-high
From other pages I’ve seed, the broadcom chips have labels. And there is no correlation between pin number and line number. I’ve already caused a crash and reboot by setting line 47 to high.
Now, going back to my original snippet, I see that physical pin 40 (off in the far corner ) is on /dev/gpiochip2 on line 9. And now it works as expected!
If at somepoint Ubuntu or Debian finally drops GPIO sysfs, I hope someone googling around sees this post. Or if you are using Fedora IoT right now.
I’ll probably make a fork of python-periphery to integrate this mapping more easily, so you only have to worry about the physical pin layout number.
Thank you for the fine detective work. I just started looking into the GPIO thing on the Odyssey definitely saved me some work by posting your findings
Confirmed that GPIO sysfs works with 512 added to every number.
e.g.
pin on connect 28 → BCM1_ID_SCL which is 389 in your program, now works as 901.
see seeed odyssey pin overview for the other numbers