Pi
2017.02.15 17:48

라즈베리파이 gpio utility

조회 수 6374 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

https://projects.drogon.net/raspberry-pi/wiringpi/the-gpio-utility/



The GPIO utility

WiringPi comes with a separate program to help manage the GPIO. This program, called gpio, can also be used in scripts to manipulate the GPIO pins – set outputs and read inputs. It’s even possible to write entire programs just using the gpio command in a shell-script, although it’s not terribly efficient doing it that way… Another way to call it is using the system() function in C/C++ or it’s equivalent in other programming languages.

  • The gpio command is designed to be installed as a setuid program and called by a normal user without using the sudo command (or logging in as root).

In addition to using the gpio utility to control the GPIO pins, you can:

  • Export/Unexport pins via the /sys/class/gpio interface, where they will then be available to user programs (that then do not need to be run as root or with sudo)
  • Export pins to enable edge-triggered interrupts via the /sys/class/gpio interface.
  • Control the pins on the PiFace peripheral device.
  • Load SPI and I2C modules and set /dev/ permissions to enable read/write by the user running the gpio program.
  • Set the SPI buffer size and  I2C baud rate (when loading the modules)
  • Output values to the Gertboard DAC
  • Read inputs from the Gertboard ADC
  • Determine your Raspberry Pi board hardware revision.

See the man page for the gpio program to see what all the features are by typing

man gpio

at the command prompt.

Usage

From the Linux command line:

  • gpio -v

This prints the version.

  • gpio -g …

The optional -g flag causes pin numbers to be interpreted as BCM_GPIO pin numbers rather than standard wiringPi pin numbers.

Standard input and output commands

  • gpio [-g] mode <pin> in/out/pwm/up/down/tri

This sets the mode of a pin to be input, output or pwm and additionally can set the internal pull-up/down resistors to pull-up, pull-down or none.

  • gpio [-g] write <pin> 0/1

This sets an output pin to high (1) or low (0)

  • gpio [-g] pwm <pin> <value>

Set the pin to a PWM value (0-1023 is supported)

  • gpio [-g] read <pin>

Reads and prints the logic value of the given pin. It will print 0 (low) or 1 (high).

  • gpio readall

This reads all the normally accessible pins and prints a table of their numbers (both wiringPi and BCM_GPIO, so makes for a handy cross-reference chart), along with their modes and current values.

Module Load Commands

  • gpio load spi [buffer size in KB]

This loads the SPI kernel modules and optionally sets the internal buffer to the given size in KB (multiples of 1024). The default is 4KB and is usually more than enough for most application which only exchange a byte or 2 at a time over the SPI bus.

The /dev/spi* entries are set to be owned by the person using the gpio program, so there is no need to run subsequent programs as root (unless they use other wiringPi functions)

  • gpio load i2c [baud rate in Kb/sec]

This loads the I2C kernel modules and optionally sets the baud rate to the given speed in Kb/sec (multiples of 1000). The default is 100Kb/sec.

The /dev/I2c* entries are set to be owned by the person using the gpio program, so there is no need to run subsequent programs as root (unless they use other wiringPi functions)

/sys/class/gpio mode commands

  • gpio export <pin> in/out

This exports the given pin (BCM-GPIO pin number) as an input or output and makes it available for a user program running as the same user to use.

  • gpio unexport <pin>

Removes the export of the given pin.

  • gpio unexportall

Removes all /sys/class/gpio exports.

  • gpio exports

This prints a list of all gpio pins which have been exported via the /sys/class/gpio interface and their modes.

  • gpio edge <pin> rising/falling/both/none

This enables the given pin for edge interrupt triggering on the rising, falling or both edges. (Or none which disables it)

Note: The pin numbers in the sys mode are always BCM-GPIO pin numbers.

Examples

gpio mode 0 out
gpio write 0 1

This uses the wiringPi pin numbers to set pin 0 as an output and then sets the pin to a logic 1.

gpio -g mode 0 in
gpio -g read 0

This uses the BCM_GPIO pin numbering scheme and reads pin 0 (SDA0 on a Rev. 1 Raspberry Pi)

Internal pull up/down resistors

The GPIO lines have internal pull up or pull-down resistors which can be controlled via software when a pin is in input mode.

gpio mode 0 up
gpio mode 0 down
gpio mode 0 tri

These set the resistors to pull-up, pull-down and none respectively on wiringPi pin 0.

PiFace Commands

The PiFace is somewhat limited in that it has 8 inputs pins and 8 output pins and these are fixed in the hardware, so only the write and read commands are implemented:

  • gpio -p write <pin> 0/1

Writes the value 0 (off) or 1 (on) to the output pin on the PiFace

  • gpio -p read <pin>

Reads and prints the value on the given input pin.

  • gpio -p mode <pin> up/tri

This enables (up) or disables (tri) the internal pull-up resistor on the given input pin. You need to enable the pull-up if you want to read any of the on-board switches on the PiFace board.



Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
401 일반 배치파일(bat)에서 for루프 사용법 2010.04.15 47827 0
400 일반 배치파일(bat 파일) 명령어 사용법 2007.01.23 42999 61
399 C# 문자열 다루기 1 2012.04.06 18653 0
398 C# 문자열 검색 / 조작 2012.01.03 23561 0
397 Pi 무선랜 wifi 설정 2015.10.01 6979 0
396 LINUX 명령어 뒤의 옵션 자동완성 기능, complete 명령어 2015.01.06 9000 0
395 Android 맨날 까먹는 버튼 클릭 이벤트 핸들러 코드 2014.12.17 5964 0
394 LINUX 매번 잊는다.. tar 풀기 : tar zxvf file 2 2009.04.14 36736 0
393 일반 마크다운 markdown (.md) 파일이란 2017.07.12 12408 0
392 업무 마이크로 버블 Micro Bubble 이란 2016.08.29 9482 0
391 MFC 리사이징 다이얼로그(Resizing dialog) 2008.03.24 46824 0
390 LINUX 리눅스의 기본 명령어들 2015.01.20 6786 0
389 LINUX 리눅스에서 특정작업 or 명령어 반복하기 Crontab 2014.11.10 10386 0
388 LINUX 리눅스 파일시스템 체크 하기 fsck(e2fsck) 사용법 2016.04.15 39956 0
387 LINUX 리눅스 커널리빌딩, 버젼확인, ctags명령, vi편집기활용, 기본명령 2012.05.07 15054 0
목록
Board Pagination ‹ Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5