프로젝트형 IoT 서비스 개발 4회차/3. 게이트웨이 디바이스 제어

[Day51] 2022-04-11(월) 라즈베리파이 준비4 - VNC, GPIO 사용 준비 - 김서연 강사님

powerstone 2022. 4. 11. 17:56
728x90

[1] VNC (Virtual Network Computing)

  - 라즈베리파이를 컴퓨터에서 가상으로 사용할 수 있는 환경 제공

  1. VNC 사용 활성화

    - 명령어 ~$ sudo raspi-config

3 Interface Options
I3 VNC
YES

  2. VNC 뷰어 다운 및 설치

https://www.realvnc.com/en/connect/download/viewer/windows/

 

Download VNC Viewer for Windows | VNC® Connect

Control VNC® enabled computers with VNC® Viewer.

www.realvnc.com

  3. 설치된 VNC Viewer 실행

File -> New connection 선택
VNC Server에 라즈베리파이 IP, Name은 마음대로 작성하고 OK
생성한 myhome_raspberrypi 더블 클릭
pi/raspberry 입력하고 OK
접속 완료

  3. VNC 화면 해상도 조절

    - PuTTY 에서 명령어 ~$ sudo raspi-config

2 Display Options
D5 VNC Resolution
원하는 해상도 선택 후 Select 하고 Finish로 설정 화면 나가기

[2] 회로 연결 준비

  1. T-Cobbler 연결

  - 라즈베리파이 보드와 T-Cobbler 연결

  - T-Cobbler의 홈과 케이블의 튀어나온 부분을 잘 보고 꽂기

  2. GPIO (General-Purpose Input/Output)

출처 - https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header
출처 - https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header

  3. Wiringpi 설치 (C언어를 이용해 GPIO 기능 사용)

    1) 다운로드

      - 명령어 : ~ $  wget https://project-downloads.drogon.net/wiringpi-latest.deb

      - .deb 파일 : 데비안 소프트웨어 패키지 파일

    2) 설치

      - 명령어 : ~ $ sudo dpkg -i wiringpi-latest.deb

    3) 핀 정보 출력

      - 명령어 : ~$ gpio readall

 

[3] Python으로 GPIO 사용

  1. 파이참에 GPIO 패키지 설치

    - RPi.GPIO-def 검색하여 설치

RPi.GPIO-def 찾아서 설치

  2. GPIO 기본 사용법

    1) GPIO 핀 번호 모드 설정

      ① BOARD 모드

Physical에 해당되는 핀 번호가 BOARD 모드로 핀을 사용하는 번호

      ② BCM 모드

BCM에 해당되는 핀 번호가 BCM 모드로 핀을 사용하는 번호

  2) 예제

basic_led.py

import RPi.GPIO as GPIO
import time

led_pin = 24
# GPIO 핀을 어떤 방법으로 액세스 할 것인지 모드를 설정
# GPIO.setmode(GPIO.BOARD)    # BOARD 모드
GPIO.setmode(GPIO.BCM)      # BCM 모드

# GPIO 핀이 입력인지 출력인지 설정
GPIO.setup(led_pin, GPIO.OUT)   # 출력으로 설정

# GPIO 핀에 출력하는 작업
GPIO.output(led_pin, GPIO.HIGH)     # 24번 핀으로 HIGH(3.3V) 출력
time.sleep(1)
GPIO.output(led_pin, GPIO.LOW)      # 24번 핀으로 LOW(0V) 출력
GPIO.cleanup()      # GPIO 설정 초기화

basic_led_exam1.py

import RPi.GPIO as GPIO
import time

led_pin = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)

GPIO.output(led_pin, GPIO.HIGH)
GPIO.output(led_pin, GPIO.LOW)

while True:
    GPIO.output(led_pin, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(led_pin, GPIO.LOW)
    time.sleep(1)

basic_led_exam2.py

import RPi.GPIO as GPIO
import time

led_pin = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)

for i in range(10):
    GPIO.output(led_pin, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(led_pin, GPIO.LOW)
    time.sleep(1)

GPIO.cleanup()

 

- 끝 -

728x90