LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 08-13-2016, 05:00 AM   #1
jiatang
Member
 
Registered: Jul 2016
Posts: 36

Rep: Reputation: Disabled
Cool How to use the GPIO of NanoPi M3


In embedded devices,we often need to control device's GPIO,and we general write one driver program. Actually there is one easy way to control GPIO,that is “/sys/class/gpio” mode. Using this method , you donot need to write drivers, use GPIO directly, the kernel is smaller and
the development is more convenient.

First ,you log File System through the serial port ,to check if there is “/sys/class/gpio” folder or not. If there isn't exit the folder,you need increase sysfs interface when you compile the kernel Device Drivers——> GPIO Support——> /sys/class/gpio/....

1、gpio_operation:Via /sys/ file interface to Operat IO port GPIO mapping to file system;

2、Control GPIO directory located in /sys/class/gpio;

3、Use /sys/class/gpio/export file to notify system which GPIO number need to be exported;

4、Use /sys/class/gpio/unexport to notify system cancel exports GPIO

5、/sys/class/gpio/gpiochipX directly which saves GPIO register's information of system,which includes the first number base 、register name、total PIN number exports a PIN's foot steps of register control PIN;
(X means number)

6、First we need to count PIN number,PIN number = register cardinal number of control PIN + register digit of control PIN

7、Wite number to /sys/class/gpio/export ,example if you want to export 12 PIN,you can use the command which will be introduced ;

8:echo 12 > /sys/class/gpio/export;

9、We can use direction file to define input/output direction;

10:echo out > direction;

11、There are accepted parameters:in, out, high, low,and high/low all set the direction as output,and set value as corresponding 1/0;

12、“value” file is port's numerical,that is 1 or 0;

13:echo 1 & > value.

/sys/class/gpio introductions:

Test:Since we want to use sysfs method to operat GPIO,we need to find out the PIN number that corresponds to the kernel(each GPIO number have its only number in kernel),you can use the following method to check out kernel number:

1)After NanoPi M3 booting,enter the root file system;

2)Type these commands in terminal:
# cd /sys/class/gpio
# for i in gpiochip* ; do echo `cat $i/label`: `cat $i/base` ; done
nxp-gpio.0: 0
nxp-gpio.4: 128
nxp-gpio.5: 160
nxp-gpio.1: 32
nxp-gpio.2: 64
nxp-gpio.3: 96

Actually gpio.0 is mean GPIOA,gpio.1 is mean GPIOB,and the other is the same.
If we want to use GPIO30 PIN of NanoPi M3 in your application,the PIN number can be expressed as 64+30=94,that is mean we use 94 PIN GPIO.
 
Old 08-14-2016, 08:57 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,

Thanks for sharing..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NanoPi M3 Assigns IP Address jiatang Linux - Embedded & Single-board computer 1 08-16-2016 10:53 PM
Configure the Firewalls with NanoPi M3 jiatang Linux - Software 2 08-16-2016 10:45 PM
How to open GPIO with NanoPi M3 jiatang Linux - Hardware 0 08-09-2016 10:45 AM
GPIO access on a Fujitsu Mini-ITX Industrial Mainboard, PCI Driver for GPIO mechatrix Linux - Embedded & Single-board computer 3 11-20-2011 03:57 PM
Using GPIO (from kernel GPIO support) in MY application DannyGilbert Linux - Kernel 2 03-16-2009 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 08:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration