키트 데모 예제

카메라

sudo apt update
sudo apt install python3-opencv -y
import cv2

cap = cv2.VideoCapture(0)
if not cap.isOpened():
    raise RuntimeError("카메라를 열 수 없다.")

print("q 키로 종료한다.")
while True:
    ok, frame = cap.read()
    if not ok:
        break
    cv2.imshow('USB Camera', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

image.png

터치패널

sudo apt update
sudo apt install -y python3-tk tk-dev
python3-pil python3-pil.imagetk
# file: touch_basic.py
import tkinter as tk
from PIL import Image, ImageTk

WIDTH, HEIGHT = 800, 480 # 7인치 해상도에 맞게 조정 가능

class TouchApp:
    def __init__(self, root):
        self.root = root
        self.root.title("Touch Demo")
        self.root.geometry(f"{WIDTH}x{HEIGHT}")
        self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg="#111111")
        self.canvas.pack(fill="both", expand=True)

        # 버튼 영역 정의(예시)
        self.buttons = {
            "RED": (50, 50, 250, 200, "#7f1d1d"),
            "GREEN":(300, 50, 500, 200, "#14532d"),
            "BLUE": (550, 50, 750, 200, "#1e3a8a"),
        }
        self.draw_buttons()

        self.pos_text = self.canvas.create_text(
            WIDTH//2, HEIGHT-40, fill="#ffffff", font=("NanumGothic", 18), text="x=?, y=?"
        )

        self.canvas.bind("<Button-1>", self.on_touch)
        self.canvas.bind("<B1-Motion>", self.on_touch)

    def draw_buttons(self):
        for name, (x1, y1, x2, y2, color) in self.buttons.items():
            self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="#e5e7eb", width=2)
            self.canvas.create_text((x1+x2)//2, (y1+y2)//2, text=name, fill="#ffffff", font=("NanumGothic", 16, "bold"))

    def on_touch(self, event):
        x, y = event.x, event.y
        self.canvas.itemconfig(self.pos_text, text=f"x={x}, y={y}")
        for name, (x1, y1, x2, y2, color) in self.buttons.items():
            if x1 <= x <= x2 and y1 <= y <= y2:
                self.root.configure(bg=color)
                break

if __name__ == "__main__":
    root = tk.Tk()
    app = TouchApp(root)
    root.mainloop()

KakaoTalk_20251015_182732076.mp4

스위치

# led_button_lgpio.py  (RPi.GPIO 코드의 lgpio 버전)
import lgpio, time

# 핀 번호 (BCM 기준)
LED1 = 18   # P1 pin 12
LED2 = 23   # P1 pin 16
BTN  = 17   # P1 pin 11

h = lgpio.gpiochip_open(0)

# 출력 설정
lgpio.gpio_claim_output(h, LED1, 0)   # 처음엔 꺼짐
lgpio.gpio_claim_output(h, LED2, 0)

# 버튼 입력: 보통 스위치가 GND로 당겨지므로 풀업 사용
lgpio.gpio_claim_input(h, BTN, lgpio.SET_PULL_UP)

print("Press CTRL+C to exit")
try:
    while True:
        pressed = (lgpio.gpio_read(h, BTN) == 0)  # 눌리면 0
        if not pressed:
            # 버튼을 누르지 않았을 때: LED1 ON, LED2 OFF
            lgpio.gpio_write(h, LED1, 1)
            lgpio.gpio_write(h, LED2, 0)
        else:
            # 버튼을 눌렀을 때: LED1 OFF, LED2 깜빡
            lgpio.gpio_write(h, LED1, 0)
            lgpio.gpio_write(h, LED2, 1)
            time.sleep(0.1)
            lgpio.gpio_write(h, LED2, 0)
            time.sleep(0.1)
        time.sleep(0.01)  # 소프트 디바운스
except KeyboardInterrupt:
    pass
finally:
    lgpio.gpio_write(h, LED1, 0)
    lgpio.gpio_write(h, LED2, 0)
    lgpio.gpiochip_close(h)

IMU

https://www.devicemart.co.kr/goods/view?no=1247052&srsltid=AfmBOorGs0vvss7Jvjji_6CvdigOUHmAGuRG4GFgvwSHByJ_0G43CSz1

image.png

6축 보급형 예제 가장 많음.