티스토리 뷰

OS/NanoPi

NanoPi NEO Air - WiringNP, pi4j

파란크리스마스 2017. 3. 22. 02:05
728x90

NanoPi NEO Air - WiringNP, pi4j

출처 : NanoPi NEO Air

현재 pi4j는 NanoPi NEO Air을 지원하지 않아 수정한 jar를 배포합니다.

pi4j-core.jar

# git clone git://github.com/wertyzp/WiringNP
# cd WiringNP
# sh ./build

GPIO 설치 확인

# 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: Model A, Revision: 1.2, Memory: 1024MB, Maker: LeMaker 
# gpio readall
 +-----+-----+----------+------+---+-NanoPI M1+---+------+----------+-----+-----+
 | 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       |     |     |
 | 203 |   7 |   GPIO.7 |  OUT | 1 |  7 || 8  | 0 | ALT5 | TxD3     | 15  | 198 |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT5 | RxD3     | 16  | 199 |
 |   0 |   0 |     RxD2 | ALT5 | 0 | 11 || 12 | 0 | OFF  | GPIO.1   | 1   | 6   |
 |   2 |   2 |     TxD2 | ALT5 | 0 | 13 || 14 |   |      | 0v       |     |     |
 |   3 |   3 |     CTS2 | ALT5 | 0 | 15 || 16 | 0 | OFF  | GPIO.4   | 4   | 200 |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | OFF  | GPIO.5   | 5   | 201 |
 |  64 |  12 |     MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v       |     |     |
 |  65 |  13 |     MISO | ALT4 | 0 | 21 || 22 | 0 | ALT5 | RTS2     | 6   | 1   |
 |  66 |  14 |     SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0      | 10  | 67  |
 |     |     |       0v |      |   | 25 || 26 | 0 | OFF  | GPIO.11  | 11  | 17  |
 |  19 |  30 |    SDA.1 | ALT5 | 0 | 27 || 28 | 0 | ALT5 | SCL.1    | 31  | 18  |
 |  20 |  21 |  GPIO.21 | ALT5 | 0 | 29 || 30 |   |      | 0v       |     |     |
 |  21 |  22 |  GPIO.22 | ALT5 | 0 | 31 || 32 | 0 | OFF  | RTS1     | 26  | 7   |
 |   8 |  23 |  GPIO.23 |  OUT | 0 | 33 || 34 |   |      | 0v       |     |     |
 |  16 |  24 |  GPIO.24 | ALT4 | 0 | 35 || 36 | 0 | ALT4 | CTS1     | 27  | 13  |
 |   9 |  25 |  GPIO.25 |  OFF | 0 | 37 || 38 | 0 | OUT  | TxD1     | 28  | 15  |
 |     |     |       0v |      |   | 39 || 40 | 0 | ALT4 | RxD1     | 29  | 14  |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+-NanoPI M1+---+------+----------+-----+-----+

 +-----+----NanoPI M1 Debug UART---+----+
 | BCM | wPi |   Name   | Mode | V | Ph |
 +-----+-----+----------+------+---+----+
 |     |     |       0v |      |   | 41 |
 |     |     |       5v |      |   | 42 |
 |   4 |  32 |   GPIO.4 | ALT5 | 0 | 43 |
 |   5 |  33 |   GPIO.5 | ALT5 | 0 | 44 |
 +-----+-----+----------+------+---+----+

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

실행

# ./blink

java 샘플 소스

/*
 * #%L
 * **********************************************************************
 * ORGANIZATION  :  Pi4J
 * PROJECT       :  Pi4J :: Java Examples
 * FILENAME      :  ControlGpioExample.java
 *
 * This file is part of the Pi4J project. More information about
 * this project can be found here:  http://www.pi4j.com/
 * **********************************************************************
 * %%
 * Copyright (C) 2012 - 2016 Pi4J
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * <http: www.gnu.org="" licenses="" lgpl-3.0.html="">.
 * #L%
 */
 
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.NanoPiNEOAirGpioProvider;
import com.pi4j.io.gpio.NanoPiNEOAirPin;
import com.pi4j.io.gpio.PinState;
 
/**
 * This example code demonstrates how to perform simple state
 * control of a GPIO pin on the Raspberry Pi.
 *
 * @author Robert Savage
 */
public class ControlGpioExample {
 
    public static void main(String[] args) throws InterruptedException {

        //GpioFactory.setDefaultProvider(new OrangePiPc2GpioProvider());
        GpioFactory.setDefaultProvider(new NanoPiNEOAirGpioProvider());

        System.out.println("<--Pi4J--> GPIO Control Example ... started.");
 
        // create gpio controller
        final GpioController gpio = GpioFactory.getInstance();
 
        // provision gpio pin #01 as an output pin and turn on
        final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(NanoPiNEOAirPin.GPIO_07, "MyLED", PinState.HIGH);
 
        // set shutdown state for this pin
        pin.setShutdownOptions(true, PinState.LOW);
 
        System.out.println("--> GPIO state should be: ON");
 
        Thread.sleep(5000);
 
        // turn off gpio pin #01
        pin.low();
        System.out.println("--> GPIO state should be: OFF");
 
        Thread.sleep(5000);
 
        // toggle the current state of gpio pin #01 (should turn on)
        pin.toggle();
        System.out.println("--> GPIO state should be: ON");
 
        Thread.sleep(5000);
 
        // toggle the current state of gpio pin #01  (should turn off)
        pin.toggle();
        System.out.println("--> GPIO state should be: OFF");
 
        Thread.sleep(5000);
 
        // turn on gpio pin #01 for 1 second and then off
        System.out.println("--> GPIO state should be: ON for only 1 second");
        pin.pulse(1000, true); // set second argument to 'true' use a blocking call
 
        // stop all GPIO activity/threads by shutting down the GPIO controller
        // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
        gpio.shutdown();
 
        System.out.println("Exiting ControlGpioExample");
    }
}

실행

# java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar ControlGpioExample

실행결과


댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함