BPI-M2 Berry - RDP 서버 설치

OS/Banana Pi 2017.09.15 02:10 Posted by 파란크리스마스

출처 : How to use RDP - BananaPro/Pi - LeMaker wiki

RDP 서버 설치

$ sudo apt-get install xrdp
$ sudo apt-get install tightvncserver

RDP 서버 서비스 등록

$ sudo systemctl enable xrdp
xrdp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable xrdp

재부팅

$ sudo shutdown -r now


저작자 표시
신고

BPI-M2 Berry - Python + OpenCV

OS/Banana Pi 2017.09.01 00:27 Posted by 파란크리스마스

출처 : BPI-M2 Ultra use OpenCV and face recognition - Banana Pi BPI-M2 Ultra / BPI-M2 Berry
Compile and Run OpenCV2 on Banana Pi - Banana Pi BPI-M2 - banana pi single board computer official forum SinoVoip BPI team
Raspberry Pi 3에 opencv_contrib 포함하여 OpenCV 3.2 설치 - 멈춤보단 천천히라도
Install guide: Raspberry Pi 3 + Raspbian Jessie + OpenCV 3
OpenCV 설치 - MechaWiki

Use bpi-update command to update kernel image

Update bpi-tools

$ git clone https://github.com/BPI-SINOVOIP/bpi-tools.git
Cloning into 'bpi-tools'...
remote: Counting objects: 89, done.
remote: Total 89 (delta 0), reused 0 (delta 0), pack-reused 89
Unpacking objects: 100% (89/89), done.
Checking connectivity... done.
$ cd bpi-tools
$ sudo ./bpi-tools -u -U
F_UPDATE=yes
F_UPGRADE=yes
BPIFILE=/home/pi/.bpi-tools.lst
Wait for download index file ...
OK!!\n
BPIFILE=/home/pi/.bpi-tools.lst
Wait for download index file ...
OK!!\n
 
bpi files:
bpi-tools       v1.2.0(github)
bpi-bootsel     v1.0.6a
bpi-copy        v1.0.11a
bpi-get         v1.0.3(github)
bpi-migrate     v1.3.2a(github)
bpi-hw          v1.2.8
bpi-update      v1.3.2a
 
download bpi files:
bpi-tools
bpi-tools: v1.2.1(github)
bpi-bootsel
bpi-bootsel: v1.2.1(github)
bpi-copy
bpi-copy: v1.2.1(github)
bpi-get
bpi-get: v1.0.3(github)
bpi-migrate
bpi-migrate: v1.3.5(github)
bpi-hw
bpi-hw: v1.2.8
bpi-update
bpi-update: v1.3.4(github)
 
upgrade bpi files:
/usr/bin/bpi-tools
/usr/bin/bpi-bootsel
/usr/bin/bpi-copy
/usr/bin/bpi-get
/usr/bin/bpi-migrate
/usr/bin/bpi-hw
/usr/bin/bpi-update
 
bpi files:
/usr/bin/bpi-tools      v1.2.1(github)
/usr/bin/bpi-bootsel    v1.2.1(github)
/usr/bin/bpi-copy       v1.2.1(github)
/usr/bin/bpi-get        v1.0.3(github)
/usr/bin/bpi-migrate    v1.3.5(github)
/usr/bin/bpi-hw v1.2.8
/usr/bin/bpi-update     v1.3.4(github)

Check bpi-tools version

$ bpi-tools -v
F_VERSION=yes
 
bpi files:
/usr/bin/bpi-tools      v1.2.1(github)
/usr/bin/bpi-bootsel    v1.2.1(github)
/usr/bin/bpi-copy       v1.2.1(github)
/usr/bin/bpi-get        v1.0.3(github)
/usr/bin/bpi-migrate    v1.3.5(github)
/usr/bin/bpi-hw v1.2.8
/usr/bin/bpi-update     v1.3.4(github)

Use bpi-update to update kerenl

$ mkdir update_file
$ cd update_file
$ sudo bpi-update -c bpi-m2u.conf
CONFFILE=bpi-m2u.conf
Wait for download bpi-m2u.conf ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/others/for-bpi-tools/conf/board/bpi-m2u.conf
OK!!\n
BPIFILE=/home/pi/.bpi-update.lst
Wait for download index file ...
OK!!\n
INFO: /dev/mmcblk0 : SD/eMMC !!
umount device: /dev/mmcblk0
umount /dev/mmcblk0p1
 
######################
update /dev/mmcblk0p1(vfat) with BPI-BOOT-bpi-m2u.tgz
######################
 
 
Wait for download BPI-BOOT-bpi-m2u.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-BOOT/BPI-BOOT-bpi-m2u.tgz
OK!!\n
tar xf BPI-BOOT-bpi-m2u.tgz --keep-directory-symlink -C /mnt
total 28
drwxr-xr-x  4 root root 16384 Aug 24 08:04 .
drwxr-xr-x 22 root root  4096 Sep 13 10:24 ..
drwxr-xr-x  3 root root  4096 Aug 24 08:04 bananapi
drwxr-xr-x  2 root root  4096 Sep 13 04:35 System Volume Information
 
######################
update /dev/mmcblk0p2(root) with bpi-tools.tgz BOOTLOADER-bpi-m2u.tgz 3.10.107-BPI-M2U-Kernel.tgz libvdpau_sunxi.tgz bpi-service.tgz addons.tgz bt.tgz camera.tgz camera-apps.tgz brcm.tgz
######################
 
 
Wait for download bpi-tools.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/bpi-tools.tgz
OK!!\n
tar xf bpi-tools.tgz --keep-directory-symlink -C /
Wait for download BOOTLOADER-bpi-m2u.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/BOOTLOADER-bpi-m2u.tgz
OK!!\n
tar xf BOOTLOADER-bpi-m2u.tgz --keep-directory-symlink -C /
Wait for download 3.10.107-BPI-M2U-Kernel.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/3.10.107-BPI-M2U-Kernel.tgz
OK!!\n
tar xf 3.10.107-BPI-M2U-Kernel.tgz --keep-directory-symlink -C /
Wait for download libvdpau_sunxi.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/libvdpau_sunxi.tgz
OK!!\n
tar xf libvdpau_sunxi.tgz --keep-directory-symlink -C /
Wait for download bpi-service.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/bpi-service.tgz
OK!!\n
tar xf bpi-service.tgz --keep-directory-symlink -C /
Wait for download addons.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/addons.tgz
OK!!\n
tar xf addons.tgz --keep-directory-symlink -C /
Wait for download bt.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/bt.tgz
OK!!\n
tar xf bt.tgz --keep-directory-symlink -C /
Wait for download camera.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/camera.tgz
OK!!\n
tar xf camera.tgz --keep-directory-symlink -C /
Wait for download camera-apps.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/camera-apps.tgz
OK!!\n
tar xf camera-apps.tgz --keep-directory-symlink -C /
Wait for download brcm.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/brcm.tgz
OK!!\n
tar xf brcm.tgz --keep-directory-symlink -C /
total 92
drwxr-xr-x  22 root root  4096 Nov  8  2016 .
drwxr-xr-x  22 root root  4096 Nov  8  2016 ..
drwxr-xr-x   2 root root  4096 Nov 21  2016 bin
drwxr-xr-x   2 root root  4096 Apr 22  2016 boot
drwxr-xr-x  14 root root  4600 Sep 13 10:22 dev
drwxr-xr-x 150 root root 12288 Nov 22  2016 etc
drwxr-xr-x   3 root root  4096 Jul 13  2016 home
drwxr-xr-x  22 root root  4096 Nov 27  2015 lib
drwx------   2 root root 16384 Apr 22  2016 lost+found
drwxr-xr-x   3 root root  4096 Jul 21  2016 media
drwxr-xr-x   2 root root  4096 Apr 21  2016 mnt
drwxr-xr-x   3 root root  4096 Jul 20  2016 opt
dr-xr-xr-x 195 root root     0 Jan  1  1970 proc
drwx------   8 root root  4096 Aug 23 15:50 root
drwxr-xr-x  27 root root   880 Sep 13 10:24 run
drwxr-xr-x   2 root root  4096 Aug  1 10:54 sbin
drwxr-xr-x   2 root root  4096 Apr 21  2016 srv
dr-xr-xr-x  12 root root     0 Sep 13 10:21 sys
drwxr-xr-x   4 root root  4096 Nov 27  2015 system
drwxrwxrwt  10 root root  4096 Sep 13 15:47 tmp
drwxr-xr-x  12 root root  4096 Dec 21  2016 usr
drwxr-xr-x  13 root root  4096 Jul  4  2016 var
INFO: online system: skip umount /

기존에 설치된 OpenCV 제거

OpenCV 설치 여부 확인 - 설치가 안 된경우

$ pkg-config --modversion opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

OpenCV 설치 여부 확인 - 설치 되어 있는 경우

$  pkg-config --modversion opencv
2.4.9.1

설치되어 있는 OpenCV 삭제

$ sudo apt-get purge libopencv* python-opencv
$ sudo apt-get autoremove

OS 업그레이드

$ sudo apt-get update
$ sudo apt-get upgrade

개발 도구와 관련 패키지 설치

$ sudo apt-get install build-essential cmake pkg-config

이미지(JPEG, PNG, TIFF, 기타 등등...) 처리 관련 패키지 설치

$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

비디오 처리 관련 패키지 설치

$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

Video4Linux 패키지 설치

$ sudo apt-get install libv4l-dev v4l-utils

GTK 패키지 설치

$ sudo apt-get install libgtk2.0-dev

OpenCV 관련 패키지 설치

$ sudo apt-get install libatlas-base-dev gfortran libeigen3-dev

Python 설치

$ sudo apt-get install python2.7-dev python3-dev

NumPy 설치

출처 : 예제로 배우는 파이썬 프로그래밍 - numpy 사용하기

$ sudo apt-get install python-numpy python3-numpy

OpenCV 소스 다운로드 및 압축해제

$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip
$ unzip opencv.zip

OpenCV Extra Modules 소스 다운로드 및 압축해제

$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip
$ unzip opencv_contrib.zip

cmake

$ cd ~/opencv-3.2.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_ZLIB=ON \
-D BUILD_PNG=ON \
-D WITH_TBB=OFF \
-D WITH_IPP=OFF \
-D WITH_1394=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D ENABLE_NEON=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
-D WITH_V4L=ON  \
-D WITH_FFMPEG=ON \
-D WITH_XINE=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
../
 
-- 
-- General configuration for OpenCV 3.2.0 =====================================
--   Version control:               unknown
-- 
--   Extra modules:
--     Location (extra):            /home/pi/opencv_contrib-3.2.0/modules
--     Version control (extra):     unknown
-- 
--   Platform:
--     Timestamp:                   2017-09-12T15:12:16Z
--     Host:                        Linux 3.10.107-BPI-M2U-Kernel armv7l
--     CMake:                       3.5.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          /usr/lib/arm-linux-gnueabihf/libtiff.so /usr/lib/arm-linux-gnueabihf/libjasper.so /usr/lib/arm-linux-gnueabihf/libjpeg.so gtk-3 gdk-3 pangocairo-1.0 pango-1.0 atk-1.0 cairo-gobject cairo gdk_pixbuf-2.0 gio-2.0 gobject-2.0 glib-2.0 gthread-2.0 avcodec-ffmpeg avformat-ffmpeg avutil-ffmpeg swscale-ffmpeg dl m pthread rt
--     3rdparty dependencies:       zlib libwebp libpng IlmImf libprotobuf tegra_hal
-- 
--   OpenCV modules:
--     To be built:                 core flann imgproc ml photo reg surface_matching video dnn freetype fuzzy imgcodecs shape videoio highgui objdetect plot superres xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo tracking videostab xfeatures2d ximgproc aruco optflow phase_unwrapping stitching structured_light python2 python3
--     Disabled:                    world contrib_world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java ts viz cnn_3dobj cvv hdf matlab sfm
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 3.x:                    YES (ver 3.18.9)
--     GThread :                    YES (ver 2.48.2)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.8)
--     JPEG:                        /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
--     WEBP:                        build (ver 0.3.1)
--     PNG:                         build (ver 1.6.24)
--     TIFF:                        /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 - 4.0.6)
--     JPEG 2000:                   /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     GDAL:                        NO
--     GDCM:                        NO
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  NO
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 56.60.100)
--       avformat:                  YES (ver 56.40.101)
--       avutil:                    YES (ver 54.31.100)
--       swscale:                   YES (ver 3.1.101)
--       avresample:                NO
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     OpenNI2:                     NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     Aravis SDK:                  NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO
--     gPhoto2:                     NO
-- 
--   Parallel framework:            pthreads
-- 
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use VA:                      NO
--     Use Intel VA-API/OpenCL:     NO
--     Use Lapack:                  NO
--     Use Eigen:                   YES (ver 3.2.92)
--     Use Cuda:                    NO
--     Use OpenCL:                  YES
--     Use OpenVX:                  NO
--     Use custom HAL:              YES (carotene (ver 0.0.1))
-- 
--   OpenCL:                        <Dynamic loading of OpenCL library>
--     Include path:                /home/pi/opencv-3.2.0/3rdparty/include/opencl/1.2
--     Use AMDFFT:                  NO
--     Use AMDBLAS:                 NO
-- 
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.12)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.12)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.5.2)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.5m.so (ver 3.5.2)
--     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python3.5/dist-packages
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Matlab:                        Matlab not found or implicitly disabled
-- 
--   Tests and samples:
--     Tests:                       NO
--     Performance tests:           NO
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/pi/opencv-3.2.0/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/opencv-3.2.0/build

빌드 (BPI-M2 Berry 에는 4 개의 코어가 있으므로 OpenCV를 더 빠르게 컴파일 할 수 있도록 -j4 옵션추가)

$ cat /proc/cpuinfo | grep processor | wc -l
4
$ make -j4

OpenCV 설치

$ sudo make install

/etc/ld.so.conf.d/ 디렉토리에 /usr/local/lib를 포함하는 설정파일이 있는지 확인

$ cat /etc/ld.so.conf.d/*
#/opt/vc/lib
/usr/lib/mali
## Multiarch support
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf/mesa-egl
/usr/lib/arm-linux-gnueabihf/mesa
## libc default configuration
/usr/local/lib
/opt/vc/lib

OpenCV 설치

$ sudo ldconfig

OpenCV 설치 확인 - 1

$ pkg-config --modversion opencv
3.2.0

OpenCV 설치 확인 - 2

$ pkg-config --libs --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_freetype -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_plot -lopencv_dnn -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

용량 확보를 위해서 다운로드 받은 소스 파일 삭제

$ cd ~
$ rm -rf opencv-3.2.0 opencv_contrib-3.2.0

python3에서 OpenCV 버전확인

$ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'

python3에서 얼굴인식 예제 실행 (Camera 인식 실패로 Camera 직접 제어는 포기)

$ python3 /usr/local/share/OpenCV/samples/python/facedetect.py --cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml" /dev/video0
 
 
face detection using haar cascades
 
USAGE:
    facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]
 
Warning: unable to open video source:  /dev/video0
Warning: unable to open video source:  synth
Traceback (most recent call last):
  File "/usr/local/share/OpenCV/samples/python/facedetect.py", line 52, in <module>
    ret, img = cam.read()
AttributeError: 'NoneType' object has no attribute 'read'

python3에서 얼굴인식 예제 작성 (mjpg-streamer에서 Camera 영상을 받아 오도록 수정)

#!/usr/bin/env python

'''
face detection using haar cascades

USAGE:
    facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]
'''

# Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2
import requests

# local modules
# from video import create_capture
from common import clock, draw_str

BYTES_NONE = b'';

def detect(img, cascade):
    rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),
                                     flags=cv2.CASCADE_SCALE_IMAGE)
    if len(rects) == 0:
        return []
    rects[:,2:] += rects[:,:2]
    return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv2.rectangle(img, (x1, y1), (x2, y2), color, 2)

if __name__ == '__main__':
    import sys, getopt
    print(__doc__)

    args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
    try:
        video_src = video_src[0]
    except:
        video_src = 0
    args = dict(args)
    cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
    nested_fn  = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")

    cascade = cv2.CascadeClassifier(cascade_fn)
    nested = cv2.CascadeClassifier(nested_fn)

    #cam = create_capture(video_src, fallback='synth:bg=../data/lena.jpg:noise=0.05')

    while True:
        r = requests.get('http://127.0.0.1:8080/?action=snapshot"', auth=('user', 'password'), stream=True)
        if (r.status_code == 200):
            bytes = BYTES_NONE
            for chunk in r.iter_content(chunk_size=1024):
                bytes += chunk
                a = bytes.find(b'\xff\xd8')
                b = bytes.find(b'\xff\xd9')
                if a != -1 and b != -1:
                    jpg = bytes[a:b + 2]
                    bytes = bytes[b + 2:]

                    # ret, img = cam.read()
                    # ret, \
                    img = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
                    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                    gray = cv2.equalizeHist(gray)

                    t = clock()
                    rects = detect(gray, cascade)
                    vis = img.copy()
                    draw_rects(vis, rects, (0, 255, 0))
                    if not nested.empty():
                        for x1, y1, x2, y2 in rects:
                            roi = gray[y1:y2, x1:x2]
                            vis_roi = vis[y1:y2, x1:x2]
                            subrects = detect(roi.copy(), nested)
                            draw_rects(vis_roi, subrects, (255, 0, 0))
                    dt = clock() - t

                    draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000))
                    cv2.imshow('facedetect', vis)

        if cv2.waitKey(5) == 27:
            break
    cv2.destroyAllWindows()
$ python3 /usr/local/share/OpenCV/samples/python/facedetect.py --cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml" /dev/video0

python3에서 얼굴인식 예제 실행




얼굴인식 예제 컴파일, 실행 (컴파일 실패로 CPP 예제는 포기)

$ cp /usr/local/share/OpenCV/samples/cpp/facedetect.cpp ./
$ g++ -o facedetect facedetect.cpp $(pkg-config --libs --cflags opencv) 
/usr/bin/ld: /tmp/ccWuwUjB.o: undefined reference to symbol 'fopen@@GLIBC_2.4'
//lib/arm-linux-gnueabihf/libc.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

cmake 다른 옵션

$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_ZLIB=ON \
-D BUILD_PNG=ON \
-D WITH_TBB=OFF \
-D WITH_IPP=OFF \
-D WITH_1394=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D ENABLE_NEON=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
-D WITH_V4L=ON  \
-D WITH_FFMPEG=ON \
-D WITH_XINE=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
../


저작자 표시
신고

BPI-M2 Berry mjpg-streamer

OS/Banana Pi 2017.09.01 00:07 Posted by 파란크리스마스

BPI-M2 Berry 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

input_ov5640.so 컴파일 관련 내용 추가

input_ov5640.so 소스는 누락되어 있습니다.(참고용)

$ vi Makefile

Makefile 내용 일부

# define the name of the program
APP_BINARY = mjpg_streamer

# define the names and targets of the plugins
PLUGINS = input_ov5640.so              # bluexmas : 추가
PLUGINS += input_uvc.so

... 생략 ...

# bluexmas : 추가
ifeq ($(USE_LIBV4L2),true)
input_ov5640.so: mjpg_streamer.h utils.h
	make -C plugins/input_ov5640 USE_LIBV4L2=true all
	cp plugins/input_ov5640/input_ov5640.so .
else
input_ov5640.so: mjpg_streamer.h utils.h
	make -C plugins/input_ov5640 all
	cp plugins/input_ov5640/input_ov5640.so .
endif

ifeq ($(USE_LIBV4L2),true)
input_uvc.so: mjpg_streamer.h utils.h

... 생략 ...

# cleanup
clean:
	make -C plugins/input_ov5640 $@           # bluexmas : 추가
	make -C plugins/input_uvc $@

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_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_ov5640.so

input_ov5640.so.tgz

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

제가 작업한 OV5640의 YUV420코덱을 지원하는 so 파일을 공개 합니다.
BPI-M2 Berry의 카메라인 OV5640를 사용해서 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_ov5640.so -y -n" -o "output_http.so -w /usr/local/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...: /usr/local/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
# 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=10
export SHUTDOWN_WAIT=2
export QUALITY=95

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 mjpg_service | 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_ov5640.so -r "$width"x"$height" -f $fps -q $QUALITY -y" -o "$LD_MJPG_STREAMER/output_http.so -p 8080 -w /usr/local/www" mjpg_service
		sleep 2
		f_message "mjpg_streamer started"
  fi

  return 0
}

stop() {
  pid=$(mjpg_streamer_pid)
  if [ -n "$pid" ]
  then
    f_message "Stopping mjpg_streamer..."
    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";
      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 mjpg_streamer | grep -v grep | awk '{ print $16 }'`
                currfps=`ps axu | grep mjpg_streamer | 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 Thu 2017-08-31 20:14:42 CST; 2min 28s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 5108 ExecStart=/etc/init.d/mjpg-streamer start (code=exited, status=0/SUCCESS)
   Memory: 1.0M
      CPU: 1min 18.585s
   CGroup: /system.slice/mjpg-streamer.service
           └─5117 mjpg_streamer -b -i /usr/local/lib/input_ov5640.so -r 640x480 -f 10 -q 95 -y -o /usr/local/lib/output_http.so -p 8080 -w /
 
Aug 31 20:14:40 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: Format............: YUV420
Aug 31 20:14:40 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: JPEG Quality......: 95
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: www-folder-path...: /usr/local/www/
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: HTTP TCP port.....: 8080
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: username:password.: disabled
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: commands..........: enabled
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: starting input plugin /usr/local/lib/input_ov5640.so
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: starting output plugin: /usr/local/lib/output_http.so (ID: 00)
Aug 31 20:14:42 bpi-iot-ros-ai mjpg-streamer[5108]: [+] mjpg_streamer started
Aug 31 20:14:42 bpi-iot-ros-ai systemd[1]: Started LSB: mjpg_streamer for webcam.
lines 1-20/20 (END)

실행

-b 옵션 백드라운드로 실행

$ mjpg_streamer -b -i "input_ov5640.so -r "640"x"480" -f 10 -q 75 -y" -o "output_http.so -p 8080 -w /usr/local/www"
enabling daemon modeforked to background (10942)

motion

출처 : mjpegtoyuv420p patch for Logitech Quickcam Pro

$ svn co http://www.lavrsen.dk/svn/motion/trunk motion
$ cd motion
$ ./configure
$ make


저작자 표시
신고

BPI-M2 Berry CSI camera

OS/Banana Pi 2017.08.31 23:42 Posted by 파란크리스마스

BPI-M2 Berry CSI camera Camera(OV5640)

출처 : BPI-M2+ OV5640 camera linux driver is work fine
BPI-M2+ camera module

Camera 모듈 설치

$ sudo vi /etc/modules

내용 추가

ov5640
vfe_v4l2

Camera 설치 확인

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

Camera 정보

$ modinfo ov5640
filename:       /lib/modules/3.10.107-BPI-M2U-Kernel/kernel/drivers/media/platform/sunxi-vfe/device/ov5640.ko
license:        GPL
description:    A low-level driver for ov5640 sensors
author:         raymonxiu
srcversion:     179C0D2FEBE682C736CFAEB
alias:          i2c:ov5640
depends:        vfe_io
intree:         Y
vermagic:       3.10.107-BPI-M2U-Kernel SMP mod_unload modversions ARMv7 p2v8 

Camera 캡쳐 프로그램 컴파일 및 실행

출처 : https://github.com/avafinger/ov5640

$ git clone https://github.com/avafinger/cap-v4l2
$ cd cap-v4l2
$ sudo ./install_deps.sh
$ ./build_script.sh

캡쳐

$ ./cap 1280 720 4 1 -999 -1 -1
---- cap parameters -----
width: 1280
height: 720
v4l2 buffers: 4
exposure: -999
hflip: -1
vflip: -1
Mode: V4L2_MODE_VIDEO
Driver: "sunxi-vfe"
Card: "sunxi-vfe"
Bus: "sunxi_vfe csi0"
Version: 1.0
Capabilities: 05000001
Input: 0
V4L2 pixel formats:
0: [0x50323234] '422P' (planar YUV 422)
1: [0x32315559] 'YU12' (planar YUV 420)
2: [0x32315659] 'YV12' (planar YVU 420)
3: [0x3631564E] 'NV16' (planar YUV 422 UV combined)
4: [0x3231564E] 'NV12' (planar YUV 420 UV combined)
5: [0x3136564E] 'NV61' (planar YUV 422 VU combined)
6: [0x3132564E] 'NV21' (planar YUV 420 VU combined)
7: [0x32314D48] 'HM12' (MB YUV420)
8: [0x56595559] 'YUYV' (YUV422 YUYV)
9: [0x55595659] 'YVYU' (YUV422 YVYU)
10: [0x59565955] 'UYVY' (YUV422 UYVY)
11: [0x59555956] 'VYUY' (YUV422 VYUY)
12: [0x31384142] 'BA81' (RAW Bayer BGGR 8bit)
13: [0x47524247] 'GBRG' (RAW Bayer GBRG 8bit)
14: [0x47425247] 'GRBG' (RAW Bayer GRBG 8bit)
15: [0x47425247] 'GRBG' (RAW Bayer RGGB 8bit)
16: [0x30314742] 'BG10' (RAW Bayer BGGR 10bit)
17: [0x30314247] 'GB10' (RAW Bayer GBRG 10bit)
18: [0x30314142] 'BA10' (RAW Bayer GRBG 10bit)
19: [0x30314142] 'BA10' (RAW Bayer RGGB 10bit)
20: [0x32314742] 'BG12' (RAW Bayer BGGR 12bit)
21: [0x32314247] 'GB12' (RAW Bayer GBRG 12bit)
22: [0x32314142] 'BA12' (RAW Bayer GRBG 12bit)
23: [0x32314142] 'BA12' (RAW Bayer RGGB 12bit)
V4L2 pixel sizes:
( 2592 x 1936 ) Pixels
( 2048 x 1536 ) Pixels
( 1920 x 1080 ) Pixels
( 1600 x 1200 ) Pixels
( 1280 x 960 ) Pixels
( 1280 x 720 ) Pixels
( 1024 x 768 ) Pixels
( 800 x 600 ) Pixels
( 640 x 480 ) Pixels

Sensor size: 1280x720 pixels
Pixel Format: V4L2_PIX_FMT_YUV420 [0x32315559]
Frame #10 will be saved!
Length: 1382400         Bytesused: 1382400      Address: 0x49528
FPS[0]: 11.87
Length: 1382400         Bytesused: 1382400      Address: 0x49530
FPS[1]: 30.19
Length: 1382400         Bytesused: 1382400      Address: 0x49538
FPS[2]: 30.16
Length: 1382400         Bytesused: 1382400      Address: 0x49540
FPS[3]: 30.78
Length: 1382400         Bytesused: 1382400      Address: 0x49528
FPS[4]: 30.20
Length: 1382400         Bytesused: 1382400      Address: 0x49530
FPS[5]: 30.18
Length: 1382400         Bytesused: 1382400      Address: 0x49538
FPS[6]: 30.09
Length: 1382400         Bytesused: 1382400      Address: 0x49540
FPS[7]: 30.07
Length: 1382400         Bytesused: 1382400      Address: 0x49528
FPS[8]: 29.85
Length: 1382400         Bytesused: 1382400      Address: 0x49530
FPS[9]: 5.85
------- Avg FPS: 30.19 --------
저작자 표시
신고

BPI-M2 Berry

OS/Banana Pi 2017.08.28 23:17 Posted by 파란크리스마스

BPI-M2 Berry

출처 : BPI-M2+
【BPI-M2+】之mjpg-streamer测试和体验- Bananap讨论区- 烽火社区 ...
http://forum.banana-pi.org/c/Banana-pi-BPI-M2

SD 확장

SD 확장전 용량확인

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        7155064 4430272   2344940  66% /
devtmpfs          380080       0    380080   0% /dev
tmpfs             511300     340    510960   1% /dev/shm
tmpfs             511300    7652    503648   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             511300       0    511300   0% /sys/fs/cgroup
tmpfs             102260      24    102236   1% /run/user/1000
/dev/mmcblk0p1    261868    6740    255128   3% /media/pi/BPI-BOOT

SD FDisk

pi@bpi-iot-ros-ai:~$ sudo 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: 0x540302a1

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1      204800   729087   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      729088 15267839 14538752    7G 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): 729088
Last sector, +sectors or +size{K,M,G,T,P} (729088-31116287, default 31116287): 

Created a new partition 2 of type 'Linux' and of size 14.5 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).

pi@bpi-iot-ros-ai:~$ sudo shutdown -r now

SD 확장

$ sudo 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 3798400 (4k) blocks long.

SD 확장 확인

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root       14956880 4432300   9830596  32% /
devtmpfs          380080       0    380080   0% /dev
tmpfs             511300     204    511096   1% /dev/shm
tmpfs             511300    7664    503636   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             511300       0    511300   0% /sys/fs/cgroup
tmpfs             102260      24    102236   1% /run/user/1000
/dev/mmcblk0p1    261868    6740    255128   3% /media/pi/BPI-BOOT

GPIO사용 (BPI-WiringPi)

출처 : Supports BananaPi BPI -M1 / M1Plus / M2 / M2P / M3

기존 설치된 wiringpi 삭제

$ sudo apt-get remove wiringpi
$ sudo apt autoremove

wiringpi 설치

$ git clone https://github.com/BPI-SINOVOIP/BPI-WiringPi2.git
$ cd BPI-WiringPi2/
$ chmod +x ./build
$ sudo ./build

GPIO 확인

$ gpio -v
gpio version: 2.44
Copyright (c) 2012-2017 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty
 
Raspberry Pi Details:
  Type: Banana Pi M2 Ultra[R40], Revision: 01, Memory: 2048MB, Maker: BPI-Sinovoip 
  * Device tree is enabled.
  *--> sun8iw11p1
  * Root or sudo required for GPIO access.
$ gpio readall
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |  53 |   8 |   SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5v      |     |     |
 |  52 |   9 |   SCL.1 | ALT5 | 0 |  5 || 6  |   |      | 0v      |     |     |
 |  35 |   7 | GPIO. 7 | ALT3 | 0 |  7 || 8  | 0 | ALT4 | TxD     | 15  | 274 |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT4 | RxD     | 16  | 275 |
 | 276 |   0 | GPIO. 0 | ALT3 | 0 | 11 || 12 | 0 | ALT3 | GPIO. 1 | 1   | 273 |
 | 277 |   2 | GPIO. 2 | ALT3 | 0 | 13 || 14 |   |      | 0v      |     |     |
 | 249 |   3 | GPIO. 3 | ALT2 | 0 | 15 || 16 | 0 | ALT3 | GPIO. 4 | 4   | 272 |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | ALT2 | GPIO. 5 | 5   | 250 |
 |  64 |  12 |    MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |  65 |  13 |    MISO | ALT4 | 0 | 21 || 22 | 0 | ALT2 | GPIO. 6 | 6   | 251 |
 |  66 |  14 |    SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0     | 10  | 87  |
 |     |     |      0v |      |   | 25 || 26 | 0 | ALT2 | CE1     | 11  | 248 |
 | 257 |  30 |   SDA.0 | ALT3 | 0 | 27 || 28 | 0 | ALT3 | SCL.0   | 31  | 256 |
 | 224 |  21 | GPIO.21 | ALT4 | 0 | 29 || 30 |   |      | 0v      |     |     |
 | 225 |  22 | GPIO.22 | ALT4 | 0 | 31 || 32 | 0 | ALT3 | GPIO.26 | 26  | 116 |
 | 226 |  23 | GPIO.23 | ALT4 | 0 | 33 || 34 |   |      | 0v      |     |     |
 | 227 |  24 | GPIO.24 | ALT4 | 0 | 35 || 36 | 0 | ALT4 | GPIO.27 | 27  | 231 |
 | 228 |  25 | GPIO.25 | ALT4 | 0 | 37 || 38 | 0 | ALT4 | GPIO.28 | 28  | 230 |
 |     |     |      0v |      |   | 39 || 40 | 0 | ALT4 | GPIO.29 | 29  | 229 |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+

detect I2C chips

출처 : i2cdetect(8): detect I2C chips - Linux man page

$ ls /dev/*i2c*
/dev/i2c-0  /dev/i2c-1  /dev/i2c-2  /dev/i2c-4
$ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

pi4j

촐처 : Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART) http://www.pi4j.com
BUILDING AN EXECUTABLE PI4J JAR

$ sudo apt install maven
$ git clone https://github.com/Pi4J/pi4j.git
$ cd pi4j/pi4j-native
$ mvn package

pi4j pwm 오류

촐처 : How to: banana pi BPI-M3 install BPI-WiringPi - Linux - banana pi ...

PWM 관련 오류가 있어 수정해 보려고 했으나 포기

val pwmWrite 0 <= X <= 1024
Or you can set new range by yourself by pwmSetRange(range
저작자 표시
신고

BPI-M2 Berry 외형편

OS/Banana Pi 2017.08.27 02:47 Posted by 파란크리스마스

출처 : BPI-M2 Berry Quad-core Development Board - Banana Pi

BPI-M2 Berry 외형

알리에서 구입한 BPI-M2 Berry 입니다.

포장은 기존 바나나 파이 박스에 BPI-M2 Berry라는 스티커가 붙어 있고,
라즈베리파이의 경우 간단한 매뉴얼과 비닐 포장의 경우 밀봉되지 않아 미개봉 여부를 알 수 없다는 단점이 있었는데,
BPI-M2 Berry는 비닐 포장이 밀봉되어 있고, 매뉴얼은 따로 없습니다.

부품의 배치나 외형은 아래 사진에서 보는것과 같이 라즈베리파이3와 일치합니다.

기존 바나나 파이에는 eMMC라든지 외부 안테나 지원하는데 BPI-M2 Berry에는 빠진것이 아쉽지만,
라즈베리파이에서 지원하지 않는 디버깅용 UART 지원과 SATA가 지원됩니다.

저작자 표시
신고

Banana Pi - BPI-M2+ / i2c 통신, pi4j, PCA9685

OS/Banana Pi 2017.03.12 16:11 Posted by 파란크리스마스

detect I2C chips

출처 : i2cdetect(8): detect I2C chips - Linux man page

$ ls /dev/*i2c*
/dev/i2c-0  /dev/i2c-1
$ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --  

PCA9685 제어

import java.io.IOException;
import java.math.BigDecimal;

import com.pi4j.gpio.extension.pca.PCA9685GpioProvider;
import com.pi4j.gpio.extension.pca.PCA9685Pin;
import com.pi4j.io.gpio.BPIM2PGpioProvider;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinPwmOutput;
import com.pi4j.io.gpio.Pin;
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CFactory;
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException;

public class PCA9685Gpio {
	
	public static final int SERVO_DURATION_MIN = 650;
	public static final int SERVO_DURATION_NEUTRAL = 1500;
	public static final int SERVO_DURATION_MAX = 2100;
	
	private static PCA9685Gpio instance = null;
	
	private PCA9685GpioProvider gpioProvider = null;
	
	// sudo java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar PCA9685Gpio
	
	private PCA9685Gpio() throws IOException, UnsupportedBusNumberException {		
		
		GpioFactory.setDefaultProvider(new BPIM2PGpioProvider());
		
		System.out.println("<--Pi4J--> PCA9685 PWM Example ... started.");
		// This would theoretically lead into a resolution of 5 microseconds per
		// step:
		// 4096 Steps (12 Bit)
		// T = 4096 * 0.000005s = 0.02048s
		// f = 1 / T = 48.828125
		BigDecimal frequency = new BigDecimal("48.828");
		// Correction factor: actualFreq / targetFreq
		// e.g. measured actual frequency is: 51.69 Hz
		// Calculate correction factor: 51.65 / 48.828 = 1.0578
		// --> To measure actual frequency set frequency without correction
		// factor(or set to 1)
		BigDecimal frequencyCorrectionFactor = new BigDecimal("1.0578");
		// Create custom PCA9685 GPIO provider
		I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_0);
		gpioProvider = new PCA9685GpioProvider(bus, 0x40, frequency, frequencyCorrectionFactor);
		// Define outputs in use for this example
		GpioPinPwmOutput[] myOutputs = provisionPwmOutputs(gpioProvider);
		// Reset outputs
		gpioProvider.reset();
	}
	
	public static PCA9685Gpio getInstance() throws IOException, UnsupportedBusNumberException {
		if (instance==null) instance = new PCA9685Gpio();
		return instance;
	}
	
	public void setPwm(Pin pin, int duration) {
		gpioProvider.setPwm(pin, duration);
	}
	
	public void shutdown() {
		gpioProvider.shutdown();
	}
	
	private static GpioPinPwmOutput[] provisionPwmOutputs(final PCA9685GpioProvider gpioProvider) {
		GpioController gpio = GpioFactory.getInstance();
		GpioPinPwmOutput myOutputs[] = { 
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_00, "Pulse 00"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_01, "Pulse 01"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_02, "Pulse 02"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_03, "Pulse 03"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_04, "Pulse 04"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_05, "Pulse 05"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_06, "Pulse 06"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_07, "Pulse 07"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_08, "Pulse 08"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_09, "Pulse 09"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_10, "Always ON"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_11, "Always OFF"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_12, "Servo pulse MIN"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_13, "Servo pulse NEUTRAL"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_14, "Servo pulse MAX"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_15, "not used") };
		return myOutputs;
	}

	public static void main(String[] args) throws Exception {
		
		PCA9685Gpio test = PCA9685Gpio.getInstance();
		
		test.setPwm(PCA9685Pin.PWM_01, SERVO_DURATION_NEUTRAL);
		Thread.sleep(200);
		
		for (int i=SERVO_DURATION_MIN; i<=SERVO_DURATION_MAX; i+=30) {
			test.setPwm(PCA9685Pin.PWM_00, i);
			Thread.sleep(200);
		}
		
		for (int i=SERVO_DURATION_MAX; i>=(int)(SERVO_DURATION_MIN+(SERVO_DURATION_MAX-SERVO_DURATION_MIN)/2); i-=30) {
			test.setPwm(PCA9685Pin.PWM_00, i);
			Thread.sleep(200);
		}
				
		for (int i=SERVO_DURATION_MIN; i<=SERVO_DURATION_MAX; i+=30) {
			test.setPwm(PCA9685Pin.PWM_01, i);
			Thread.sleep(200);
		}
		
		for (int i=SERVO_DURATION_MAX-200; i>=(int)(SERVO_DURATION_MIN+(SERVO_DURATION_MAX-SERVO_DURATION_MIN)/2); i-=30) {
			test.setPwm(PCA9685Pin.PWM_01, i);
			Thread.sleep(200);
		}
		
		test.shutdown();

	}
	
}

실행

$ sudo java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar PCA9685Gpio
platformId = raspberrypi / label = Raspberry Pi
platformId = bananapi / label = BananaPi
platformId = bananapro / label = BananaPro
platformId = odroid / label = Odroid
platformId = BPI_M2P / label = BPI_M2P
piboardRev: Hardware string: Hardware   : sun8i
Hardware:Hardware       : sun8i
piboardRev:  3
piboardId: Revision string: Revision    : 0000
wiringPi: wiringPiSetup called
piboardRev: Hardware string: Hardware   : sun8i
Hardware:Hardware       : sun8i
piboardRev:  3
piboardRev: Hardware string: Hardware   : sun8i
Hardware:Hardware       : sun8i
piboardRev:  3
piboardId: Revision string: Revision    : 0000
wiringPiSetup: wiringPiMode = 0
<--Pi4J--> PCA9685 PWM Example ... started.

실행 결과

저작자 표시
신고

Banana Pi - BPI-M2+ pi4j

OS/Banana Pi 2017.03.12 14:52 Posted by 파란크리스마스

BPI-M2+ pi4j

출처 : The Pi4J Project - Home

현재 pi4j는 BPI-M2+ 지원하지 않아 수정한 jar를 배포합니다.

pi4j-core.jar

GPIO를 이용하여 LED 제어

/*
 * #%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.BPIM2PGpioProvider;
import com.pi4j.io.gpio.BPIM2PPin;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
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 BPIM2PGpioProvider());

        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(BPIM2PPin.GPIO_00, "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
platformId = raspberrypi / label = Raspberry Pi
platformId = bananapi / label = BananaPi
platformId = bananapro / label = BananaPro
platformId = odroid / label = Odroid
platformId = BPI_M2P / label = BPI_M2P
piboardRev: Hardware string: Hardware   : sun8i
Hardware:Hardware       : sun8i
piboardRev:  3
piboardId: Revision string: Revision    : 0000
wiringPi: wiringPiSetup called
piboardRev: Hardware string: Hardware   : sun8i
Hardware:Hardware       : sun8i
piboardRev:  3
piboardRev: Hardware string: Hardware   : sun8i
Hardware:Hardware       : sun8i
piboardRev:  3
piboardId: Revision string: Revision    : 0000
wiringPiSetup: wiringPiMode = 0
<--Pi4J--> GPIO Control Example ... started.
pinMode,2272,pin:1,mode:1
func:sunxi_set_pin_mode pin:1, MODE:1 bank:0 index:1 phyaddr:0x1c20800
read reg val: 0x77222212 offset:4
Out mode ready set val: 0x77222212
Out mode set over reg val: 0x77222212
func:sunxi_digitalWrite pin:1, value:1 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8002,index:1
HIGH val set over reg val: 0x8002
--> GPIO state should be: ON
func:sunxi_digitalWrite pin:1, value:0 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8002,index:1
LOW val set over reg val: 0x8000
--> GPIO state should be: OFF
func:sunxi_digitalRead pin:1,bank:0 index:1 phyaddr:0x1c20810
***** read reg val: 0x0,bank:0,index:1,line:1389
func:sunxi_digitalWrite pin:1, value:1 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8000,index:1
HIGH val set over reg val: 0x8002
--> GPIO state should be: ON
func:sunxi_digitalRead pin:1,bank:0 index:1 phyaddr:0x1c20810
***** read reg val: 0x1,bank:0,index:1,line:1389
func:sunxi_digitalWrite pin:1, value:0 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8002,index:1
LOW val set over reg val: 0x8000
--> GPIO state should be: OFF
--> GPIO state should be: ON for only 1 second
func:sunxi_digitalWrite pin:1, value:1 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8000,index:1
HIGH val set over reg val: 0x8002
func:sunxi_digitalWrite pin:1, value:0 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8002,index:1
LOW val set over reg val: 0x8000
func:sunxi_digitalWrite pin:1, value:0 bank:0 index:1 phyaddr:0x1c20810
befor write reg val: 0x8000,index:1
LOW val set over reg val: 0x8000
Exiting ControlGpioExample

실행 결과

저작자 표시
신고

Banana Pi - BPI-M2+

OS/Banana Pi 2017.02.26 22:23 Posted by 파란크리스마스

Banana PI - BPI-M2+

출처 : BPI-M2+
【BPI-M2+】之mjpg-streamer测试和体验- Bananap讨论区- 烽火社区 ...
http://forum.banana-pi.org/c/Banana-pi-BPI-M2

SD 확장

SD 확장전 용량확인

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        7156088 4680932   2111636  69% /
devtmpfs          380800       0    380800   0% /dev
tmpfs             512036     800    511236   1% /dev/shm
tmpfs             512036   20248    491788   4% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             512036       0    512036   0% /sys/fs/cgroup
/dev/mmcblk0p1    261868  213188     48680  82% /boot
tmpfs             102408      36    102372   1% /run/user/1000

SD FDisk

pi@bpi-iot-ros-ai:~$ sudo 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.7 GiB, 15811477504 bytes, 30881792 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: 0x0006c94a

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *    204800   729087   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      729088 15269887 14540800    7G 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-30881791, default 2048): 729088
Last sector, +sectors or +size{K,M,G,T,P} (729088-30881791, default 30881791): 

Created a new partition 2 of type 'Linux' and of size 14.4 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).

pi@bpi-iot-ros-ai:~$ sudo shutdown -r now

SD 확장

$ sudo 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 3769088 (4k) blocks long.

SD 확장 확인

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root       14839632 4653484   9513188  33% /
devtmpfs          380800       0    380800   0% /dev
tmpfs             512036     316    511720   1% /dev/shm
tmpfs             512036    7456    504580   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             512036       0    512036   0% /sys/fs/cgroup
/dev/mmcblk0p1    261868  213188     48680  82% /boot
tmpfs             102408      28    102380   1% /run/user/1000

How to burn Linux image to eMMC

출처 : How to burn Linux image to eMMC
bpi-copy command

root@bpi-iot-ros-ai:~# uname -a
Linux bpi-iot-ros-ai 3.4.112-sun8i #2 SMP PREEMPT Mon May 30 20:34:33 CST 2016 armv7l armv7l armv7l GNU/Linux
root@bpi-iot-ros-ai:~# fdisk -l
Disk /dev/mmcblk0: 14.7 GiB, 15811477504 bytes, 30881792 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: 0x0006c94a

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *    204800   729087   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      729088 30881791 30152704 14.4G 83 Linux


Disk /dev/mmcblk1: 7.3 GiB, 7818182656 bytes, 15269888 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: 0x00000000


Disk /dev/mmcblk1boot1: 4 MiB, 4194304 bytes, 8192 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


Disk /dev/mmcblk1boot0: 4 MiB, 4194304 bytes, 8192 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

이미지 복원

이미지 복원이 완료되면 SD 메모리를 제거하고 재부팅

$ sudo dd if=2016-07-21-ubuntu-mate-16.04-desktop-armhf-raspberry-pi-bpi-m2p-sd-emmc.img of=/dev/mmcblk1 bs=10MB
781+1 records in
781+1 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 1023.46 s, 7.6 MB/s

eMMC 부팅(SD동시 사용 - 적용실패)

출처 : Banana Pi M2+ with system on emmc, data on sd card - Allwinner H2/H3
Boot from eMMC with blank SD in slot (BPI-M3)

$ cat /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p2  /               ext4   defaults,noatime  0       1
/dev/mmcblk0p1  /boot/          vfat    defaults          0       2
$ lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0boot0 179:16   0    4M  1 disk 
mmcblk0boot1 179:32   0    4M  1 disk 
mmcblk0      179:0    0  7.3G  0 disk 
쒋mmcblk0p1  179:1    0  256M  0 part /boot
붴mmcblk0p2  179:2    0    7G  0 part /
$ cat /boot/boot.cmd
#setenv device mmc
#setenv partition 0:1
setenv bpi bananapi
setenv board bpi-m64
setenv chip a64
setenv service linux
setenv kernel Image
setenv initrd initrd.img
setenv dtb pine64-plus.dtb
 
setenv bootargs "console=ttyS0,115200n8 no_console_suspend earlycon=uart,mmio32,0x01c28000 mac_addr=${ethaddr} board=${board} root=${root} rootwait panic=10 consoleblank=0 enforcing=0 loglevel=2"
 
 
setenv fdt_filename "${bpi}/${board}/${service}/${dtb}"
setenv kernel_filename "${bpi}/${board}/${service}/${kernel}"
setenv initrd_filename "${bpi}/${board}/${service}/${initrd}"
 
run load_dtb load_kernel load_initrd boot_kernel
 
## Recompile with:
## mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
## mkimage -C none -A arm -T script -d boot.cmd boot.scr

generate boot.src

$ sudo mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
Image Name:   
Created:      Sun Feb  26 11:55:34 2017
Image Type:   ARM Linux Script (uncompressed)
Data Size:    805 Bytes = 0.79 kB = 0.00 MB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 797 Bytes = 0.78 kB = 0.00 MB
$ sudo shutdown -r now

GPIO사용 (BPI-WiringPi)

출처 : Supports BananaPi BPI -M1 / M1Plus / M2 / M2P / M3

기존 설치된 wiringpi 삭제

$ sudo apt-get remove wiringpi
$ sudo apt autoremove

wiringpi 설치

$ git clone https://github.com/BPI-SINOVOIP/BPI-WiringPi.git -b BPI_M2P
$ cd BPI-WiringPi
$ chmod +x ./build
$ sudo ./build

GPIO 확인

$ gpio -v
gpio version: 2.26
Copyright (c) 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty
 
Banana Pi Details:
  Type: Model BM, Revision: 1.2, Memory: 1024MB, Maker: BPI 
$ gpio readall
 +-----+-----+---------+------+---+---Pi ---+---+------+---------+-----+-----+
 | CPU | wPi |    Name   | Mode | V | Physical | V | Mode |   Name    | wPi | CPU |
 +-----+-----+-----------+------+---+----++----+---+------+-----------+-----+-----+
 |     |     |      3.3v |      |   |  1 || 2  |   |      | 5v        |     |     |
 |  12 |   8 |     SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5V        |     |     |
 |  11 |   9 |     SCL.1 | ALT5 | 0 |  5 || 6  |   |      | GND       |     |     |
 |   6 |   7 |      PWM1 | ALT3 | 0 |  7 || 8  | 0 | ALT4 | UART3-TX  | 15  | 13  |
 |     |     |       GND |      |   |  9 || 10 | 0 | ALT4 | UART3-RX  | 16  | 14  |
 |   1 |   0 |  UART2-RX | ALT5 | 0 | 11 || 12 | 0 | OUT  | UART3-CTS | 1   | 16  |
 |   0 |   2 |  UART2-TX | ALT5 | 0 | 13 || 14 |   |      | GND       |     |     |
 |   3 |   3 | UART2-CTS | ALT5 | 0 | 15 || 16 | 1 | ALT4 | UART3-RTS | 4   | 15  |
 |     |     |      3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO.PC04 | 5   | 68  |
 |  64 |  12 | SPI0_MOSI | ALT4 | 0 | 19 || 20 |   |      | GND       |     |     |
 |  65 |  13 | SPI0_MISO | ALT4 | 0 | 21 || 22 | 0 | ALT5 | UART2-RTS | 6   | 2   |
 |  66 |  14 |  SPI0_CLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | SPI0-CS   | 10  | 67  |
 |     |     |       GND |      |   | 25 || 26 | 0 | ALT3 | GPIO.PL07 | 11  | 71  |
 |  19 |  30 |     SDA.0 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.0     | 31  | 18  |
 |   7 |  21 | GPIO.PA07 | ALT3 | 0 | 29 || 30 |   |      | GND       |     |     |
 |   8 |  22 | GPIO.PA08 | ALT3 | 0 | 31 || 32 | 0 | ALT3 | GPIO.PL02 | 26  | 354 |
 |   9 |  23 | GPIO.PA09 | ALT3 | 0 | 33 || 34 |   |      | GND       |     |     |
 |  10 |  24 | GPIO.PA10 | ALT3 | 0 | 35 || 36 | 0 | ALT3 | GPIO.PL04 | 27  | 356 |
 |  17 |  25 | SPDIF-OUT | ALT3 | 0 | 37 || 38 | 0 | ALT3 | GPIO.PA21 | 28  | 21  |
 |     |     |       GND |      |   | 39 || 40 | 0 | ALT3 | GPIO.PA20 | 29  | 20  |
 +-----+-----+-----------+------+---+----++----+---+------+-----------+-----+-----+
 | CPU | wPi |    Name   | Mode | V | Physical | V | Mode |   Name    | wPi | CPU |
 +-----+-----+---------+------+---+---Pi ---+---+------+---------+-----+-----+

detect I2C chips

출처 : i2cdetect(8): detect I2C chips - Linux man page

$ ls /dev/*i2c*
/dev/i2c-0  /dev/i2c-1
$ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --  

jdk1.8 설치

출처 : 우분투(Ubuntu) Oracle(Sun) Java JDK 설치 - 사르기스

OpenJDK 제거

$ sudo apt-get purge openjdk*

repository 추가

$ sudo add-apt-repository ppa:webupd8team/java

repository index 업데이트

$ sudo apt-get update

JDK 설치

$ sudo apt-get install oracle-java8-installer

JAVA_HOME 환경변수 추가

$ sudo vi /etc/profile

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

export JAVA_HOME=/usr/lib/jvm/java-8-oracle

pi4j

촐처 : Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART) http://www.pi4j.com
BUILDING AN EXECUTABLE PI4J JAR

$ sudo apt install maven
$ git clone https://github.com/Pi4J/pi4j.git
$ cd pi4j/pi4j-native
$ mvn package

pi4j pwm 오류

촐처 : How to: banana pi BPI-M3 install BPI-WiringPi - Linux - banana pi ...

PWM 관련 오류가 있어 수정해 보려고 했으나 포기

val pwmWrite 0 <= X <= 1024
Or you can set new range by yourself by pwmSetRange(range
저작자 표시
신고

Banana Pi - BPI-M2+ mjpg-streamer

OS/Banana Pi 2017.02.26 04:49 Posted by 파란크리스마스

BPI-M2+ 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_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_ov5640.so

input_ov5640.tar.gz

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

제가 작업한 OV5640의 YUV420코덱을 지원하는 so 파일을 공개 합니다.
BPI-M2+의 카메라인 OV5640를 사용해서 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_ov5640.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=10
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 mjpg_streamer | 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_ov5640.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..."
    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";
      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 mjpg_streamer | grep -v grep | awk '{ print $16 }'`
                currfps=`ps axu | grep mjpg_streamer | 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 Sat 2017-03-11 23:04:13 CST; 15min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4201 ExecStart=/etc/init.d/mjpg_streamer start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mjpg_streamer.service
           └─4015 mjpg_streamer -b -i /usr/local/lib/input_ov5640.so -r 1280x720 -f 24 -q 45 -y -o /usr/local/lib/output_http.so -p 8080 -w /usr/local/www
 
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4201]: [+] Starting mjpg_streamer
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4201]: enabling daemon modeforked to background (4210)
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4210]: MJPG-streamer [4210]: MJPG Streamer Version: svn rev: 3:172M
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4210]: MJPG-streamer [4210]: Using V4L2 device.: /dev/video0
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4210]: MJPG-streamer [4210]: Desired Resolution: 640 x 480
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4210]: MJPG-streamer [4210]: Frames Per Second.: 10
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4210]: MJPG-streamer [4210]: Format............: YUV420
Mar 11 23:04:11 bpi-iot-ros-ai mjpg_streamer[4210]: MJPG-streamer [4210]: JPEG Quality......: 75
Mar 11 23:04:13 bpi-iot-ros-ai mjpg_streamer[4201]: [+] mjpg_streamer started
Mar 11 23:04:13 bpi-iot-ros-ai systemd[1]: Started LSB: mjpg_streamer for webcam.

실행

motion

출처 : mjpegtoyuv420p patch for Logitech Quickcam Pro

$ svn co http://www.lavrsen.dk/svn/motion/trunk motion
$ cd motion
$ ./configure
$ make


저작자 표시
신고

Banana Pi - BPI-M2+ Camera(OV5640)

OS/Banana Pi 2017.02.26 04:27 Posted by 파란크리스마스

BPI-M2+ Camera(OV5640)

출처 : BPI-M2+ OV5640 camera linux driver is work fine
BPI-M2+ camera module

Camera 모듈 설치

$ sudo vi /etc/modules

내용 추가

ov5640
vfe_v4l2

Camera 설치 확인

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

Camera 정보

$ modinfo ov5640
filename:       /lib/modules/3.4.112-sun8i/kernel/drivers/media/video/sunxi-vfe/device/ov5640.ko
license:        GPL
description:    A low-level driver for ov5640 sensors
author:         raymonxiu
alias:          i2c:ov5640
depends:        cci,vfe_subdev
intree:         Y
vermagic:       3.4.112-sun8i SMP preempt mod_unload modversions ARMv7 p2v8 

Camera 캡쳐 프로그램 컴파일 및 실행

출처 : https://github.com/avafinger/ov5640

$ git clone https://github.com/avafinger/cap-v4l2
$ cd cap-v4l2
$ sudo ./install_deps.sh
$ ./build_script.sh
$ ./cap 1280 720 4 1 -999 -1 -1
저작자 표시
신고


 

티스토리 툴바