Echo: write error: Invalid argument

Hi,

I am trying to access the GPIO from Linux (Ubuntu 22.04 with kernel 5.15.0-48-generic). I am following the steps from the Wiki: Accessing 40-pin GPIO - Seeed Wiki

When I try to write to export I get an error “echo: write error: Invalid argument”

sudo -i
cd /sys/class/gpio
echo 337 > export
-bash: echo: write error: Invalid argument

Any suggestions?

Thanks. Gary.

Hello @garysims,

Could you please try this on Ubuntu 18.04?

Thank you.

Yes, it works on 18.04, I reverted to the older version just after I posted the message, however my question isn’t about 18.04, it is about 22.04.

Hello @garysims,

I have tested this further with Ubuntu 18.04, 19.04, 20.04 and 22.04 and it seems that it works only for 18.04, 19.04.

When I checked the kernel version, the corresponding versions were as follows:

  • 18.04 - 5.4.0
  • 19.04 - 5.0.0
  • 20.04 - 5.15.0
  • 22.04 - 5.15.0

It seems that it is related with the kernel. For 5.15, it does not work.

Unfortunately, we do not have the resources to debug this further. We might need to conclude that it is only compatible with 18.04 and 19.04.

I wonder if it is because since Linux 4.8 the GPIO sysfs interface is DEPRECATED. Maybe Linux 5.15 has removed it completely.

Did some digging into the GPIO layout on Ubuntu 22.04

I found that the GPIO pins start at 809.

is there a way to walk them and figure out which is which without hooking up like an LED circuit up to each and every pin?

its simple, just add 512 to every number.

1 Like

This error message usually occurs when a command or script tries to write to a file or directory that does not exist or is inaccessible.

Here are a few possible reasons and solutions for the “Echo: write error: Invalid argument” error message:

The file or directory does not exist: Make sure that the file or directory you are trying to write to actually exists. If it does not exist, create it using the “mkdir” command for directories or “touch” command for files.

The file or directory is read-only: Check the permissions of the file or directory using the “ls -l” command. If the file or directory is read-only, use the “chmod” command to change the permissions.

The file or directory is owned by another user: Check the ownership of the file or directory using the “ls -l” command. If it is owned by another user, use the “chown” command to change the ownership.

The file or directory is located on a read-only file system: If the file or directory is located on a read-only file system, you will not be able to write to it. Mount the file system as read-write or move the file to a different location.

The file or directory name contains special characters: If the file or directory name contains special characters, such as spaces, quotes, or slashes, you may need to escape them using backslashes or quotes.

By addressing the above reasons, you can resolve the “Echo: write error: Invalid argument” error message.

Regards,
Rachel Gomez

Worked perfectly!
changed demo code from “echo 415 > export” to “echo 927 > export” and everything worked 100%

Thanks for your help