Community
cancel
Showing results for 
Search instead for 
Did you mean: 
jmccu3
Beginner
1,148 Views

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

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

# include

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;

}

0 Kudos
4 Replies
FTinetti
Honored Contributor I
61 Views

Hi jeremy2017,

I suggest you try first using the console as briefly explained at (take a look at the first Pablo reply) so you don't have to compile, and later to include your findings in your .c code once you know you are doing what you need.

I'll try to find some more information on this, since I've not done it before. Maybe you can look for similar threads in this forum too.

Edit: there are several other threads, but they refer to Intel Galileo, not Intel Galileo Gen2, and I think pin numbers are different...

HTH,

Fernando.

jmccu3
Beginner
61 Views

Thank you. I have the Galileo Gen 2 reading from the 1 or 0 listed by accessing the files corresponding to the "value" files for the GPIO pins. I found some commands from this link http://www.malinov.com/Home/sergey-s-blog/intelgalileo-programminggpiofromlinux Intel Galileo - Programming GPIO From Linux - Malinov Family Web Presence

root@clanton:~# echo -n "1" > /sys/class/gpio/gpio27/value

root@clanton:~# echo -n "0" > /sys/class/gpio/gpio27/value

Now my issue is get the timing correct so I am able to use the Galileo to interface with a PIC16F18857. I want the Galileo to send a message (using the GPIO pins and a "strobe signal" to the PIC and then have the PIC send a message back (using the same GPIO pins). It seems that I may have a timing issue; because when I set the Galileo GPIO pins to write (OUTPUT) then send a message and then wait for a reply message(INPUT) from the PIC the messages fail. I think there is a timing issue I need to figure out so I know for certain that the Galileo and PIC are in read or write modes at different times.

I'll try to get the code that I'm using posted for review soon.

Thank you for you help,

Jeremy

FTinetti
Honored Contributor I
61 Views

Good to know you managed to handle pin values

Remember Yocto Linux is not a real time OS so it's likely you'll have timing issues in timing dependent signals, I/O, processing, etc.

Fernando.

idata
Community Manager
61 Views

Hi Jeremy2017,

 

 

Do you have any updates about this? Do you still have issues?

 

 

The reply from FGT is very helpful, please check it and let us know if it works.

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
Reply