Circuits.gpio.open() errors not found, while linux's gpioset does work

Device is a Glovary Firewall 6l with GPIO (2x5) on the motherboard.
The header is the not so standard dupont pins 2mm
GPIO is over the super I/O chip: iTE IT8613E

PIN 1 : SIO_PD0  (line 0)
PIN 2 : SIO_PD4  (line 38)
PIN 3 : SIO_PD1  (line 3)
PIN 4 : SIO_PD5  (line 39)
PIN 5 : SIO_PD2  (line 10)
PIN 6 : SIO_PD6  (line 40)
PIN 7 : SIO_PD3  (line 41)
PIN 8 : SIO_PD7  (line 9)
PIN 9 : GND
PIN 10 : VCC

not working:

> Circuits.GPIO.open("GPIO41", :output)
{:error, :not_found}

> Circuits.GPIO.open(41, :output)
{:error, :not_found}

> Circuits.GPIO.enumerate()
[]

> Circuits.GPIO.backend_info()
%{name: Circuits.GPIO.CDev, gpio_number_remapping: :none}


linux (toybox):

> sudo gpioset 0  "41=1" # turn on
> sudo gpioset 0  "41=0" # turn off

> gpioset --version
toybox 0.8.11

linux (libgpiod):

> sudo gpioset -t0 -c gpiochip0 "41=1" # turn on
> sudo gpioset -t0 -c gpiochip0 "41=0" # turn off

> gpioset --version
gpioset (libgpiod) v2.2
Copyright (C) 2017-2023 Bartosz Golaszewski
License: GPL-2.0-or-later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

@benwilson512
I saw you changed the topic to the nerves section.
Is Circuits.Gpio only on a nerves installation? I’m trying to use the library without nerves.

Hi @water,

My first thought is that it’s a permissions issue and Circuits.GPIO doesn’t have access to the GPIOs. I see that you ran sudo on gpioset. I’m assuming that you’re not running Elixir as root and that if you removed the sudo that gpioset wouldn’t work either.

If it is a permissions issue and your device is running udev, you can add a udev rule to set the group/permissions on/dev/gpiochip0 so that Elixir can access it without running as root. Create a file like /etc/udev/rules.d/99-gpio.rules file with the following contents:

KERNEL=="gpiochip*", SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"

Then create the gpio group if you don’t already have one. E.g. sudo addgroup gpio. Also make sure that your user is in the gpio group in /etc/group.

Then reload udev and rerun the rules:

sudo udevadm control --reload-rules
sudo udevadm trigger

If you look at /dev/gpiochip0, it should have the right permissions and Circuits.GPIO should find the GPIOs. You also shouldn’t need to run sudo for gpioset, etc.

Hope this helps!

1 Like

Hey @water that’s my bad, I saw Circuits.GPIO and assumed nerves!

1 Like

thank you.

nixos configuration

    services.udev.extraRules = ''
      KERNEL=="gpiochip*", SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
    '';
    users.groups."gpio" = { };
    users.users.${config.ncfg.primaryUserName}.extraGroups = [
      "gpio"
    ];

1 Like

Writing to the led works.
I can also read from an input.
But Circuits.GPIO.set_interrupts gives an error and the error message is not clear.

{:ok, mybutton} = Circuits.GPIO.open({"gpiochip0", 0}, :input) # tuple: GPIO controller hardware name , a line offset
## {:ok, %Circuits.GPIO.CDev{ref: #Reference<0.1604890481.3279814673.239057>}}

Circuits.GPIO.read(mybutton)
## 1
# Push the button down
Circuits.GPIO.read(mybutton)
## 0

The example in the readme is the reverse of my button press result. I don’t think it matters?

iex(37)> Circuits.GPIO.set_interrupts(mybutton, :both)
{:error, {:errno, 1}}
iex(38)> Circuits.GPIO.set_interrupts(mybutton, :rising)
{:error, {:errno, 1}}
iex(39)> Circuits.GPIO.set_interrupts(mybutton, :falling)
{:error, {:errno, 1}}

I can’t get gpiomon to work either.

I’ll change the 2 buttons with switches.
Polling them every 500ms should do the trick.