Presentation is loading. Please wait.

Presentation is loading. Please wait.

임베디드 프로그래밍 Lecture #03 2018. 10. 02.

Similar presentations


Presentation on theme: "임베디드 프로그래밍 Lecture #03 2018. 10. 02."— Presentation transcript:

1 임베디드 프로그래밍 Lecture #03

2 목 차 라즈베리파이의 장치 제어 디지털 출력 및 입력 테스트 디지털 입력 이벤트 처리 테스트

3 라즈베리파이의 장치 제어 (1) IoT 단말 장치의 구성 Sensors Communication Device
Controller Sensors Actuator Communication Device

4 라즈베리파이의 장치 제어 (2) 라즈베리파이의 장치 제어 Communication Interface
GPIO IO Digital Input(DI) 26개의 GPIO Digital Output(DO) Ethernet Analog Input(DI) WiFi PWM 지원 Analog Output(DO) Serial Comm. Bluetooth 2 채널 지원 SPI Communication Interface I2C UART Device Interface

5 라즈베리파이의 장치 제어 (3) 라즈베리파이의 입출력 핀 구성

6 디지털 출력 및 입력 테스트 (1) 버튼 입력 처리 택 스위치(Tact Switch) 버튼 입력 회로 구성
GPIO Pin GND (2) Pull-up 회로 GPIO Pin Vcc (1) Pull-down 회로 Vcc 10kΩ 10kΩ GND

7 Pull-up resistor  버튼을 누르면 LOW 입력
디지털 출력 및 입력 테스트 (2) Pull-up resistor  버튼을 누르면 LOW 입력 버튼 입력 테스트 회로 LED – gpio 17(11) Led Button – gpio 23(16) Exit Button – gpio 24(18) 동작: Led button 입력에 따라 LED on-off Exit button 입력 시에 프로그램 종료

8 디지털 출력 및 입력 테스트 (3) 버튼 입력 테스트 회로

9 디지털 출력 및 입력 테스트 (4) 버튼 입력 테스트 프로그램 import java.io.IOException;
import jdk.dio.DeviceManager; import jdk.dio.gpio.GPIOPin; public class PushButton { private static final String LED_PIN = "GPIO17"; private static final String LED_BTN = "GPIO23"; private static final String EXIT_BTN = "GPIO24"; private GPIOPin ledPin; private GPIOPin ledBtnPin; private GPIOPin exitBtnPin; public PushButton() { super(); this.ledPin = DeviceManager.open(LED_PIN, GPIOPin.class); this.ledBtnPin = DeviceManager.open(LED_BTN, GPIOPin.class); this.exitBtnPin = DeviceManager.open(EXIT_BTN, GPIOPin.class); System.out.println("Devices successfully opened..."); } public void run() throws IOException { boolean exit = false; boolean led = false; try { while (!exit) { led = ledBtnPin.getValue(); ledPin.setValue(led); System.out.System.out.println("LED: " + (led?"ON":"OFF")); exit = exitBtnPin.getValue(); Thread.sleep(1000); } catch (InterruptedException e) {} System.out.println("Exit..."); close();

10 디지털 출력 및 입력 테스트 (5) 버튼 입력 테스트 프로그램 (계속)
public void close() throws IOException { ledPin.close(); ledBtnPin.close(); exitBtnPin.close(); } public static void public static void main(String[] args) { PushButton pushButton = new PushButton(); pushButton.run();

11 장치타입 정의에 의해 장치의 기본 속성값이 결정
디지털 출력 및 입력 테스트 (6) 버튼 입력 테스트 프로그램 – 장치 레지스트리 dio.properties # RPi P3 header pins 17 = deviceType: gpio.GPIOPin, pinNumber:17, name:GPIO17, mode:4, direction:1, predefined:true 23 = deviceType: gpio.GPIOPin, pinNumber:23, name:GPIO23, mode:2, direction:0, predefined:true 23 = deviceType: gpio.GPIOPin, pinNumber:24, name:GPIO24, mode:2, direction:0, predefined:true gpio.GPIOPin = initValue:0, deviceNumber:0, direction:0, mode:1, trigger:0, predefined:true 장치이름 장치번호 장치타입 정의에 의해 장치의 기본 속성값이 결정

12 디지털 출력 및 입력 테스트 (7) 버튼 입력 테스트 프로그램 – 장치 레지스트리 속성 장치번호 & 장치이름 – 장치 식별자
deviceType – 장치 타입 선언에 의해 장치의 기본 속성값을 정의 pinNumber – GPIO 장치 속성으로 입출력 핀의 GPIO pin 번호 mode – GPIO pin 모드 정의 pull-up input(1), pull-down input(2) push-pull output(4), open-drain output(8) direction – GPIO pin의 입출력 방향 정의 입력전용(0), 출력전용(1), 초기입력 양방향(2), 초기출력 양방향(3) predefined – 장치 속성 정보의 수정 가능 여부 true – 프로그래밍에 의해 속성 정보 수정 가능, false – 수정 불가능 initValue – 출력 GPIO pin의 초기값 trigger - GPIO pin의 입력 모드에서의 트리거 모드 지정 no-trigger(0), rising-edge(1), falling-edge(2), both-edges(3)

13 디지털 출력 및 입력 테스트 (8) 버튼 입력 테스트 프로그램 – 장치 보안 정책 java.policy
build.xml 파일 수정 grant { permission jdk.dio.DeviceMgmtPermission "*:*", "open"; };

14 레지스트리 설정 및 보안 설정 파일 이름은 상황에 맞게 수정
디지털 출력 및 입력 테스트 (9) 버튼 입력 테스트 프로그램 – 실행 환경 설정 프로젝트 속성(properties) 설정 메뉴 선택 2 3 4 레지스트리 설정 및 보안 설정 파일 이름은 상황에 맞게 수정 1

15 디지털 출력 및 입력 테스트 (10) 버튼 입력 테스트 프로그램 – 테스트 원격 실행 원격 디버깅
버튼 입력 처리 동작의 타이밍 지연 문제 버튼 입력에 대한 1초 주기의 폴링(polling)에 의해 야기 디지털 입력에 대한 트리거 이벤트(trigger event) 처리로 해결

16 디지털 출력 및 입력 테스트 (11) 버튼 입력 테스트 프로그램 확장
버튼을 누를 때마다 LED blinking 동작을 토그링(toggling) 구현 고려 사항: 버튼을 누르는 시점을 식별하여 함.  디지털 입력에 대한 edge detection LED Blinking 동작과 버튼 입력 검사 동작이 비동기적으로 실행하여야 함. 해결 방법: 디지털 입력 이벤트 처리 방식을 적용 Device IO 라이브러리는 디지털 입력에 대한 이벤트 처리를 지원

17 디지털 입력 이벤트 처리 (1) 버튼 입력 이벤트 처리 디지털 입력 이벤트 모델
Device I/O 라이브러리는 하드웨어 인터럽트 혹은 소프트웨어 시그널을 처리하 기 위한 이벤트 모델을 제공

18 디지털 입력 이벤트 처리 (2) 버튼 입력 이벤트 처리 프로그램 테스트 회로는 앞의 회로를 동일하게 사용
이벤트 수신 처리 프로그램 – 교재 pp.126~126, 예제 3-9 Project Name: jiot03-buttonevent Main Class Name: jiot3.buttonevent.PushButtonEventEx

19 디지털 입력 이벤트 처리 (3) import java.io.IOException;
import jdk.dio.DeviceManager; import jdk.dio.gpio.GPIOPin; import jdk.dio.gpio.PinEvent; import .jdk.dio.gpio.PinListener; public class PushButtonEventEx implements Runnable { public static final String LED_PIN = "GPIO17"; public static final String BTN1_PIN = "GPIO23"; public static final String BTN2_PIN = "GPIO24"; private GPIOPin ledPin = null; private GPIOPin btn1Pin = null; private GPIOPin btn2Pin = null; private volatile boolean togglingStop = false, exit = false; public PushButtonEventEx() throws IOException { ledPin = DeviceManager.open(LED_PIN, GPIOPin.class); btn1Pin = DeviceManager.open(BTN1_PIN, GPIOPin.class); btn2Pin = DeviceManager.open(BTN2_PIN, GPIOPin.class); btn1Pin.setInputListener(new PinListener() { @Override public void valueChanged(PinEvent pe) { if (!pe.getValue()) { togglingStop = !togglingStop; } }); btn2Pin.setInputListener(new PinListener() { exit = true; System.out.println("LED & Button devices successfully opened...");

20 디지털 입력 이벤트 처리 (4) public void close() throws IOException {
ledPin.close(); btn1Pin.close(); btn2Pin.close(); System.out.println("All devices successfully closed..."); } public void run() { System.out.println("LED Toggling..."); while (!exit) { if (!togglingStop) { try { ledPin.setValue(true); Thread.sleep(500); ledPin.setValue(false); } catch (IOException | InterruptedException ex) { Logger.getLogger(PushButtonEventEx.class.getName()) .log(Level.SEVERE, null, ex); try { close(); } catch (IOException ex) { Logger.getLogger(PushButtonEventEx.class.getName()) .log(Level.SEVERE, null, ex); } public static void main(String[] args) { Thread t = new Thread(new PushButtonEventEx()); t.start();

21 디지털 입력 이벤트 처리 (5) 버튼 입력 이벤트 처리 프로그램 – 장치 레지스트리 # RPi P3 header pins
17 = deviceType: gpio.GPIOPin, pinNumber:17, name:GPIO17, mode:4, direction:1, trigger:0, predefined:true 23 = deviceType: gpio.GPIOPin, pinNumber:23, name:GPIO23, predefined:true 24 = deviceType: gpio.GPIOPin, pinNumber:24, name:GPIO24, predefined:true gpio.GPIOPin = initValue:0, deviceNumber:0, mode:1, direction:0, trigger:3, predefined:true

22 디지털 입력 이벤트 처리 (6) 버튼 입력 이벤트 처리 프로그램 – 장치 보안 정책 grant {
permission jdk.dio.DeviceMgmtPermission "*:*", "open"; };

23 디지털 입력 이벤트 처리 (7) 버튼 입력 이벤트 처리 프로그램 – 실행 환경 설정 앞 예제와 동일하게 설정

24 디지털 입력 이벤트 처리 (8) 버튼 입력 이벤트 처리 프로그램 – 테스트 원격 실행 원격 디버깅

25 디지털 입력 이벤트 처리 확장 (1) 동작 감지 센서(Passive Infrared(PIR) Motion Sensor) 개요
BISS0001 칩을 사용하는 DYP-ME003 PIR Module 작고, 저가이며, 저전력에 사용하기 쉽고, 외부에는 설치할 수 없음 적외선의 레벨을 검출할 수 있는 초전 센서로 구성 초전 센서은 덮고 있는 반구 형태의 커버를 벗기면 중앙에 사각형 크리스탈을 장착한 둥근 금속 적외선을 띈 물체의 움직임을 감지하는 센서 - 태양 빛과 같이 PIR 센서가 감지 가능한 대역의 빛이 있다면 오동작 할 수 있음 주요 특징 Input Voltage: DC V Trigger: High-Yes, Low-No Delay time: 5 S(default) Sentry Angle: < 110 degree Sentry Distance: 3 m(default) - max 7 m

26 디지털 입력 이벤트 처리 확장 (2) 동작 감지 센서(PIR Motion Sensor) 제어 방법 장치 설정
동작 센서는 110도 범위각에서 기본 3m, 최대 7m 범위의 거리에 물체의 움직임 감지 움직임이 감지되면 OUT 핀을 통하여 디지털 신호를 전송 전송된 신호를 디지털 입력핀을 통하여 값을 읽어 확인 장치 설정 1번 가변 저항은 지연 시간(Delay Time)을, 2번 가변 저항은 센싱 거리(Distance)를 조절 각각의 가변 저항을 시계방향으로 돌리면, 지연 시간이 약 5초에 서 300초까지 증가하며, 센싱 거리가 약 3m에서 7m까지 증가

27 디지털 입력 이벤트 처리 확장 (4) 동작 감지 센서 회로 실습 키트 회로

28 디지털 입력 이벤트 처리 확장 (3) 동작 감지 센서 회로 실습 키트 회로 연결
앞의 예제와 동일하며, 추가로 PIR 출력핀을 GPIO25에 연결

29 디지털 입력 이벤트 처리 확장 (4) 동작 감지 센서 확장 프로그램
앞 예제 프로그램에서 동작 감지 센서 입력에 따라 LED blinking 동작 을 토글링하도록 확장 앞 예제 프로그램 수정

30 디지털 입력 이벤트 처리 확장 (5) : public class PushButtonEventEx implements Runnable { public static final String PIR_PIN = "GPIO25"; private GPIOPin pirPin = null; public PushButtonEventEx() throws IOException { pirPin = DeviceManager.open(PIR_PIN, GPIOPin.class); pirPin.setInputListener(new PinListener() { @Override public void valueChanged(PinEvent pe) { togglingStop = !pe.getValue(); } });

31 디지털 입력 이벤트 처리 확장 (6) 동작 감지 센서 확장 프로그램 – 장치 레지스트리 # RPi P3 header pins
17 = deviceType: gpio.GPIOPin, pinNumber:17, name:GPIO17, mode:4, direction:1, trigger:0, predefined:true 23 = deviceType: gpio.GPIOPin, pinNumber:23, name:GPIO23, predefined:true 24 = deviceType: gpio.GPIOPin, pinNumber:24, name:GPIO24, predefined:true 25 = deviceType: gpio.GPIOPin, pinNumber:25, name:GPIO25, predefined:true gpio.GPIOPin = initValue:0, deviceNumber:0, mode:1, direction:0, trigger:3, predefined:true

32 디지털 입력 이벤트 처리 확장 (7) 동작 감지 센서 확장 프로그램 – 실행 환경 설정
앞 예제와 동일하게 설정 동작 감지 센서 확장 프로그램 – 테스트 원격 실행 원격 디버깅


Download ppt "임베디드 프로그래밍 Lecture #03 2018. 10. 02."

Similar presentations


Ads by Google