티스토리 뷰

OS/Raspberry Pi

RaspberryPi - Serial 통신

파란크리스마스 2015. 10. 7. 13:55
728x90

출처 : Serial Communication in Java with Raspberry Pi and RXTX
HowTo: Serial connection to Raspberry Pi (Java, RXTX, UART)
How to Use RXTX on Raspberry Pi or BeagleBone
Ryanteck Raspberry Pi Serial Debug Clip review
Raspberry Pi and the Serial Port
Raspberry Pi UART serial wont work
Using the UART
Raspberry Pi Serial Communication: What, Why, and a Touch of How
RPi Serial Connection


핀맵

적색 - 5V
백색 - TXD
녹색 - RXD
흑색 - GND

bluetooth 장착 확인

$ lsusb | grep -i bluetooth
Bus 001 Device 006: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

서비스 설치

$ sudo apt-get install --no-install-recommends bluetooth

서비스 실행 확인

$ sudo service bluetooth status
bluetooth is running.

-

블루투스 serial 부팅

출처 : A cheap Bluetooth serial port for your Raspberry Pi

기본적으로 라즈베리 파이는 직렬 포트로 부팅 할 때 부팅 메시지를 기록하고. 또한에 로그인 콘솔을 시작합니다. 

라즈베리파이는 직렬 포트로 사용하는 기본 전송 속도는 115200 BPS 이지만 블루투스 모듈은 공장에서 9600 BPS로 되어 라즈베리파이의 전송속도를 9600 BPS로 설정해야 됩니다.

RPi의 Serial port의 기본 전송 속도 확인 (/boot/cmdline.txt, /etc/inittab)

$ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait
$ cat /etc/inittab

.. 생략 ...

#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

RPi의 Serial port의 기본 전송 속도 변경 (/boot/cmdline.txt)

$ cd /boot
$ sudo cp cmdline.txt cmdline.bak
$ sudo vi /boot/cmdline.txt 

dwc_otg.lpm_enable=0 console=ttyAMA0,9600 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait

Kernel Debugger Boot (커널 디버깅 할때만 하세요)

dwc_otg.lpm_enable=0 console=ttyAMA0,9600 kgdboc=ttyAMA0,9600 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

RPi의 Serial port의 기본 전송 속도 변경 (/boot/inittab)

$ sudo vi /etc/inittab 

#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
T0:23:respawn:/sbin/getty -L ttyAMA0 9600 vt100

BlueCove 컴파일 하기

bluecove-gpl-2.1.0.jar

출처 : Bluecove programming problem

BlueCove 컴파일 관련 패키지 설치

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get autoremove
$ sudo apt-get install bluetooth bluez-utils blueman
$ hcitool dev
Devices:
        hci0    00:1A:7D:DA:71:10

BlueZ 라이브러리 설치 - 컴파일시 필요

$ sudo apt-get install libbluetooth-dev

ant 설치

$ sudo apt-get install ant

BlueCove ant 빌드

$ ant all
Buildfile: /home/pi/bluecove-gpl-2.1.0/build.xml

clean:
   [delete] Deleting directory /home/pi/bluecove-gpl-2.1.0/target

init-native:
    [mkdir] Created dir: /home/pi/bluecove-gpl-2.1.0/target/classes
    [mkdir] Created dir: /home/pi/bluecove-gpl-2.1.0/target/native
     [echo] java.home /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre

verify-java-home:

verify-cruisecontrol:

init:

verify-bluecove-main-exists:

compile:
     [echo] compiling on java 1.8.0
    [javac] /home/pi/bluecove-gpl-2.1.0/build.xml:87: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 3 source files to /home/pi/bluecove-gpl-2.1.0/target/classes
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.3
    [javac] warning: [options] source value 1.3 is obsolete and will be removed in a future release
    [javac] warning: [options] target value 1.1 is obsolete and will be removed in a future release
    [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
    [javac] 4 warnings

jni-headers:
     [echo] create JNI headers using java.home /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre

compile-native-lib:
     [echo] compiling  .c -> .o
    [apply] /home/pi/bluecove-gpl-2.1.0/src/main/c/BlueCoveBlueZ_SDPServer.c: In function 쁞luecove_sdp_extract_pdu

                      [apply] /home/pi/bluecove-gpl-2.1.0/src/main/c/BlueCoveBlueZ_SDPServer.c:94:47: warning: assignment from incompatible pointer type [enabled by default]
     [echo] linking    .o -> libbluecove_arm.so
     [echo] ldd libbluecove_arm.so
     [exec]     /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0x76f1d000)
     [exec]     libbluetooth.so.3 => /usr/lib/arm-linux-gnueabihf/libbluetooth.so.3 (0x76eef000)
     [exec]     libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x76dbf000)
     [exec]     /lib/ld-linux-armhf.so.3 (0x76f40000)
     [exec] 
     [exec]     Version information:
     [exec]     /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so:
     [exec]             libc.so.6 (GLIBC_2.4) => /lib/arm-linux-gnueabihf/libc.so.6
     [exec]     /usr/lib/arm-linux-gnueabihf/libbluetooth.so.3:
     [exec]             ld-linux-armhf.so.3 (GLIBC_2.4) => /lib/ld-linux-armhf.so.3
     [exec]             libc.so.6 (GLIBC_2.7) => /lib/arm-linux-gnueabihf/libc.so.6
     [exec]             libc.so.6 (GLIBC_2.4) => /lib/arm-linux-gnueabihf/libc.so.6
     [exec]     /lib/arm-linux-gnueabihf/libc.so.6:
     [exec]             ld-linux-armhf.so.3 (GLIBC_2.4) => /lib/ld-linux-armhf.so.3
     [exec]             ld-linux-armhf.so.3 (GLIBC_PRIVATE) => /lib/ld-linux-armhf.so.3
     [copy] Copying 1 file to /home/pi/bluecove-gpl-2.1.0/src/main/resources
     [copy] Copying 1 file to /home/pi/bluecove-gpl-2.1.0/target/classes

native-lib:

jar:
      [jar] Building jar: /home/pi/bluecove-gpl-2.1.0/target/bluecove-gpl-2.1.0.jar

all:

BUILD SUCCESSFUL
Total time: 31 seconds
pi@raspberrypi:~/bluecove-gpl-2.1.0$ 

Sample 컴파일 및 실행

$ wget http://get.pi4j.com/download/pi4j-1.1-SNAPSHOT.zip
$ unzip pi4j-1.1-SNAPSHOT.zip
$ cp /home/pi/bluecove-gpl-2.1.0/target/bluecove-gpl-2.1.0.jar ~/pi4j-1.1-SNAPSHOT/lib
$ javac -cp lib/pi4j-core.jar:lib/bluecove-gpl-2.1.0.jar:lib/bluecove-2.1.0.jar SimpleSPPServer.java
$ sudo java -cp .:lib/pi4j-core.jar:lib/bluecove-gpl-2.1.0.jar:lib/bluecove-2.1.0.jar SimpleSPPServer
BlueCove version 2.1.0 on bluez
Address: 001A7DDA7110
Name: raspberrypi-0

Server Started. Waiting for clients to connect...


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