์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[47] 230307 Ch. 5 ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด GPIO ๋ฐ ์ผ์ ํ์ฉํ๊ธฐ: 6. IยฒC(Inter-Integrated Circuit) ํต์ [K-๋์งํธ ํธ๋ ์ด๋ 47์ผ] ๋ณธ๋ฌธ
[47] 230307 Ch. 5 ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด GPIO ๋ฐ ์ผ์ ํ์ฉํ๊ธฐ: 6. IยฒC(Inter-Integrated Circuit) ํต์ [K-๋์งํธ ํธ๋ ์ด๋ 47์ผ]
yjyuwisely 2023. 3. 7. 09:06230307 Tue 47th class
Ch. 5 ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด GPIO ๋ฐ ์ผ์ ํ์ฉํ๊ธฐ
์ง๋: p. 156 ~ (๊ต์ฌ: IoT ์ฌ๋ฌผ์ธํฐ๋ท์ ์ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด 4 ์ ์, ์ ์: ์ต์ฃผํธ , ๊น์ฌ๋ฒ , ์ ๋์ง)
๊ต์ฌ ์ฝ๋ ๊นํ๋ธ: https://github.com/codingspecialist/RaspberryPi4-Book-Example
๊ต์ฌ ์์ค ๋ฐ PPT: http://jspstudy.co.kr/main/main.jsp
์ ์ ์นดํ: https://cafe.naver.com/metacoding
IoT ์ฌ๋ฌผ์ธํฐ๋ท์ ์ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด 4 ์ ์ | ์ต์ฃผํธ - ๊ต๋ณด๋ฌธ๊ณ
IoT ์ฌ๋ฌผ์ธํฐ๋ท์ ์ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด 4 ์ ์ | ใIoT ์ฌ๋ฌผ์ธํฐ๋ท์ ์ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด 4 ์ ์ใ์ ์์ด๋ณด๋ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด๋ฅผ ์ด์ฉํด ๋ค์ํ IoT๋ฅผ ์ง์ ๊ฐ๋ฐํ ์ ์๋๋ก ์ ๊ธฐ์ ์ ๊ธฐ์ด ์๋ฆฌ๋ถํฐ ์ผ
product.kyobobook.co.kr
์ค๋ ๋ฐฐ์ด ๊ฒ ์ค ๊ธฐ์ตํ ๊ฒ์ ์ ๋ฆฌํ๋ค.
Chapter 05 ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด GPIO ๋ฐ ์ผ์ ํ์ฉํ๊ธฐ
์ฑ ์ ๋ชฉ์ฐจ
01 _ GPIO ์ ์ด ๋ฐ ํ ์คํธ
01-1 LED ์ค์ต
01-2 ํธ์ ๋ฒํผ ์ค์์น ์ค์ต(Polling ๋ฐฉ์)
01-3 ํธ์ ๋ฒํผ ์ค์์น ์ค์ต(Event ์๋ฆผ ๋ฐฉ์)
01-4 ํธ์ ๋ฒํผ ์ ๋ ฅ์ผ๋ก LED ์ค์ต
02 _ PWM ์ ์ด
02-1 PWM์ผ๋ก LED ์ค์ต
02-2 PWM์ผ๋ก ๋ถ์ ์ค์ต
02-3 PWM์ผ๋ก ์๋ณด๋ชจํฐ ์ค์ต
03 _ ์ด์ํ์ผ์(HC-SR04) ์ค์ต
04 _ PIR ์ผ์(HC-SR501) ์ค์ต
05 _ ์๋ ๋ก๊ทธ ์ ํธ์ SPI ํต์
05-1 ์๋ ๋ก๊ทธ ์ ํธ๋ฅผ ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด๋ก ์ฝ์ด์ค๊ธฐ
05-2 SPI ํต์ ์ ์ดํด
05-3 SPI ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด์์ ์ค์ ํ๊ธฐ
05-4 ์๋ ๋ก๊ทธ ์ ์์ MCP3008๋ก ์ฝ์ด์ค๊ธฐ
05-5 LDR ์ผ์ ์ค์ต
05-6 ์กฐ์ด์คํฑ(Joystick) ์ค์ต
06 _ IยฒC ํต์
06-1 IยฒC ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด์์ ์ค์ ํ๊ธฐ
06-2 BMP180(๋๊ธฐ์ ์ผ์) ์ค์ต
06-3 OLED ๋์คํ๋ ์ด ์ค์ต
6 IยฒC (Inter-Integrated Circuit) ํต์ p. 161
- SDA(Serial Data) : ์๋ฆฌ์ผ ๋ฐ์ดํฐ๋ก ํต์ ํ๊ณ ์ ํ๋ ๋ฐ์ดํฐ๋ฅผ ์๋ฏธํ๋ฉฐ ์์ ์ค๋ช ์ฒ๋ผ SCL์ด LOW์ผ ๋ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์์ผ๋ฉฐ ๊ฐ๊ฐ์ ์ ์ก์๋ ACK๊ฐ ํฌํจ๋๋ฉฐ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ ๊ฒ์ผ์ง ์ธ ๊ฒ์ผ์ง์ ๋ฐ๋ผ ๊ท๊ฒฉ์ด ๋ค๋ฅด๋ค.
- SCL(Serial Clock) : ์๋ฆฌ์ผ ํด๋ญ์ผ๋ก ๋ง์คํฐ์ ์ฌ๋ ์ด๋ธ ๊ฐ์ ํด๋ญ์ ๋ง์ถฐ ๋ฐ์ดํฐ๋ฅผ ์ก์์ ํ ์ ์๊ฒ ํด์ค๋ค. ๊ธฐ๋ณธ ๊ฐ HIGH์ผ ๋๋ง SDA๊ฐ HIGH -> LOW ๋ก ๊ฐ๋ฉด START, LOW -> HIGH๋ก ๊ฐ๋ฉด END๋ฅผ ๋ปํ๋ค. ๋ฐ์ดํฐ ์ก์์ ์ SCL์ด LOW์ผ ๋๋ง ๊ฐ๋ฅํ๋ค.

์ฐธ๊ณ : https://gudgud.tistory.com/28
IยฒC ํต์ ์์ธ ๋ถ์ ์ฐธ๊ณ : https://www.hardcopyworld.com/?p=2790

6.1 IยฒC ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด์์ ์ค์ ํ๊ธฐ


6.2 BMP180(๋๊ธฐ์ ์ผ์) ์ค์ต
BMP180: Barometric Pressure






[1] BMP_180.py p. 163
#-*- coding: utf-8 -*- #ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ถ๋ฌ์ต๋๋ค. (BMP85/180) import Adafruit_BMP.BMP085 as BMP085 #BMP180์ผ์์ ์ธ์คํด์ค sensor ์์ฑ sensor = BMP085.BMP085() #์จ๋, ์๋ ฅ, ๊ณ ๋ ๊ฐ์ ์ฝ์ด์ ๋ณ์์ ์ ์ฅ temp = sensor.read_temperature() pressure = sensor.read_pressure() ALTitude = sensor.read_ALTiture() #์ธก์ ๊ฐ์ ์ถ๋ ฅ print('Temp = {0:0.2f} *C'.format(temp)) print('Pressure = {0:0.2f} Pa'.format(pressure)) print('ALTitude = {0:0.2f} m'.format(ALTitude))
6.3 OLED ๋์คํ๋ ์ด ์ค์ต


ํฐ๋ฏธ๋์ ์ ๋ ฅ
i2cdetect -y 1


(3) ํ์ด์ฌ ์ฝ๋ ์์ฑํ๊ธฐ
[2] Oled.py p. 165 - p. 166
์ค์ตํ์ผ: /home/pi/webapps/ch05/Oled.py
#-*-coding:utf-8-*- # ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ถ๋ฌ์ต๋๋ค. import time import Adafruit_SSD1306 from PIL import Image, ImageDraw, ImageFont import Adafruit_BMP.BMP085 as BMP085 # OLED 128X64 ( i2c_address = ์ฐ๊ฒฐ๋ OLED ์ฃผ์ ) ์ธ์คํด์ค disp ์์ฑ disp = Adafruit_SSD1306.SSD1306_128_64(rst=None, i2c_address=0x3C) # disp ์ด๊ธฐํ disp.begin() # ํ๋ฉด ํด๋ฆฌ์ด disp.clear() disp.display() # Create blank image for drawing. # Make sure to create image with mode '1' for 1-bit color width = disp.width height = disp.height image = Image.new('1', (width, height)) # Get drawing object to draw on image. draw = ImageDraw.Draw(image) # Draw a black filled box to clear the image draw.rectangle((0,0,width,height), outline=0, fill=0) # First define some constants to allow easy resizing of shapes. padding = -2 top = padding bottom = height-padding # Move left to right keeping track of the current x position for drawing shapes. x = 0 # ๋ํดํธ ํฐํธ ๋ถ๋ฌ์ค๊ธฐ font = ImageFont.load_default() # BMP180์ผ์์ ์ธ์คํด์ค sensor ์์ฑ sensor = BMP085.BMP085() while True: # ์จ๋, ์๋ ฅ, ๊ณ ๋ ๊ฐ์ ์ฝ์ด์ ๋ณ์์ ์ ์ฅ temp = sensor.read_temperature() pressure = sensor.read_pressure() altitude = sensor.read_altitude() # ์ธก์ ๊ฐ์ ์ถ๋ ฅ (ํฐ๋ฏธ๋) print('Temp = {0:0.2f} *C'.format(temp)) print('Pressure = {0:0.2f} Pa'.format(pressure)) print('Altitude = {0:0.2f} m'.format(altitude)) # OLED์ ํ๋ฉด ํ์ ๋ด์ฉ draw.text((x,top), 'Temp = {0:0.2f} *C'.format(temp), font=font, fill=255) draw.text((x,top+8), 'Pressure = {0:0.2f} Pa'.format(pressure),font=font, fill=255) draw.text((x,top+16),'Altitude = {0:0.2f} m'.format(altitude), font=font, fill=255) # ํ๋ฉด ํ์ disp.image(image) disp.display() # ๋๋ ์ด ์๊ฐ 2์ด time.sleep(2)
