Hugh Jarse
Posts: 46
Joined: Mon Mar 05, 2012 5:03 pm

Re: Programming GPIO

Sat Mar 10, 2012 9:12 pm

Can anyone shed any light on what (if any) programming interfaces will be available for reading and writing to the GPIO hardware - e.g. will it be accessible from say python.

Is it the case that we will need to await drivers from the open source community, or is there something already available for the recommended distros.

If there is something available, what is the preferred language/environment for accessing this.

Thanks

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Programming GPIO

Sat Mar 10, 2012 9:33 pm

It seems there will be a number if ways to access the gpio port. Someone has started a tutorial on it. Search will find you plenty of info.

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Hugh Jarse
Posts: 46
Joined: Mon Mar 05, 2012 5:03 pm

Re: Programming GPIO

Sat Mar 10, 2012 11:01 pm

Thanks for your reply.

It seems that output will be done by redirecting data to a logical file  :

http://www.raspberrypi.org/archives/500

which is great, and seems straight forward.  Has anyone seen any info on generating interrupts/events/python signals from the pins assigned to input ?

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Programming GPIO

Sat Mar 10, 2012 11:08 pm

The data sheet will give you all the register addresses you need. The ARM architecture documents will tell you how interrupts work, and there is a demonstration program somewhere on here to show you how to map memory to access the registers directly.

I don't believe (I may be wrong) that user programs can use interrupts. So if you want to use interrupts, then you need to build a Linux driver, which I'm told is easy... but there are various levels of easy and writing an interrupt-driven device driver is never very easy.

Hugh Jarse
Posts: 46
Joined: Mon Mar 05, 2012 5:03 pm

Re: Programming GPIO

Sat Mar 10, 2012 11:29 pm

The FAQ suggests the datasheet is not available yet - is this still the case?

Meanwhile it looks as if inotify may be one way of generating events in C or Python, when a file is changed (i.e. a GPIO input changes).

secretagent
Posts: 36
Joined: Wed Mar 07, 2012 10:09 am

Re: Programming GPIO

Sun Mar 11, 2012 1:01 am

rurwin said:


I don't believe (I may be wrong) that user programs can use interrupts. So if you want to use interrupts, then you need to build a Linux driver, which I'm told is easy… but there are various levels of easy and writing an interrupt-driven device driver is never very easy.


As far as I remember, if the gpio driver already has support for interrupts (and it seems like this one does) then you can set them up from userspace by writing to the "edge" file in the gpio's directory and then you can do poll or select on the "value" file. Then, the value file becomes "ready" for reading when an interrupt arrives for that pin.

secretagent
Posts: 36
Joined: Wed Mar 07, 2012 10:09 am

Re: Programming GPIO

Sun Mar 11, 2012 1:16 am

MartyR said:


The FAQ suggests the datasheet is not available yet - is this still the case?


There is a peripherals datasheet here: http://www.raspberrypi.org/wp-.....herals.pdf and the ARM core's manual is here: http://infocenter.arm.com/help.....p7_trm.pdf

MartyR said:


Meanwhile it looks as if inotify may be one way of generating events in C or Python, when a file is changed (i.e. a GPIO input changes).


I think inotify only works for regular files, but see my previous reply regarding userspace events for the GPIO input changes.

Hugh Jarse
Posts: 46
Joined: Mon Mar 05, 2012 5:03 pm

Re: Programming GPIO

Sun Mar 11, 2012 11:24 am

Thanks for your replies.

Return to “General discussion”