User Tools

Site Tools


fluidcanvas_r2pi:tft_boot_splash_and_status_display_guide

TFT Boot Splash & Status Display Guide (Raspberry Pi)

개요

이 문서는 Raspberry Pi에서 부팅 과정에서 다음의 정보를 SPI TFT-LCD(/dev/fb1)에 순차적으로 표시하는 방법을 설명합니다. 다음의 두 기능을 수행하는 홈 영역의 스크립트를 systemd에서 순차적으로 실행하는 것에 해당합니다.

  1. 부팅 시 splash 이미지 표시 - /home/pi/scripts/tft-splash.sh
  2. 부팅 완료 후 시스템 정보(시간, IP address, CPU 등)를 화면에 표시 - /home/pi/scripts/fluidardule_status.py

1. 필요한 패키지 설치

fbi는 이미 설치되어 있다고 가정한다.

sudo apt update
sudo apt install -y python3-pil

2. Splash 이미지

480x320p Splash 이미지

ls -l /home/pi/sf2/FluidArdule.png

3. Splash 표시용 스크립트(~/scripts/tft-splash.sh)

nano
 ~/scripts/tft-splash.sh
#!/bin/bash
sleep 1
/usr/bin/pkill fbi >/dev/null 2>&1 || true
/usr/bin/fbi -d /dev/fb1 --noverbose -a /home/pi/sf2/FluidArdule.png >/dev/null 2>&1
sudo chmod +x ~/scripts/tft-splash.sh

4. 상태 화면 스크립트(~/scripts/fluidardule_status.py)

#!/usr/bin/env python3
from PIL import Image, ImageDraw, ImageFont
import subprocess
from pathlib import Path

W, H = 480, 320
OUT = Path("/home/pi/fluidardule_status.png")

FONT_BOLD = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
FONT_REG  = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"

def run_cmd(cmd):
    try:
        result = subprocess.run(
            cmd, shell=True, capture_output=True, text=True
        )
        return result.stdout.strip()
    except Exception:
        return ""

def get_status():
    hostname = run_cmd("hostname")
    time_str = run_cmd("date '+%Y-%m-%d %H:%M:%S'")
    ip_str = run_cmd("hostname -I 2>/dev/null | awk '{print $1}'")
    if not ip_str:
        ip_str = "no network"

    cpu_load = run_cmd("awk '{print $1}' /proc/loadavg")
    cpu_temp = run_cmd("vcgencmd measure_temp | sed 's/temp=//'")
    mem = run_cmd("free -m | awk '/Mem:/ {print $3\"/\"$2\"MB\"}'")

    return {
        "hostname": hostname or "-",
        "time": time_str or "-",
        "ip": ip_str,
        "cpu_load": cpu_load or "-",
        "cpu_temp": cpu_temp or "-",
        "mem": mem or "-",
    }

def render(status):
    img = Image.new("RGB", (W, H), "black")
    draw = ImageDraw.Draw(img)

    font_title = ImageFont.truetype(FONT_BOLD, 26)
    font_label = ImageFont.truetype(FONT_BOLD, 18)
    font_text  = ImageFont.truetype(FONT_REG, 18)

    # 제목
    draw.text((W // 2, 18), "FluidArdule Status", font=font_title, fill="white", anchor="ma")
    draw.line((20, 45, W - 20, 45), fill="white", width=2)

    items = [
        ("HOST", status["hostname"]),
        ("TIME", status["time"]),
        ("IP", status["ip"]),
        ("LOAD", status["cpu_load"]),
        ("TEMP", status["cpu_temp"]),
        ("MEM", status["mem"]),
    ]

    y = 70
    for label, value in items:
        draw.text((24, y), f"{label:5}", font=font_label, fill="white")
        draw.text((110, y), f": {value}", font=font_text, fill="white")
        y += 36

    draw.line((20, H - 40, W - 20, H - 40), fill="white", width=1)
    draw.text((W // 2, H - 28), "READY", font=font_label, fill="white", anchor="ma")

    img.save(OUT)

def show():
    subprocess.run(
        ["sudo", "fbi", "-T", "1", "-d", "/dev/fb1", "--noverbose", "-a", str(OUT)],
        check=False
    )

def main():
    status = get_status()
    render(status)
    show()

if __name__ == "__main__":
    main()
sudo chmod +x ~/scripts/fluidardule_status.py

5. Splash 서비스

sudo nano /etc/systemd/system/tft-splash.service
[Unit]
Description=TFT splash screen
DefaultDependencies=no
After=local-fs.target
 
[Service]
Type=oneshot
ExecStart=/home/pi/scripts/tft-splash.sh
RemainAfterExit=yes
 
[Install]
WantedBy=sysinit.target

6. 상태 화면 서비스

sudo nano /etc/systemd/system/fluid_ardule.service
[Unit]
Description=TFT status screen after boot
After=multi-user.target tft-splash.service
Wants=multi-user.target
 
[Service]
Type=oneshot
ExecStart=/home/pi/scripts/fluidardule_status.py
 
[Install]
WantedBy=multi-user.target

7. 서비스 활성화

sudo systemctl daemon-reload
sudo systemctl enable tft-splash.service
sudo systemctl enable fluid_ardule.service

8. 재부팅 테스트

sudo reboot

9. 문제 해결

systemctl status tft-splash.service
journalctl -u tft-splash.service -b
systemctl status fluid_ardule.service -b
journalctl -u fluid_ard
ule.service -b

서비스를 아예 끄려면(재부팅 후에도 불활성화)

sudo systemctl stop tft-splash.service
sudo systemctl stop fluid_ardule.service
sudo systemctl disable tft-splash.service
sudo systemctl disable fluid_ardule.service

10. 확장 아이디어

  • MIDI 상태 표시
  • USB mount 상태 표시
  • CPU 그래프 표시
  • 실시간 업데이트 루프 구현

핵심 요약

  • splash는 fbi로 빠르게 표시
  • systemd로 자동 실행
  • fbi는 항상 덮어쓰기 방식 사용

한 줄 결론

“부팅은 이미지, 완료 후는 정보”

fluidcanvas_r2pi/tft_boot_splash_and_status_display_guide.txt · Last modified: by hyjeong