If you're new to programming and the beaglebone, I suggest you stop what you're doing and go read.
You say this code is supposed to be opening /changing *whatever* on gpio44, but clearly in your code it is opening gpio68. I'm not sure where you found that code, but its a mess. Anyway look up Derek Molloy on youtube and watch his videos and / or read his blog. On Fri, Aug 22, 2014 at 7:43 AM, <[email protected]> wrote: > I'm new to beaglebone and to C programming so I may be asking a stupid > question but when I try to run the following code it exports gpio44 but > gives a segmentation fault error and stops. > > #include <stdio.h> > #include <unistd.h> > #include <stdlib.h> > > void export_pin(char pin_n[]); > void unexport_pin(char pin_n[]); > void set_pin(char pin_n[], char pin_val[]); > > > int main() { > set_pin("44", "1"); > return 0; > } > > void set_pin(char pin_n[], char pin_val[]) { > export_pin(pin_n); > > FILE *direction = 0; > FILE *value = 0; > > char pin_dir[] = "out"; > > direction = fopen("/sys/class/gpio/gpio68/direction", "w"); > > fwrite(pin_dir, 1, sizeof(pin_dir), direction); > > fclose(direction); > > value = fopen("/sys/class/gpio/gpio68/value", "w"); > fwrite(pin_val, 1, sizeof(pin_val), value); > fclose(value); > } > > void export_pin(char pin_n[]) { > FILE *export = NULL; > > export = fopen("/sys/class/gpio/export", "w"); > > fwrite(pin_n, 1, sizeof(pin_n), export); > > fclose(export); > } > > void unexport_pin(char pin_n[]) { > FILE *unexport = NULL; > > unexport = fopen("/sys/class/gpio/unexport", "w"); > > fwrite(pin_n, 1, sizeof(pin_n), unexport); > > fclose(unexport); > } > > I have no idea what could be causing this. > > -- > For more options, visit http://beagleboard.org/discuss > --- > You received this message because you are subscribed to the Google Groups > "BeagleBoard" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
