4 Replies Latest reply on Mar 9, 2017 10:29 AM by FGT

    Galileo Gen 2 Help with reading the value of a GPIO pin

    jeremy2017

      Hello,

       

      I'm very new to both Linux and the Galileo Gen 2. I am working on a project that will read 5 pins that are connected to a micro-controller. Furthermore, I need these inputs to be a 1 or 0 and accessible inside my c program.  The read function I'm using is below and it will print a 1 or 0 to the screen but my file cannot seem to capture the 1 or 0. I've used scanf, getch() and even tried to access the "value" file without success. I've read every tutorial I can find but I'm missing something...like I said I'm new to this so any help will be appreciated.

       

      Thank you,

      Jeremy

       

      #include<stdio.h>

      #include<string.h>

      int main()

      {

        int PORTS[5] = {40,48,50,52,54};

       

      int i;

      int x=1;

      int readbuff;

        while(1)

        {

        x=!x;

        for(i =0; i<5; i++)

        {

      char buffer[256];

      sprintf(buffer, "echo %d > /sys/class/gpio/export", PORTS[i]);

      system(buffer);

       

      sprintf(buffer, "echo in > /sys/class/gpio/gpio%d/direction", PORTS[i]);

      system(buffer);

       

      sprintf(buffer, "cat /sys/class/gpio/gpio%d/value",PORTS[i]);

      system(buffer); 

       

      sleep(1);

       

      }

        } 

        return 0;

      }