ateneo
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
rpdom
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.

Heater
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 :
https://elinux.org/RPi_GPIO_Code_Sample ... ter_access

Works a treat.

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

Re: GPIO and C Begginners

Sat Mar 03, 2018 9:48 am

Hi

Having been in the same place as you a few months ago I looked at WiringPi http://wiringpi.com/ and the BCM2835 library http://www.airspayce.com/mikem/bcm2835/. I found both of the libraries easy to use, the WiringPi site has some helpful examples too.

Hope that helps
The ProgrammingPescador

User avatar
FTrevorGowen
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": http://www.cpmspectrepi.uk/raspberry_pi ... tware.html - circuits/modules to which the various programs included apply start here: http://www.cpmspectrepi.uk/raspberry_pi ... Boards_Etc.
Trev.
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: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Return to “C/C++”