I can export GPIO's and do what I want quite easily -
echo 244 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio244/direction
echo "rising" > /sys/class/gpio/gpio244/edge
But if I try to do it in C -
#define SYSFS_GPIO_DIR "/sys/class/gpio"
fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY);
fd returns -1
Please could somebody tell me what I am doing wrong - does a kernel module need to be loaded first?
Thanks
Andy.
What your code do is kind of non-sense :
fd = open("/sys/class/gpio" "/export", O_WRONLY);
You need to provide proper path into a single string ...
The code was copied from an example
#define SYSFS_GPIO_DIR "/sys/class/gpio"
fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY);
If you change it to
fd = open("/sys/class/gpio/export", O_WRONLY);
The result is the same.
You're doing it all as root?
John
No, I am doing it over VisualGDB as olimex login.
Probably the problem!
Look at the permissions on those files!
You can also look at errno :)
John
Was easiest to change the file permissions ;)
Should do this more often as keep getting a bit rusty!
Thanks!
Andy.