Skip to content

Instantly share code, notes, and snippets.

@simryang
Created November 17, 2023 06:54
Show Gist options
  • Save simryang/aaa7b83162ddb078daff79d7ab99bce0 to your computer and use it in GitHub Desktop.
Save simryang/aaa7b83162ddb078daff79d7ab99bce0 to your computer and use it in GitHub Desktop.
raspberry pi 4B check csi rpi2 camera
from pathlib import Path
import smbus
bus_number = 10
def have_csicamera() -> bool:
# csi 카메라는 i2c 를 사용하므로 연결되어 있다면 /dev/i2c-10 이 존재
return Path(f"/dev/i2c-{bus_number}").exists()
def is_cam_connected() -> bool:
# i2cdetect -y -r 10 명령을 내리면 카메라가 정상 동작하는 경우 -- 가 아닌 값이 존재. 다만 빈 값은 예약 영역임
bus = smbus.SMBus(bus_number)
have_valid_data = False
for i in range(128):
try:
data = bus.read_byte(i)
# 예약된 영역은 빈 값이 읽혀서 제외
if 2 < data < 120:
print(i, data)
have_valid_data = True
break
except Exception:
pass
return have_valid_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment