Orange PI PC2 GPIO 설치, pi4j

OS/Orange PI 2017.03.17 01:53 Posted by 파란크리스마스

Orange PI PC2 GPIO 설치

출처 : This is a modified WiringPi for OrangePi. We call it WiringOP. Test fo Orangepi pc
OrangePi-PCを使ってみる WiringPiとWiringOP
Orange PI PC 2 GPIO доступ через sysfs

현재 pi4j는 Orange PI PC2 지원하지 않아 수정한 jar를 배포합니다.

pi4j-core.jar

$ git clone https://github.com/kazukioishi/WiringOP.git -b h5
$ cd WiringOP
$ chmod +x ./build
$ sudo ./build
$ gpio -v
gpio version: 2.20
Copyright (c) 2012-2014 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty
 
Banana Pro Details:
  Type: Banana Pro, Revision: 1.2, Memory: 1024MB, Maker: LeMaker 
$ gpio readall
 +-----+-----+----------+------+---+-Orange Pi+---+---+------+---------+-----+--+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 |     |     |     3.3v |      |   |  1 || 2  |   |      | 5v       |     |     |
 |  12 |   8 |    SDA.0 | ALT5 | 0 |  3 || 4  |   |      | 5V       |     |     |
 |  11 |   9 |    SCL.0 | ALT5 | 0 |  5 || 6  |   |      | 0v       |     |     |
 |   6 |   7 |   GPIO.7 | ALT3 | 0 |  7 || 8  | 0 | ALT5 | TxD3     | 15  | 13  |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT5 | RxD3     | 16  | 14  |
 |   1 |   0 |     RxD2 | ALT5 | 0 | 11 || 12 | 0 | ALT3 | GPIO.1   | 1   | 110 |
 |   0 |   2 |     TxD2 | ALT5 | 0 | 13 || 14 |   |      | 0v       |     |     |
 |   3 |   3 |     CTS2 | ALT5 | 0 | 15 || 16 | 0 | ALT3 | GPIO.4   | 4   | 68  |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO.5   | 5   | 71  |
 |  64 |  12 |     MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v       |     |     |
 |  65 |  13 |     MISO | ALT0 | 0 | 21 || 22 | 0 | ALT5 | RTS2     | 6   | 2   |
 |  66 |  14 |     SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0      | 10  | 67  |
 |     |     |       0v |      |   | 25 || 26 | 0 | ALT3 | GPIO.11  | 11  | 21  |
 |  19 |  30 |    SDA.1 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.1    | 31  | 18  |
 |   7 |  21 |  GPIO.21 | ALT3 | 0 | 29 || 30 |   |      | 0v       |     |     |
 |   8 |  22 |  GPIO.22 | ALT3 | 0 | 31 || 32 | 0 | ALT5 | RTS1     | 26  | 200 |
 |   9 |  23 |  GPIO.23 | ALT3 | 0 | 33 || 34 |   |      | 0v       |     |     |
 |  10 |  24 |  GPIO.24 | ALT3 | 0 | 35 || 36 | 0 | ALT5 | CTS1     | 27  | 201 |
 |  20 |  25 |  GPIO.25 |  OUT | 1 | 37 || 38 | 0 | ALT5 | TxD1     | 28  | 198 |
 |     |     |       0v |      |   | 39 || 40 | 0 | ALT5 | RxD1     | 29  | 199 |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+-Orange Pi+---+------+----------+-----+-----+

C언어 샘플 소스

#include <wiringpi.h>
 
int main()
{
  wiringPiSetup();
  pinMode(7, OUTPUT);
  while(1) {
    digitalWrite(7,HIGH); 
    delay(500);
    digitalWrite(7,LOW); 
    delay(500);
  }
  return 0;
}

컴파일

$ gcc -Wall -o blink blink.c -lwiringPi -lpthread

실행

$ sudo ./blink
wiringPi: wiringPiSetup called
piboardRev: Hardware string: Hardware   : sun50iw2
Hardware:Hardware       : sun50iw2
piboardRevH3:  3
piboardRev: Hardware string: Hardware   : sun50iw2
Hardware:Hardware       : sun50iw2
piboardRevH3:  3
piboardRev: Hardware string: Hardware   : sun50iw2
Hardware:Hardware       : sun50iw2
piboardId: Revision string: 0000
pinMode,1947,pin:7,mode:1
func:sunxi_set_gpio_mode pin:6, MODE:1 bank:0 index:6 phyaddr:0x1c20800
read reg val: 0x71222222 offset:24
Out mode ready set val: 0x71222222
Out mode set over reg val: 0x71222222
digitalWrite,2270
func:sunxi_digitalWrite pin:6, value:1 bank:0 index:6 phyaddr:0x1c20810
befor write reg val: 0x100040,index:6
HIGH val set over reg val: 0x100040
digitalWrite,2270
func:sunxi_digitalWrite pin:6, value:0 bank:0 index:6 phyaddr:0x1c20810
befor write reg val: 0x100040,index:6
LOW val set over reg val: 0x100000
digitalWrite,2270
func:sunxi_digitalWrite pin:6, value:1 bank:0 index:6 phyaddr:0x1c20810
befor write reg val: 0x100000,index:6
HIGH val set over reg val: 0x100040
digitalWrite,2270
func:sunxi_digitalWrite pin:6, value:0 bank:0 index:6 phyaddr:0x1c20810
befor write reg val: 0x100040,index:6
LOW val set over reg val: 0x100000
digitalWrite,2270
func:sunxi_digitalWrite pin:6, value:1 bank:0 index:6 phyaddr:0x1c20810
befor write reg val: 0x100000,index:6
HIGH val set over reg val: 0x100040

java 샘플 소스

import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.OrangePiPc2GpioProvider;
import com.pi4j.wiringpi.Gpio;

public class Blink {

	public static void main(String[] args) throws InterruptedException {
		
		GpioFactory.setDefaultProvider(new OrangePiPc2GpioProvider());

		// setup wiring pi
		if (Gpio.wiringPiSetup() == -1) {
			System.out.println(" ==>> GPIO SETUP FAILED");
			return;
		}

		Gpio.pinMode(7, Gpio.OUTPUT);
		while (true) {
			Gpio.digitalWrite(7, Gpio.HIGH);
			Gpio.delay(500);
			Gpio.digitalWrite(7, Gpio.LOW);
			Gpio.delay(500);
		}
	}
}

실행

$ sudo java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar Blink

실행결과

저작자 표시
신고


 

티스토리 툴바