๐Ÿ’ป My Work/๐Ÿ’ Raspberry Pi

[๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด] GPIO ์ œ์–ดํ•˜๊ธฐ, Python gpiozero

Jaeseo Kim 2022. 12. 30. 23:58

๐Ÿ’ Raspberry Pi 4 ๋ชจ๋ธ ์‚ฌ์šฉ


๊ฐœ๋…


GPIO

General Purpose Input Output, ๋ฒ”์šฉ ์ž…์ถœ๋ ฅ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

 

GPIO ํ•€ ๋ฒˆํ˜ธ

๊ฐ ํ•€ ์ •๋ณด๋Š” ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

pinout

 

 

gpiozero

๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์žฌ๋‹จ์—์„œ ๊ณต์‹์œผ๋กœ ๋ผ์ฆˆ๋น„์•ˆ์— ํฌํ•จ์‹œ์ผœ ๋ฐฐํฌํ•˜๊ณ  ์žˆ๋Š” GPIO์ œ์–ด์šฉ ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค.

์•„๋ž˜ ๊ณต์‹ ๋ฌธ์„œ์—์„œ ์—ฌ๋Ÿฌ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿš€

 

gpiozero — GPIO Zero 1.6.2 Documentation

Pin factories GPIO Zero builds on a number of underlying pin libraries, including RPi.GPIO and pigpio, each with their own benefits. You can select a particular pin library to be used, either for the whole script or per-device, according to your needs. See

gpiozero.readthedocs.io

 

 

 

์‹ค์Šต


๐Ÿ“Œ LED 1์ดˆ๋งˆ๋‹ค ํ‚ค๊ณ  ๋„๊ธฐ

ํŒŒ์ด์ฌ ์ฝ”๋“œ

from gpiozero import LED
from time import sleep # time์œผ๋กœ๋ถ€ํ„ฐ sleep์„ ๊ฐ€์ ธ์˜ค๊ฒ ๋‹ค

led = LED(25) # GPIO25

while True:
        led.on() # led ํ‚ค๊ธฐ
        sleep(1) # delay 1์ดˆ ์‰ผ
        led.off() # led ํฌ๊ธฐ
        sleep(1) # delay 1์ดˆ ์‰ผ

 

์‹คํ–‰ํ•˜๊ธฐ

python <์‹คํ–‰์‹œํ‚ฌ ํŒŒ์ผ๋ช…>

 

 

โœจโœจโœจ