Search

Orange PI Zero - pi4j로 PWM 제어

OS/Orange PI 2017.03.25 12:10 Posted by 파란크리스마스

Orange PI Zero - pi4j로 PWM 제어

Orange PI Zero는 하나의 PWM만 지원

배선

Java 소스

import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.OrangePiZeroGpioProvider;
import com.pi4j.wiringpi.Gpio;
import com.pi4j.wiringpi.SoftPwm;

public class SG90PWMMain {

	private static int PIN_NUMBER = 7;

	public static void main(String[] args) throws Exception {
		//
		//GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
		//GpioFactory.setDefaultProvider(new OrangePiPc2GpioProvider());
		//GpioFactory.setDefaultProvider(new NanoPiNEOAirGpioProvider());
		GpioFactory.setDefaultProvider(new OrangePiZeroGpioProvider());

		// initialize wiringPi library, this is needed for PWM
		Gpio.wiringPiSetup();

		// softPwmCreate(int pin, int value, int range)
		// the range is set like (min=0 ; max=100)
		SoftPwm.softPwmCreate(PIN_NUMBER, 0, 50);
		int counter = 0;
		while (counter < 3) {
			// fade LED to fully ON
			for (int i = 0; i <= 100; i++) {
				// softPwmWrite(int pin, int value)
				// This updates the PWM value on the given pin. The value is
				// checked to be in-range and pins
				// that haven't previously been initialized via softPwmCreate
				// will be silently ignored.
				SoftPwm.softPwmWrite(PIN_NUMBER, i);
				Thread.sleep(25);
			}
			// fade LED to fully OFF
			for (int i = 100; i >= 0; i--) {
				SoftPwm.softPwmWrite(PIN_NUMBER, i);
				Thread.sleep(25);
			}
			counter++;
		}
	}

}

실행

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

실행 영상

저작자 표시
신고

Orange PI Zero GPIO 설치, pi4j

OS/Orange PI 2017.03.25 03:01 Posted by 파란크리스마스

Orange PI Zero GPIO 설치

출처 : WiringOP for Orange pi zero - Beginners - OrangePi - Powered by

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

pi4j-core.jar

$ sudo apt-get install build-essential
$ git clone https://github.com/zhaolei/WiringOP.git -b h3
$ 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 
orangepi@OrangePizero:~/WiringOP$ 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 | ALT3 | TxD3     | 15  | 13  |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT3 | 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 | ALT3 | 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 | ALT4 | 0 | 21 || 22 | 0 | ALT3 | 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 | ALT3 | RTS1     | 26  | 200 |
 |   9 |  23 |  GPIO.23 | ALT3 | 0 | 33 || 34 |   |      | 0v       |     |     |
 |  10 |  24 |  GPIO.24 |  OUT | 0 | 35 || 36 | 0 | ALT3 | 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

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.OrangePiZeroGpioProvider;
import com.pi4j.io.gpio.OrangePiZeroPin;
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());
    	GpioFactory.setDefaultProvider(new OrangePiZeroGpioProvider());

        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(OrangePiZeroPin.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");
    }
}

실행

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

실행결과

저작자 표시
신고

Orange PI Zero

OS/Orange PI 2017.03.25 02:01 Posted by 파란크리스마스

Orange PI Zero

출처 : 스터디메이크 :: 오렌지파이 제로 보드 간단 사용기
Xunlong Orange Pi Zero

vi 설치

$ sudo apt-get install vim

vnc 설치

출처 : Armbian: Access the Remote Desktop of Orange Pi with VNC

vnc 설치

$ sudo apt-get update && apt-get upgrade
$ sudo apt-get install tightvncserver

vnc 사용자 추가

$ su - 
# adduser vnc
Adding user `vnc' ...
Adding new group `vnc' (1001) ...
Adding new user `vnc' (1001) with group `vnc' ...
Creating home directory `/home/vnc' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for vnc
Enter the new value, or press ENTER for the default
        Full Name []: VNCuser
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] 

vnc 사용자 추가

# gpasswd -a vnc sudo
Adding user vnc to group sudo

vnc 서버 실행

# su - vnc
$ vncserver :1
 
You will require a password to access your desktops.
 
Password: 
Verify:   
Would you like to enter a view-only password (y/n)? 
*** buffer overflow detected ***: vncpasswd terminated
xauth:  file /home/vnc/.Xauthority does not exist
 
New 'X' desktop is OrangePizero:1
 
Creating default startup script /home/vnc/.vnc/xstartup
Starting applications specified in /home/vnc/.vnc/xstartup
Log file is /home/vnc/.vnc/OrangePizero:1.log

Wifi 설정

출처 : 014. Raspberry Pi 라즈베리 파이 - wheezy무선랜 ... - Tsunami - Tistory

$ cd /etc/ifplugd/action.d/
$ sudo mv ifupdown ifupdown.bk
$ sudo cp /etc/wpa_supplicant/ifupdown.sh ./ifupdown

암비안 와이파이 설정

출처 : 오렌지파이 제로 무선인터넷 설정 1.2 암비안 와이파이 설정

$ sudo nmtui

SD 확장

SD 확장전 용량확인

$ sudo fdisk /dev/mmcblk0
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.6G  1.2G  349M  78% /
devtmpfs        168M     0  168M   0% /dev
tmpfs           224M     0  224M   0% /dev/shm
tmpfs           224M  8.5M  216M   4% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           224M     0  224M   0% /sys/fs/cgroup
tmpfs           224M  4.0K  224M   1% /tmp
/dev/mmcblk0p1   63M  4.6M   59M   8% /media/boot
tmpfs            45M     0   45M   0% /run/user/107
tmpfs            45M     0   45M   0% /run/user/1000

SD FDisk

orangepi@OrangePizero:~$ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000b04ea

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1       40960  172031  131072   64M  b W95 FAT32
/dev/mmcblk0p2      172032 3514367 3342336  1.6G 83 Linux


Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2048-15523839, default 2048): 172032
Last sector, +sectors or +size{K,M,G,T,P} (172032-15523839, default 15523839): 

Created a new partition 2 of type 'Linux' and of size 7.3 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

orangepi@OrangePizero:~$ sudo shutdown -r now

SD 확장

$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 1918976 (4k) blocks long.

SD 확장 확인

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.3G  1.2G  5.8G  17% /
devtmpfs        168M     0  168M   0% /dev
tmpfs           224M     0  224M   0% /dev/shm
tmpfs           224M  8.5M  216M   4% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           224M     0  224M   0% /sys/fs/cgroup
tmpfs           224M  4.0K  224M   1% /tmp
/dev/mmcblk0p1   63M  4.6M   59M   8% /media/boot
tmpfs            45M     0   45M   0% /run/user/107
tmpfs            45M     0   45M   0% /run/user/1000

JDK 설치

$ sudo apt install -t jessie-backports openjdk-8-jre openjdk-8-jre-headless openjdk-8-jdk openjdk-8-jdk-headless ca-certificates-java

JAVA_HOME 환경변수 추가

$ sudo vi /etc/profile

내용 추가 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-armhf

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-armhf
저작자 표시
신고

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

실행결과

저작자 표시
신고

Orange PI PC2 mjpg-streamer

OS/Orange PI 2017.03.14 23:14 Posted by 파란크리스마스

Orange PI PC2 mjpg-streamer

출처 : 【BPI-M2+】之mjpg-streamer测试和体验- Bananap讨论区- 烽火社区 ...
MJPG-Streamer › Wiki › ubuntuusers.de
라즈베리파이에서 웹캠 mjpg-streamer 따라하기|작성자 서리
mjpg-streamer 웹캠 영상 스트리밍 | Mungrrr

관련 라이브러리 설치

$ sudo apt-get install libjpeg8-dev libv4l-dev subversion
$ sudo apt-get install imagemagick

mjpg-streamer 컴파일 및 설치

출처 : http://www.lavrsen.dk/svn/motion/tags/3.2.9/picture.c

$ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer
$ make USE_LIBV4L2=true clean all
$ sudo make install
install --mode=755 mjpg_streamer /usr/local/bin
install --mode=644 input_ov5640.so input_gc2035.so input_uvc.so output_file.so output_udp.so output_http.so input_testpicture.so input_file.so /usr/local/lib/
install --mode=755 -d /usr/local/www
install --mode=644 -D www/* /usr/local/www

input_gc2035.so

input_gc2035.tar.gz

mjpg-streamer의 input_uvc.so는 YUV만 지원하고, Orange PI PC2의 카메라인 GC2035는 YUV420코덱만 지원하기 때문에, mjpg-streamer에서 사용 할 수 없습니다.

제가 작업한 GC2035의 YUV420코덱을 지원하는 so 파일을 공개 합니다.
Orange PI PC2의 카메라인 GC2035를 사용해서 mjpg-streamer로 스트리밍 하시려면 첨부한 파일을 사용하세요.

LD_LIBRARY_PATH 경로 추가

$ echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/mjpg-streamer" | sudo tee -a /etc/profile

mjpg-streamer 실행

$ ./mjpg_streamer -i "./input_gc2035.so -y -n" -o "./output_http.so -w ./www"
MJPG Streamer Version: svn rev: 3:172M
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 5
 i: Format............: YUV420
 i: JPEG Quality......: 80
 o: www-folder-path...: ./www/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled

서비스등록

$ sudo vi /etc/init.d/mjpg_streamer

mjpg_streamer 파일 내용

#! /bin/bash
# /etc/init.d/mjpg_streamer.sh
# v0.2 phillips321.co.uk
### BEGIN INIT INFO
# Provides:         mjpg_streamer.sh
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Streams /dev/video0 to http://IP/?action=stream
### END INIT INFO

#
export width=640
export height=480
export fps=24
export SHUTDOWN_WAIT=2
export QUALITY=75

if [ -n "$2" ]; then
  width=$2 
fi

if [ -n "$3" ]; then
  height=$3
fi

if [ -n "$4" ]; then
  fps=$4
fi

export LD_MJPG_STREAMER=/usr/local/lib

f_message(){
        echo "[+] $1"
}

mjpg_streamer_pid() {
  echo `ps aux | grep input_gc2035 | grep -v grep | awk '{ print $2 }'`
}

start() {
  pid=$(mjpg_streamer_pid)
  if [ -n "$pid" ] 
  then
    echo "mjpg_streamer is already running (pid: $pid)"
  else
    # Start mjpg_streamer
                f_message "Starting mjpg_streamer"
                mjpg_streamer -b -i "$LD_MJPG_STREAMER/input_gc2035.so -r "$width"x"$height" -f $fps -q $QUALITY -y" -o "$LD_MJPG_STREAMER/output_http.so -p 8080 -w /usr/local/www"
                sleep 2
                f_message "mjpg_streamer started"
  fi

  return 0
}

stop() {
  pid=$(mjpg_streamer_pid)
  if [ -n "$pid" ]
  then
    f_message "Stopping mjpg_streamer... (pid: $pid)"
    kill -9 $pid

    let kwait=$SHUTDOWN_WAIT
    let count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n -e "\nwaiting for processes to exit\n";
      sleep 1
      let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
      echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\n"
      kill -9 $pid
    fi
  else
    echo "mjpg_streamer is not running"
  fi
 
  return 0
}

# Carry out specific functions when asked to by the system
case "$1" in
        start)
                 start
                 ;;
        stop)
                 stop
                 ;;
        restart)
                 stop
                 sleep 2
                 start
                 ;;
        resolution)
                resolution=`ps axu | grep input_gc2035 | grep -v grep | awk '{ print $16 }'`
                currfps=`ps axu | grep input_gc2035 | grep -v grep | awk '{ print $18 }'`
                if [ -n "$resolution" ];
                then
                        echo "${resolution}"x"$currfps"
                else
                        echo "0x0x0"
                fi
                ;;
        status)
                pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk '{print $1}' | head -n 1`
                if [ -n "$pid" ];
                then
                        f_message "mjpg_streamer is running with pid ${pid}"
                        f_message "mjpg_streamer was started with the following command line"
                        cat /proc/${pid}/cmdline ; echo ""
                else
                        f_message "Could not find mjpg_streamer running"
                fi
                ;;
        *)
                f_message "Usage: $0 {start|stop|status|restart}"
                exit 1
                ;;
esac
exit 0

등록

$ sudo chmod u+x /etc/init.d/mjpg_streamer
$ sudo update-rc.d mjpg_streamer defaults

서비스 실행 및 실행 확인

$ sudo service mjpg_streamer start
$ sudo service mjpg_streamer status
● mjpg_streamer.service - LSB: mjpg_streamer for webcam
   Loaded: loaded (/etc/init.d/mjpg_streamer; bad; vendor preset: enabled)
   Active: active (running) since Wed 2017-03-15 05:05:09 UTC; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8045 ExecStop=/etc/init.d/mjpg_streamer stop (code=exited, status=0/SUCCESS)
  Process: 8113 ExecStart=/etc/init.d/mjpg_streamer start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mjpg_streamer.service
           └─8122 mjpg_streamer -b -i /usr/local/lib/input_gc2035.so -r 640x480 -f 24 -q 75 -y -o /usr/local/lib/output_htt
 
Mar 15 05:05:07 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: Format............: YUV420
Mar 15 05:05:07 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: JPEG Quality......: 75
Mar 15 05:05:08 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: www-folder-path...: /usr/local/www/
Mar 15 05:05:08 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: HTTP TCP port.....: 8080
Mar 15 05:05:08 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: username:password.: disabled
Mar 15 05:05:08 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: commands..........: enabled
Mar 15 05:05:08 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: starting input plugin /usr/local/lib/input_gc2035.so
Mar 15 05:05:08 Orangepi mjpg_streamer[8122]: MJPG-streamer [8122]: starting output plugin: /usr/local/lib/output_http.so (
Mar 15 05:05:09 Orangepi mjpg_streamer[8113]: [+] mjpg_streamer started
Mar 15 05:05:09 Orangepi systemd[1]: Started LSB: mjpg_streamer for webcam.

실행


저작자 표시
신고

Orange PI PC2 Camera(GC2035), motion

OS/Orange PI 2017.03.14 22:43 Posted by 파란크리스마스

Orange PI PC2 Camera(GC2035), motion

출처 : How to Use Orange Pi Camera in Linux (with Motion)

Camera 모듈 설치

$ sudo vi /etc/modules

내용 추가

gc2035
vfe_v4l2

Camera 설치 확인

$ dmesg | grep gc2035
[   11.157004] [VFE]Find sensor name is "gc2035", i2c address is 78, type is "YUV" !
[   11.157006] [VFE]Sub device register "gc2035" i2c_addr = 0x78 start!
[   11.701914] [VFE]Sub device register "gc2035" is OK!
$ ls /dev/video*
/dev/video0

Camera 정보

$ modinfo gc2035
filename:       /lib/modules/3.10.65/kernel/drivers/media/platform/sunxi-vfe/device/gc2035.ko
license:        GPL
description:    A low-level driver for GalaxyCore gc2035 sensors
author:         raymonxiu
srcversion:     3B1ED5B0A55C98A6E316274
alias:          i2c:gc2035
depends:        vfe_io
intree:         Y
vermagic:       3.10.65 SMP preempt mod_unload modversions aarch64

motion

출처 : How to Use Orange Pi Camera in Linux (with Motion)

$ sudo apt-get install motion
$ sudo motion
[4743584] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[4743584] [NTC] [ALL] motion_startup: Motion 3.2.12+git20140228 Started with SDL support
[4743584] [NTC] [ALL] motion_startup: Logging to file (/var/log/motion/motion.log)

motion deamon 실행 수정

$ sudo vi /etc/default/motion

내용 수정

# set to 'yes' to enable the motion daemon
start_motion_daemon=no
저작자 표시
신고

Orange Pi PC 2

OS/Orange PI 2017.02.17 22:28 Posted by 파란크리스마스

Orange pi 업그레이드

$ sudo apt-get update && apt-get upgrade
$ sudo shutdown -r now

SD 용량 확인(확장전)

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/mmcblk0p2   3536592 3448920         0 100% /
devtmpfs          492596       0    492596   0% /dev
tmpfs             501596       4    501592   1% /dev/shm
tmpfs             501596   13540    488056   3% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             501596       0    501596   0% /sys/fs/cgroup
/dev/mmcblk0p1     51082   13062     38020  26% /boot
tmpfs             100320       4    100316   1% /run/user/0
tmpfs             100320       0    100320   0% /run/user/1002

파티션 늘리기

출처 : Orange PI resize SD-card root partition on Debian
Partitioning with fdisk

root@Orangepi:~# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000ebed2

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       40960   143359   102400   50M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      143360 31116287 30972928 14.8G 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2048-31116287, default 2048): 143360
Last sector, +sectors or +size{K,M,G,T,P} (143360-31116287, default 31116287): 

Created a new partition 2 of type 'Linux' and of size 14.8 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

d - to delete partition
2 - second partition
n - create partition
p - primary partition type
2 - partition number
143360 - Same start as current 2th partition
enter - Default is last block
w - write partition table

리눅스 용량 확장

# resize2fs /dev/mmcblk0p2
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3871616 (4k) blocks long.

리눅스 용량 확인

# df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/mmcblk0p2  15213236 3434452  11137696  24% /
devtmpfs          492596       0    492596   0% /dev
tmpfs             501596       0    501596   0% /dev/shm
tmpfs             501596    7092    494504   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             501596       0    501596   0% /sys/fs/cgroup
/dev/mmcblk0p1     51082   13062     38020  26% /boot
tmpfs             100320       0    100320   0% /run/user/1002.

Using SSH

출처 : Login to the Orange Pi

사용자추가

$ sudo groupadd pi        
$ sudo useradd -g pi pi -m -s /bin/bash
$ sudo passwd pi   
Enter new UNIX password: [raspberry]
Retype new UNIX password: [raspberry] 
passwd: password updated successfully

sudo 권한 부여

# vi /etc/sudoers

내용 추가

pi      ALL=(ALL:ALL) ALL

Orange pi 정보 조회

# uname -a        
Linux Orangepi 3.10.65 #55 SMP PREEMPT Fri Nov 18 16:17:28 CST 2016 aarch64 aarch64 aarch64 GNU/Linux
# nmcli device
DEVICE   TYPE      STATE      CONNECTION 
eth0     ethernet  unmanaged  --         
gretap0  gretap    unmanaged  --         
ifb0     ifb       unmanaged  --         
ifb1     ifb       unmanaged  --         
gre0     iptunnel  unmanaged  --         
sit0     iptunnel  unmanaged  --         
tunl0    iptunnel  unmanaged  --         
lo       loopback  unmanaged  --         




이하 작성중...





USB Wifi

출처 : OrangePi PC 2上使用USB WIFI

$ git clone https://github.com/orangepi-xunlong/OrangePi_H5SDK.git
$ cd OrangePi_H5SDK
$ cp kernel/arch/arm64/configs/OrangePiH5_PC2_linux_defconfig kernel/.config

내용추가

# CONFIG_MAC80211 is not set
CONFIG_MAC80211=y
CONFIG_RTLWIFI=m
CONFIG_RTL8192CU=m

빌드

$ sudo ./build.sh

Orange pi 업그레이드

pi@Orangepi:~$ cd /usr/src/
pi@Orangepi:/usr/src$ sudo git clone https://github.com/jwrdegoede/rtl8189ES_linux/
[sudo] password for pi: 
Cloning into 'rtl8189ES_linux'...
remote: Counting objects: 818, done.
remote: Total 818 (delta 0), reused 0 (delta 0), pack-reused 818
Receiving objects: 100% (818/818), 2.75 MiB | 780.00 KiB/s, done.
Resolving deltas: 100% (437/437), done.
Checking connectivity... done.
pi@Orangepi:/usr/src$ cd rtl8189ES_linux
pi@Orangepi:/usr/src/rtl8189ES_linux$ git checkout 080f2aaf6bc8e08eeb3b51f0b8c377eae1ea7ed7
fatal: Unable to create '/usr/src/rtl8189ES_linux/.git/index.lock': Permission denied
pi@Orangepi:/usr/src/rtl8189ES_linux$

Orange pi - Wifi 드라이버 설치

출처 : How to properly compile device drivers for OrangePi?
Armbian missibg headers
pvaret/rtl8192cu-fixes
Orange PI PC Wireless Module (8192cu)
apt-get --reinstall install linux-headers-`uname -r` fails


$ cd /usr/src
$ sudo git clone https://github.com/pvaret/rtl8192cu-fixes
$ sudo make ARCH=armv7l CROSS_COMPILE= -C /lib/modules/3.10.65/build M=/usr/src/rtl8192cu-fixes modules
make: *** /lib/modules/3.10.65/build: No such file or directory.  Stop.


$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install gcc build-essential
$ sudo apt-get install subversion
$ cd /usr/src
$ sudo svn checkout https://github.com/loboris/OrangePI-Kernel.git/trunk/linux-3.4
$ zcat /proc/config.gz > .config
$ make oldconfig





$ sudo apt-get install git linux-headers-generic build-essential dkms


Orange pi - Wifi 드라이버 설치

출처 : Install rtl8188etv/rtl8188eu driver on Orange-Pi
rebuild rtl8189es from GIT for OPI+
loboris/OrangePI-Kernel

$ sudo mkdir /usr/src/linux-kernel-$(uname -r)
$ cd /usr/src/linux-kernel-$(uname -r)
$ sudo git clone https://github.com/silentcreek/bananapi-kernel --depth 1


-

-

Armbian

출처 : Orange Pi – armbian

# apt-get update
# apt-get upgrade
# source /etc/armbian-release
# dpkg -r linux-u-boot-bananapi-${BRANCH} linux-$(lsb_release -cs)-root-${BRANCH}-bananapi
# apt-get -y install linux-u-boot-orangepi-${BRANCH} linux-$(lsb_release -cs)-root-${BRANCH}-orangepi
# ln -fs bin/orangepi.bin /boot/script.bin
# echo orangepi > /etc/hostname
# reboot

Kernel – armbian

출처 : Kernel – armbian

# echo "deb http://apt.armbian.com $(lsb_release -cs) main utils $(lsb_release -cs)-desktop" > /etc/apt/sources.list.d/armbian.list
# apt-key adv --keyserver keys.gnupg.net --recv-keys 0x93D6889F9F0E78D5
# apt-get update

Armbian build tools (igorpecovnik/lib)

출처 : Armbian build tools (igorpecovnik/lib)
Docs » Developer Guide » Building Armbian
Orange Pi PC - Armbian build

# apt-get -y install git
# git clone https://github.com/igorpecovnik/lib --depth 1
# cp lib/compile.sh .
# ./compile.sh


Orange Pi One Board Quick Start Guide with Armbian Debian based Linux Distribution


Orange Pi Camera

출처 : How to Use Orange Pi Camera in Linux (with Motion)

$ lsmod
Module                  Size  Used by
sunxi_ir_rx             8607  0
sunxi_keyboard          6962  0
ss                     34925  0
vfe_v4l2              779470  0
gc2035                 19147  0
vfe_io                 39108  2 vfe_v4l2,gc2035
videobuf2_dma_contig     9982  1 vfe_v4l2
videobuf2_memops        2691  1 videobuf2_dma_contig
videobuf2_core         31877  1 vfe_v4l2

$ dmesg
[   11.016560] [VFE]cci probe end cci_sel = 0!
[   11.022389] systemd[1]: Mounted Debug File System.
[   11.027676] [VFE]cci_init end
[   11.057297] systemd[1]: Started Remount Root and Kernel File Systems.
[   11.116467] systemd[1]: Started Create list of required static device nodes for the current kernel.
[   11.153733] systemd[1]: Started Nameserver information manager.
[   11.211515] systemd[1]: Reached target Network (Pre).
[   11.242083] systemd[1]: Starting Create Static Device Nodes in /dev...
[   11.283933] [VFE]Welcome to Video Front End driver
[   11.289701] [VFE]csi0 probe end!
[   11.293761] [VFE]csi_init end
[   11.297958] [ISP] isp platform_id = 3!
[   11.301463] systemd[1]: Starting udev Coldplug all Devices...
[   11.308437] [VFE]isp0 probe end!
[   11.312839] [VFE]sunxi_isp_platform_register end
[   11.322221] [VFE]mipi_init end
[   11.327704] [VFE]flash_init end
[   11.333422] [VFE]pdev->id = 0
[   11.336709] [VFE]dev->cci_sel = 0
[   11.343181] systemd[1]: Starting Load/Save Random Seed...
[   11.349636] [VFE]dev->csi_sel = 0
[   11.355996] [VFE]dev->mipi_sel = 0
[   11.360828] [VFE]dev->isp_sel = 0
[   11.364549] [VFE_WARN]fetch csi0_dev0_twi_id from device_tree failed
[   11.371634] [VFE_WARN]fetch csi0_dev0_iovdd from device_tree failed
[   11.378606] [VFE_WARN]fetch csi0_dev0_avdd from device_tree failed
[   11.379874] systemd[1]: Started Set console keymap.
[   11.391171] [VFE_WARN]fetch csi0_dev0_dvdd from device_tree failed
[   11.399505] [VFE_WARN]fetch csi0_dev0_afvdd from device_tree failed
[   11.409014] [VFE_WARN]fetch csi0_dev0_flash_en from device_tree failed
[   11.417687] systemd[1]: Started Load/Save Random Seed.
[   11.423755] [VFE_WARN]fetch csi0_dev0_flash_mode from device_tree failed
[   11.432635] [VFE_WARN]fetch csi0_dev0_flvdd from device_tree failed
[   11.442193] [VFE_WARN]fetch csi0_dev0_flvdd_vol from device_tree failed
[   11.449587] [VFE_WARN]fetch csi0_dev0_af_pwdn from device_tree failed
[   11.457381] [VFE]vfe_init end
[   11.465440] [VFE]probe_work_handle start!
[   11.469683] systemd[1]: Started Load Kernel Modules.
[   11.478053] [VFE]vfe_runtime_resume
[   11.494262] [VFE]..........................vfe clk open!.......................
[   11.502562] [VFE]v4l2 subdev register input_num = 0
[   11.508032] [VFE]vfe sensor detect start! input_num = 0
[   11.509449] systemd[1]: Started Create Static Device Nodes in /dev.
[   11.520743] [VFE]Find sensor name is "gc2035", i2c address is 78, type is "YUV" !
[   11.528982] [VFE]Sub device register "gc2035" i2c_addr = 0x78 start!
[   11.536002] [VFE]v4l2_device_register_subdev return 0
[   11.541547] [VFE]registered sensor subdev is OK!
[   11.548166] [VFE]Check sensor!
[   11.566077] [VFE]mclk on
[   11.575928] systemd[1]: Started Journal Service.
[   11.623105] [VFE CCI_0 ERR] Status error at addr_8bit = 78, wr_flag = 1, val = 3efa1cf0
[   11.632196] [VFE CCI_0 ERR] Status error at addr_8bit = 78, wr_flag = 1, val = 3efa00f0
[   11.642227] [VFE CCI_0 ERR] Status error at addr_8bit = 78, wr_flag = 1, val = 3efa00f0
[   11.653632] gc2035 sensor read retry=2
[   11.659085] [CSI_ERR][GC2035]sensor_read err at sensor_detect!
[   11.665513] [CSI_ERR][GC2035]chip found is not an target chip.
[   11.713421] [VFE]mclk off
[   11.740054] [VFE]vfe sensor subdev unregister!
[   11.745042] [VFE]Sub device register "gc2035" failed!
[   11.750592] [VFE_ERR]vfe sensor register check error at input_num = 0
[   11.757685] [VFE]V4L2 device registered as (null)
[   11.762915] [VFE]vfe_runtime_suspend
[   11.766841] [VFE]..........................vfe clk close!.......................
[   11.772987] [VFE]probe_work_handle end!


저작자 표시
신고


 

티스토리 툴바