johan_rasp_prog
Posts: 1
Joined: Wed Jan 31, 2018 12:53 pm

Writing to gpio

Wed Jan 31, 2018 12:58 pm

I have a Raspberry Pi 3 with Raspbian and I wonder what I need to do to be able to make a software which writes to the gpio addresses? Right now I get segmentation fault even if I run as root.
Can I use Linux in some way or do I have to do a bare metal software? In either way, does someone know a tutorial I can follow?

I want to be able to write to the gpio and the dma controller.


Regards
Johan

jahboater
Posts: 2858
Joined: Wed Feb 04, 2015 6:38 pm

Re: Writing to gpio

Wed Jan 31, 2018 2:09 pm

Linux/Raspbian.

You can use a library such as wiringPi or pigpio (both of which are pre-installed and ready to go).
Or you can write your own code in C, using the mmap() system call.
I suggest a popular library.

User avatar
joan
Posts: 13542
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Writing to gpio

Wed Jan 31, 2018 4:15 pm


User avatar
rados-dataplicity
Posts: 40
Joined: Wed Aug 03, 2016 11:56 am
Location: UK
Contact: Website Facebook Twitter

Re: Writing to gpio

Fri Feb 09, 2018 5:22 pm

From bash command line you can simply do:

Code: Select all

		
echo "5" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio5/direction
echo "1" > /sys/class/gpio/gpio5/value
Ofcourse, adjust parameters such as GPIO pin number as you wish ;)

/sys is your interface between the kernel
I tinker around with Raspberry Pis daily and make sure that people can easily access theirs remotely.

Community outreach @ dataplicity.com

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 3 guests