Posts: 2
Joined: Thu Feb 22, 2018 3:51 am

GPIO and C Begginners

Thu Feb 22, 2018 3:58 am

Hi, i't my first post.
I have to say im kinda lost with the Raspberry stuff. I have a Raspberry PI 3.

I have been studying the GPIO connector and readed a lot of stuff about it.

Anyway, i just want to program the GPIO interface in pure C. The memory mappings of the BCM datasheet says the Peripherihals are mapped in some adress.

I don't want to use /dev entries to program the GPIO. I just want to write the mapped adress to send info to the GPIO.

But, i'm a little bit confused.

User avatar
Posts: 12948
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: GPIO and C Begginners

Thu Feb 22, 2018 6:15 am

The usual method is to memmap /dev/gpiomem which will give you an area of memory to use that will include the GPIO address range.

Posts: 10268
Joined: Tue Jul 17, 2012 3:02 pm

Re: GPIO and C Begginners

Thu Feb 22, 2018 8:12 am

My C code that accesses the GPIO register directly is based on this example : ... ter_access

Works a treat.

Posts: 14
Joined: Sat Aug 05, 2017 12:00 pm
Location: UK

Re: GPIO and C Begginners

Sat Mar 03, 2018 9:48 am


Having been in the same place as you a few months ago I looked at WiringPi and the BCM2835 library I found both of the libraries easy to use, the WiringPi site has some helpful examples too.

Hope that helps
The ProgrammingPescador

User avatar
Forum Moderator
Forum Moderator
Posts: 4627
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: GPIO and C Begginners

Sat Mar 03, 2018 4:39 pm

My early GPIO 'C' programming started with using the wiringPi libraries (around which I wrote my own, diagnostic wrappers). I've also done the same with some of @joan's pigpio library tools (both libraries are now automatically included with Raspbian). FWIW, you're welcome to download a "snapshot" of my (in "continuous development") "GPIO Demo Software" to "peruse": ... tware.html - circuits/modules to which the various programs included apply start here: ... Boards_Etc.
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my 2xP3A+, P3B+, P3B, B+, A+ and a B2. See:

Return to “C/C++”